Skip to content

Commit

Permalink
[Upgrade Assistant] Refactor CITs (#109536)
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth authored Aug 20, 2021
1 parent ec3c28f commit af6b908
Show file tree
Hide file tree
Showing 19 changed files with 279 additions and 333 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import { act } from 'react-dom/test-utils';

import { ElasticsearchTestBed, setupElasticsearchPage, setupEnvironment } from '../helpers';

import { setupEnvironment } from '../helpers';
import { ElasticsearchTestBed, setupElasticsearchPage } from './es_deprecations.helpers';
import { esDeprecationsMockResponse, MOCK_SNAPSHOT_ID, MOCK_JOB_ID } from './mocked_responses';

describe('Default deprecation flyout', () => {
Expand Down Expand Up @@ -39,7 +39,7 @@ describe('Default deprecation flyout', () => {
const multiFieldsDeprecation = esDeprecationsMockResponse.deprecations[2];
const { actions, find, exists } = testBed;

await actions.clickDefaultDeprecationAt(0);
await actions.table.clickDeprecationRowAt('default', 0);

expect(exists('defaultDeprecationDetails')).toBe(true);
expect(find('defaultDeprecationDetails.flyoutTitle').text()).toContain(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ import { act } from 'react-dom/test-utils';

import { API_BASE_PATH } from '../../../common/constants';
import type { MlAction } from '../../../common/types';
import { ElasticsearchTestBed, setupElasticsearchPage, setupEnvironment } from '../helpers';
import { setupEnvironment } from '../helpers';
import { ElasticsearchTestBed, setupElasticsearchPage } from './es_deprecations.helpers';
import {
esDeprecationsMockResponse,
MOCK_SNAPSHOT_ID,
Expand Down Expand Up @@ -56,7 +57,7 @@ describe('Deprecations table', () => {
const { actions } = testBed;
const totalRequests = server.requests.length;

await actions.clickRefreshButton();
await actions.table.clickRefreshButton();

const mlDeprecation = esDeprecationsMockResponse.deprecations[0];
const reindexDeprecation = esDeprecationsMockResponse.deprecations[3];
Expand All @@ -80,15 +81,15 @@ describe('Deprecations table', () => {
it('filters results by "critical" status', async () => {
const { find, actions } = testBed;

await actions.clickCriticalFilterButton();
await actions.searchBar.clickCriticalFilterButton();

const criticalDeprecations = esDeprecationsMockResponse.deprecations.filter(
(deprecation) => deprecation.isCritical
);

expect(find('deprecationTableRow').length).toEqual(criticalDeprecations.length);

await actions.clickCriticalFilterButton();
await actions.searchBar.clickCriticalFilterButton();

expect(find('deprecationTableRow').length).toEqual(
esDeprecationsMockResponse.deprecations.length
Expand All @@ -98,7 +99,7 @@ describe('Deprecations table', () => {
it('filters results by type', async () => {
const { component, find, actions } = testBed;

await actions.clickTypeFilterDropdownAt(0);
await actions.searchBar.clickTypeFilterDropdownAt(0);

// We need to read the document "body" as the filter dropdown options are added there and not inside
// the component DOM tree.
Expand All @@ -125,7 +126,7 @@ describe('Deprecations table', () => {
const { find, actions } = testBed;
const multiFieldsDeprecation = esDeprecationsMockResponse.deprecations[2];

await actions.setSearchInputValue(multiFieldsDeprecation.message);
await actions.searchBar.setSearchInputValue(multiFieldsDeprecation.message);

expect(find('deprecationTableRow').length).toEqual(1);
expect(find('deprecationTableRow').at(0).text()).toContain(multiFieldsDeprecation.message);
Expand All @@ -134,7 +135,7 @@ describe('Deprecations table', () => {
it('shows error for invalid search queries', async () => {
const { find, exists, actions } = testBed;

await actions.setSearchInputValue('%');
await actions.searchBar.setSearchInputValue('%');

expect(exists('invalidSearchQueryMessage')).toBe(true);
expect(find('invalidSearchQueryMessage').text()).toContain('Invalid search');
Expand All @@ -143,7 +144,7 @@ describe('Deprecations table', () => {
it('shows message when search query does not return results', async () => {
const { find, actions, exists } = testBed;

await actions.setSearchInputValue('foobarbaz');
await actions.searchBar.setSearchInputValue('foobarbaz');

expect(exists('noDeprecationsRow')).toBe(true);
expect(find('noDeprecationsRow').text()).toContain(
Expand Down Expand Up @@ -183,7 +184,7 @@ describe('Deprecations table', () => {
expect(find('deprecationTableRow').length).toEqual(50);

// Navigate to the next page
await actions.clickPaginationAt(1);
await actions.pagination.clickPaginationAt(1);

// On the second (last) page, we expect to see the remaining deprecations
expect(find('deprecationTableRow').length).toEqual(deprecations.length - 50);
Expand All @@ -192,7 +193,7 @@ describe('Deprecations table', () => {
it('allows the number of viewable rows to change', async () => {
const { find, actions, component } = testBed;

await actions.clickRowsPerPageDropdown();
await actions.pagination.clickRowsPerPageDropdown();

// We need to read the document "body" as the rows-per-page dropdown options are added there and not inside
// the component DOM tree.
Expand All @@ -219,7 +220,7 @@ describe('Deprecations table', () => {

const criticalDeprecations = deprecations.filter((deprecation) => deprecation.isCritical);

await actions.clickCriticalFilterButton();
await actions.searchBar.clickCriticalFilterButton();

// Only 40 critical deprecations, so only one page should show
expect(find('esDeprecationsPagination').find('.euiPagination__item').length).toEqual(1);
Expand All @@ -232,7 +233,7 @@ describe('Deprecations table', () => {
(deprecation) => deprecation.correctiveAction?.type === 'reindex'
);

await actions.setSearchInputValue('Index created before 7.0');
await actions.searchBar.setSearchInputValue('Index created before 7.0');

// Only 20 deprecations that match, so only one page should show
expect(find('esDeprecationsPagination').find('.euiPagination__item').length).toEqual(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@

import { act } from 'react-dom/test-utils';

import { ElasticsearchTestBed, setupElasticsearchPage, setupEnvironment } from '../helpers';
import { setupEnvironment } from '../helpers';
import { ElasticsearchTestBed, setupElasticsearchPage } from './es_deprecations.helpers';

describe('Error handling', () => {
let testBed: ElasticsearchTestBed;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,150 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/
import { act } from 'react-dom/test-utils';

import { registerTestBed, TestBed, TestBedConfig } from '@kbn/test/jest';
import { EsDeprecations } from '../../../public/application/components/es_deprecations';
import { WithAppDependencies } from '../helpers';

const testBedConfig: TestBedConfig = {
memoryRouter: {
initialEntries: ['/es_deprecations'],
componentRoutePath: '/es_deprecations',
},
doMountAsync: true,
};

export type ElasticsearchTestBed = TestBed & {
actions: ReturnType<typeof createActions>;
};

const createActions = (testBed: TestBed) => {
const { component, find } = testBed;

/**
* User Actions
*/

const table = {
clickRefreshButton: async () => {
await act(async () => {
find('refreshButton').simulate('click');
});

component.update();
},
clickDeprecationRowAt: async (
deprecationType: 'mlSnapshot' | 'indexSetting' | 'reindex' | 'default',
index: number
) => {
await act(async () => {
find(`deprecation-${deprecationType}`).at(index).simulate('click');
});

component.update();
},
};

const searchBar = {
clickTypeFilterDropdownAt: async (index: number) => {
await act(async () => {
// EUI doesn't support data-test-subj's on the filter buttons, so we must access via CSS selector
find('searchBarContainer')
.find('.euiPopover')
.find('.euiFilterButton')
.at(index)
.simulate('click');
});

component.update();
},
setSearchInputValue: async (searchValue: string) => {
await act(async () => {
find('searchBarContainer')
.find('input')
.simulate('keyup', { target: { value: searchValue } });
});

component.update();
},
clickCriticalFilterButton: async () => {
await act(async () => {
// EUI doesn't support data-test-subj's on the filter buttons, so we must access via CSS selector
find('searchBarContainer').find('.euiFilterButton').at(0).simulate('click');
});

component.update();
},
};

const pagination = {
clickPaginationAt: async (index: number) => {
await act(async () => {
find(`pagination-button-${index}`).simulate('click');
});

component.update();
},
clickRowsPerPageDropdown: async () => {
await act(async () => {
find('tablePaginationPopoverButton').simulate('click');
});

component.update();
},
};

const mlDeprecationFlyout = {
clickUpgradeSnapshot: async () => {
await act(async () => {
find('mlSnapshotDetails.upgradeSnapshotButton').simulate('click');
});

component.update();
},
clickDeleteSnapshot: async () => {
await act(async () => {
find('mlSnapshotDetails.deleteSnapshotButton').simulate('click');
});

component.update();
},
};

const indexSettingsDeprecationFlyout = {
clickDeleteSettingsButton: async () => {
await act(async () => {
find('deleteSettingsButton').simulate('click');
});

component.update();
},
};

return {
table,
searchBar,
pagination,
mlDeprecationFlyout,
indexSettingsDeprecationFlyout,
};
};

export const setupElasticsearchPage = async (
overrides?: Record<string, unknown>
): Promise<ElasticsearchTestBed> => {
const initTestBed = registerTestBed(
WithAppDependencies(EsDeprecations, overrides),
testBedConfig
);
const testBed = await initTestBed();

return {
...testBed,
actions: createActions(testBed),
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@

import { act } from 'react-dom/test-utils';

import { ElasticsearchTestBed, setupElasticsearchPage, setupEnvironment } from '../helpers';

import { setupEnvironment } from '../helpers';
import { ElasticsearchTestBed, setupElasticsearchPage } from './es_deprecations.helpers';
import { esDeprecationsMockResponse, MOCK_SNAPSHOT_ID, MOCK_JOB_ID } from './mocked_responses';

describe('Index settings deprecation flyout', () => {
Expand Down Expand Up @@ -37,7 +37,7 @@ describe('Index settings deprecation flyout', () => {

component.update();

await actions.clickIndexSettingsDeprecationAt(0);
await actions.table.clickDeprecationRowAt('indexSetting', 0);

expect(exists('indexSettingsDetails')).toBe(true);
expect(find('indexSettingsDetails.flyoutTitle').text()).toContain(
Expand All @@ -53,7 +53,7 @@ describe('Index settings deprecation flyout', () => {
acknowledged: true,
});

await actions.clickDeleteSettingsButton();
await actions.indexSettingsDeprecationFlyout.clickDeleteSettingsButton();

const request = server.requests[server.requests.length - 1];

Expand All @@ -69,7 +69,7 @@ describe('Index settings deprecation flyout', () => {
);

// Reopen the flyout
await actions.clickIndexSettingsDeprecationAt(0);
await actions.table.clickDeprecationRowAt('indexSetting', 0);

// Verify prompt to remove setting no longer displays
expect(find('removeSettingsPrompt').length).toEqual(0);
Expand All @@ -87,7 +87,7 @@ describe('Index settings deprecation flyout', () => {

httpRequestsMockHelpers.setUpdateIndexSettingsResponse(undefined, error);

await actions.clickDeleteSettingsButton();
await actions.indexSettingsDeprecationFlyout.clickDeleteSettingsButton();

const request = server.requests[server.requests.length - 1];

Expand All @@ -103,7 +103,7 @@ describe('Index settings deprecation flyout', () => {
);

// Reopen the flyout
await actions.clickIndexSettingsDeprecationAt(0);
await actions.table.clickDeprecationRowAt('indexSetting', 0);

// Verify the flyout shows an error message
expect(find('indexSettingsDetails.deleteSettingsError').text()).toContain(
Expand Down
Loading

0 comments on commit af6b908

Please sign in to comment.