From 17712057c7b83972b3acf0ef2559affb2a560772 Mon Sep 17 00:00:00 2001
From: John Dorlus <silne.dorlus@elastic.co>
Date: Thu, 25 Feb 2021 04:02:43 -0500
Subject: [PATCH] [ILM][Accessibility] Added A11y test for ILM new policy form.
 (#92570) (#92759)

* Added A11y test for ILM new policy form.

* Separated out the takeSnapshot calls to separate tests.
---
 .../apps/index_lifecycle_management.ts        | 31 +++++++++++++++-
 .../index_lifecycle_management_page.ts        | 36 +++++++++++++++++++
 2 files changed, 66 insertions(+), 1 deletion(-)

diff --git a/x-pack/test/accessibility/apps/index_lifecycle_management.ts b/x-pack/test/accessibility/apps/index_lifecycle_management.ts
index 43fd805a42d37..d6ba222e50eb4 100644
--- a/x-pack/test/accessibility/apps/index_lifecycle_management.ts
+++ b/x-pack/test/accessibility/apps/index_lifecycle_management.ts
@@ -28,7 +28,10 @@ const TEST_POLICY_ALL_PHASES = {
 };
 
 export default function ({ getService, getPageObjects }: FtrProviderContext) {
-  const { common } = getPageObjects(['common']);
+  const { common, indexLifecycleManagement } = getPageObjects([
+    'common',
+    'indexLifecycleManagement',
+  ]);
   const retry = getService('retry');
   const testSubjects = getService('testSubjects');
   const esClient = getService('es');
@@ -55,6 +58,32 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
       await esClient.ilm.deleteLifecycle({ policy: TEST_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 () => {
         await common.navigateToApp('indexLifecycleManagement');
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 04db9e4544c9a..ddf46926f122a 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
@@ -9,6 +9,7 @@ import { FtrProviderContext } from '../ftr_provider_context';
 
 export function IndexLifecycleManagementPageProvider({ getService }: FtrProviderContext) {
   const testSubjects = getService('testSubjects');
+  const retry = getService('retry');
 
   return {
     async sectionHeadingText() {
@@ -17,5 +18,40 @@ export function IndexLifecycleManagementPageProvider({ getService }: FtrProvider
     async createPolicyButton() {
       return await testSubjects.find('createPolicyButton');
     },
+    async fillNewPolicyForm(
+      policyName: string,
+      warmEnabled: boolean = false,
+      coldEnabled: boolean = false,
+      deletePhaseEnabled: boolean = false
+    ) {
+      await testSubjects.setValue('policyNameField', policyName);
+      if (warmEnabled) {
+        await retry.try(async () => {
+          await testSubjects.click('enablePhaseSwitch-warm');
+        });
+      }
+      if (coldEnabled) {
+        await retry.try(async () => {
+          await testSubjects.click('enablePhaseSwitch-cold');
+        });
+      }
+      if (deletePhaseEnabled) {
+        await retry.try(async () => {
+          await testSubjects.click('enableDeletePhaseButton');
+        });
+      }
+    },
+    async saveNewPolicy() {
+      await testSubjects.click('savePolicyButton');
+    },
+    async createNewPolicyAndSave(
+      policyName: string,
+      warmEnabled: boolean = false,
+      coldEnabled: boolean = false,
+      deletePhaseEnabled: boolean = false
+    ) {
+      await this.fillNewPolicyForm(policyName, warmEnabled, coldEnabled, deletePhaseEnabled);
+      await this.saveNewPolicy();
+    },
   };
 }