From b45a561fa67516c39495a7e458b1a2f163cea634 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Yulia=20=C4=8Cech?= <6585477+yuliacech@users.noreply.github.com> Date: Tue, 29 Jun 2021 15:06:49 +0200 Subject: [PATCH] [ILM] Add missing a11y tests (#102887) (#103641) * [ILM] Added missing a11y tests * Fixed ILM functional tests, added after tests cleanup * Added review suggestions * Fixed section header renaming * Fixed section header renaming Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com> --- .../policy_table/components/table_content.tsx | 2 + .../sections/policy_table/policy_table.tsx | 2 +- .../apps/index_lifecycle_management.ts | 144 +++++++++++++----- .../index_lifecycle_management/home_page.ts | 31 ++-- .../index_lifecycle_management_page.ts | 65 ++++---- 5 files changed, 162 insertions(+), 82 deletions(-) diff --git a/x-pack/plugins/index_lifecycle_management/public/application/sections/policy_table/components/table_content.tsx b/x-pack/plugins/index_lifecycle_management/public/application/sections/policy_table/components/table_content.tsx index 2c653ee5f76f..ffc21ac4187f 100644 --- a/x-pack/plugins/index_lifecycle_management/public/application/sections/policy_table/components/table_content.tsx +++ b/x-pack/plugins/index_lifecycle_management/public/application/sections/policy_table/components/table_content.tsx @@ -205,6 +205,7 @@ export const TableContent: React.FunctionComponent = ({ onClick: () => { setConfirmModal(renderAddPolicyToTemplateConfirmModal(policy)); }, + 'data-test-subj': 'addPolicyToTemplate', }); items.push({ name: deletePolicyLabel, @@ -214,6 +215,7 @@ export const TableContent: React.FunctionComponent = ({ onClick: () => { setConfirmModal(renderDeleteConfirmModal(policy)); }, + 'data-test-subj': 'deletePolicy', }); const panelTree = { id: 0, diff --git a/x-pack/plugins/index_lifecycle_management/public/application/sections/policy_table/policy_table.tsx b/x-pack/plugins/index_lifecycle_management/public/application/sections/policy_table/policy_table.tsx index 6ed7d42a694c..30a2b9e68d69 100644 --- a/x-pack/plugins/index_lifecycle_management/public/application/sections/policy_table/policy_table.tsx +++ b/x-pack/plugins/index_lifecycle_management/public/application/sections/policy_table/policy_table.tsx @@ -152,7 +152,7 @@ export const PolicyTable: React.FunctionComponent = ({ + { + const actionsCell = await testSubjects.find(`policyTableCell-actions-${policyName}`); + const actionsButton = await actionsCell.findByTestSubject('policyActionsContextMenuButton'); + + await actionsButton.click(); + }; + describe('Index Lifecycle Management', async () => { before(async () => { - await esClient.ilm.putLifecycle({ policy: TEST_POLICY_NAME, body: TEST_POLICY_ALL_PHASES }); - await common.navigateToApp('indexLifecycleManagement'); + await esClient.ilm.putLifecycle({ policy: POLICY_NAME, body: POLICY_ALL_PHASES }); }); after(async () => { // @ts-expect-error @elastic/elasticsearch DeleteSnapshotLifecycleRequest.policy_id is required - await esClient.ilm.deleteLifecycle({ policy: TEST_POLICY_NAME }); + await esClient.ilm.deleteLifecycle({ policy: POLICY_NAME }); }); - it('Create Policy Form', async () => { - await retry.waitFor('Index Lifecycle Policy create/edit view to be present', async () => { - return testSubjects.isDisplayed('createPolicyButton'); - }); - - // Navigate to create policy page and take snapshot - await testSubjects.click('createPolicyButton'); - await retry.waitFor('Index Lifecycle Policy create/edit view to be present', async () => { - return (await testSubjects.getVisibleText('policyTitle')) === 'Create policy'; - }); - - // Fill out form after enabling all phases and take snapshot. - await indexLifecycleManagement.fillNewPolicyForm('testPolicy', true, true, false); - await a11y.testAppSnapshot(); - }); - - it('Send Request Flyout on New Policy Page', async () => { - // Take snapshot of the show request panel - await testSubjects.click('requestButton'); - await a11y.testAppSnapshot(); - - // Close panel and save policy - await testSubjects.click('euiFlyoutCloseButton'); - await indexLifecycleManagement.saveNewPolicy(); - }); - - it('List policies view', async () => { - await retry.waitFor('Index Lifecycle Policy create/edit view to be present', async () => { + beforeEach(async () => { + await retry.waitFor('ILM app', async () => { await common.navigateToApp('indexLifecycleManagement'); - return testSubjects.exists('policyTablePolicyNameLink') ? true : false; + return testSubjects.exists('ilmPageHeader'); }); + }); + + describe('Edit policy form', () => { + it('Create policy', async () => { + const createButtonTestSubject = 'createPolicyButton'; + await retry.waitFor('ILM create policy button', async () => { + return testSubjects.isDisplayed(createButtonTestSubject); + }); + + // Navigate to create policy page and take snapshot + await testSubjects.click(createButtonTestSubject); + await retry.waitFor('ILM create policy form', async () => { + return (await testSubjects.getVisibleText('policyTitle')) === 'Create policy'; + }); + + // Fill out form after enabling all phases and take snapshot. + await indexLifecycleManagement.fillNewPolicyForm({ + policyName: 'testPolicy', + warmEnabled: true, + coldEnabled: true, + frozenEnabled: true, + deleteEnabled: true, + }); + await a11y.testAppSnapshot(); + }); + + it('Edit policy', async () => { + const link = await findPolicyLinkInListView(POLICY_NAME); + await link.click(); + await retry.waitFor('ILM edit form', async () => { + return ( + (await testSubjects.getVisibleText('policyTitle')) === `Edit policy ${POLICY_NAME}` + ); + }); + await a11y.testAppSnapshot(); + }); + + it('Request flyout', async () => { + const link = await findPolicyLinkInListView(POLICY_NAME); + await link.click(); + await retry.waitFor('ILM request button', async () => { + return testSubjects.exists('requestButton'); + }); + // Take snapshot of the show request panel + await testSubjects.click('requestButton'); + await a11y.testAppSnapshot(); + }); + }); + + describe('Policies list', () => { + it('List policies view', async () => { + await a11y.testAppSnapshot(); + }); + }); + + it('Add policy to index template modal', async () => { + await clickPolicyActionsButton(POLICY_NAME); + + const buttonSelector = 'addPolicyToTemplate'; + + await retry.waitFor('ILM add policy to index template button', async () => { + return testSubjects.isDisplayed(buttonSelector); + }); + await testSubjects.click(buttonSelector); + + await retry.waitFor('ILM add policy to index template modal to be present', async () => { + return testSubjects.isDisplayed('confirmModalTitleText'); + }); + await a11y.testAppSnapshot(); }); - it('Edit policy with all phases view', async () => { - await retry.waitFor('Index Lifecycle Policy create/edit view to be present', async () => { - await common.navigateToApp('indexLifecycleManagement'); - return testSubjects.exists('policyTablePolicyNameLink'); + it('Delete policy modal', async () => { + await clickPolicyActionsButton(POLICY_NAME); + + const buttonSelector = 'deletePolicy'; + + await retry.waitFor('ILM delete policy button', async () => { + return testSubjects.isDisplayed(buttonSelector); }); - const link = await findPolicyLinkInListView(TEST_POLICY_NAME); - await link.click(); - await retry.waitFor('Index Lifecycle Policy create/edit view to be present', async () => { - return testSubjects.exists('policyTitle'); + await testSubjects.click(buttonSelector); + + await retry.waitFor('ILM delete policy modal to be present', async () => { + return testSubjects.isDisplayed('confirmModalTitleText'); }); + await a11y.testAppSnapshot(); }); }); diff --git a/x-pack/test/functional/apps/index_lifecycle_management/home_page.ts b/x-pack/test/functional/apps/index_lifecycle_management/home_page.ts index 50194552aec0..bd70a50724a9 100644 --- a/x-pack/test/functional/apps/index_lifecycle_management/home_page.ts +++ b/x-pack/test/functional/apps/index_lifecycle_management/home_page.ts @@ -8,37 +8,46 @@ import expect from '@kbn/expect'; import { FtrProviderContext } from '../../ftr_provider_context'; +const policyName = 'testPolicy1'; + export default ({ getPageObjects, getService }: FtrProviderContext) => { const pageObjects = getPageObjects(['common', 'indexLifecycleManagement']); const log = getService('log'); const retry = getService('retry'); - const testSubjects = getService('testSubjects'); + const esClient = getService('es'); describe('Home page', function () { before(async () => { await pageObjects.common.navigateToApp('indexLifecycleManagement'); }); + after(async () => { + // @ts-expect-error @elastic/elasticsearch DeleteSnapshotLifecycleRequest.policy_id is required + await esClient.ilm.deleteLifecycle({ policy: policyName }); + }); it('Loads the app', async () => { - await log.debug('Checking for section header'); - const headerText = await pageObjects.indexLifecycleManagement.sectionHeadingText(); + await log.debug('Checking for page header'); + const headerText = await pageObjects.indexLifecycleManagement.pageHeaderText(); expect(headerText).to.be('Index Lifecycle Policies'); const createPolicyButton = await pageObjects.indexLifecycleManagement.createPolicyButton(); expect(await createPolicyButton.isDisplayed()).to.be(true); }); - it('Create new policy with Warm and Cold Phases', async () => { - const policyName = 'testPolicy1'; - await pageObjects.indexLifecycleManagement.createNewPolicyAndSave( + it('Create new policy with all Phases', async () => { + await pageObjects.indexLifecycleManagement.createNewPolicyAndSave({ policyName, - true, - true, - false - ); + warmEnabled: true, + coldEnabled: true, + frozenEnabled: true, + deleteEnabled: true, + }); await retry.waitFor('navigation back to home page.', async () => { - return (await testSubjects.getVisibleText('sectionHeading')) === 'Index Lifecycle Policies'; + return ( + (await pageObjects.indexLifecycleManagement.pageHeaderText()) === + 'Index Lifecycle Policies' + ); }); await pageObjects.indexLifecycleManagement.increasePolicyListPageSize(); diff --git a/x-pack/test/functional/page_objects/index_lifecycle_management_page.ts b/x-pack/test/functional/page_objects/index_lifecycle_management_page.ts index 2dd70f8a9571..0c913683a162 100644 --- a/x-pack/test/functional/page_objects/index_lifecycle_management_page.ts +++ b/x-pack/test/functional/page_objects/index_lifecycle_management_page.ts @@ -7,28 +7,42 @@ import { map as mapAsync } from 'bluebird'; import { FtrProviderContext } from '../ftr_provider_context'; +interface Policy { + policyName: string; + warmEnabled?: boolean; + coldEnabled?: boolean; + frozenEnabled?: boolean; + deleteEnabled?: boolean; + snapshotRepository?: string; + minAges?: { [key: string]: { value: string; unit: string } }; +} + export function IndexLifecycleManagementPageProvider({ getService }: FtrProviderContext) { const testSubjects = getService('testSubjects'); const retry = getService('retry'); return { - async sectionHeadingText() { - return await testSubjects.getVisibleText('sectionHeading'); + async pageHeaderText() { + return await testSubjects.getVisibleText('ilmPageHeader'); }, async createPolicyButton() { return await testSubjects.find('createPolicyButton'); }, - async fillNewPolicyForm( - policyName: string, - warmEnabled: boolean = false, - coldEnabled: boolean = false, - deletePhaseEnabled: boolean = false, - minAges: { [key: string]: { value: string; unit: string } } = { - warm: { value: '10', unit: 'd' }, - cold: { value: '15', unit: 'd' }, - frozen: { value: '20', unit: 'd' }, - } - ) { + async fillNewPolicyForm(policy: Policy) { + const { + policyName, + warmEnabled = false, + coldEnabled = false, + frozenEnabled = false, + deleteEnabled = false, + snapshotRepository = 'test', + minAges = { + warm: { value: '10', unit: 'd' }, + cold: { value: '15', unit: 'd' }, + frozen: { value: '20', unit: 'd' }, + }, + } = policy; + await testSubjects.setValue('policyNameField', policyName); if (warmEnabled) { await retry.try(async () => { @@ -42,7 +56,14 @@ export function IndexLifecycleManagementPageProvider({ getService }: FtrProvider }); await testSubjects.setValue('cold-selectedMinimumAge', minAges.cold.value); } - if (deletePhaseEnabled) { + if (frozenEnabled) { + await retry.try(async () => { + await testSubjects.click('enablePhaseSwitch-frozen'); + }); + await testSubjects.setValue('frozen-selectedMinimumAge', minAges.frozen.value); + await testSubjects.setValue('searchableSnapshotCombobox', snapshotRepository); + } + if (deleteEnabled) { await retry.try(async () => { await testSubjects.click('enableDeletePhaseButton'); }); @@ -51,21 +72,9 @@ export function IndexLifecycleManagementPageProvider({ getService }: FtrProvider async saveNewPolicy() { await testSubjects.click('savePolicyButton'); }, - async createNewPolicyAndSave( - policyName: string, - warmEnabled: boolean = false, - coldEnabled: boolean = false, - deletePhaseEnabled: boolean = false, - minAges?: { [key: string]: { value: string; unit: string } } - ) { + async createNewPolicyAndSave(policy: Policy) { await testSubjects.click('createPolicyButton'); - await this.fillNewPolicyForm( - policyName, - warmEnabled, - coldEnabled, - deletePhaseEnabled, - minAges - ); + await this.fillNewPolicyForm(policy); await this.saveNewPolicy(); },