From 7ad3d4ed395952710bbdbc77eb1ead506f0a213a Mon Sep 17 00:00:00 2001 From: Alison Goryachev Date: Fri, 20 Dec 2019 20:29:53 -0500 Subject: [PATCH 1/4] enable snapshot + restore component integration tests --- .../__jest__/client_integration/home.test.ts | 4 +-- .../client_integration/policy_add.test.ts | 5 ++-- .../client_integration/policy_edit.test.ts | 4 +-- .../client_integration/repository_add.test.ts | 10 +++---- .../repository_edit.test.ts | 28 +++++++++---------- .../home/repository_list/repository_list.tsx | 2 +- 6 files changed, 22 insertions(+), 31 deletions(-) diff --git a/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/home.test.ts b/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/home.test.ts index 69b5ca9e2b68f..799d2bd666759 100644 --- a/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/home.test.ts +++ b/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/home.test.ts @@ -35,9 +35,7 @@ const removeWhiteSpaceOnArrayValues = (array: any[]) => return value.trim(); }); -// We need to skip the tests until react 16.9.0 is released -// which supports asynchronous code inside act() -describe.skip('', () => { +describe('', () => { const { server, httpRequestsMockHelpers } = setupEnvironment(); let testBed: HomeTestBed; diff --git a/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/policy_add.test.ts b/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/policy_add.test.ts index 3dc7d94ce67d5..09757c4774314 100644 --- a/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/policy_add.test.ts +++ b/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/policy_add.test.ts @@ -27,9 +27,7 @@ const MAX_COUNT = '10'; const EXPIRE_AFTER_VALUE = '30'; const repository = fixtures.getRepository({ name: `a${getRandomString()}`, type: 'fs' }); -// We need to skip the tests until react 16.9.0 is released -// which supports asynchronous code inside act() -describe.skip('', () => { +describe('', () => { let testBed: PolicyFormTestBed; const { server, httpRequestsMockHelpers } = setupEnvironment(); @@ -195,6 +193,7 @@ describe.skip('', () => { const expected = { config: {}, + isManagedPolicy: false, name: POLICY_NAME, repository: repository.name, retention: { diff --git a/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/policy_edit.test.ts b/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/policy_edit.test.ts index 1222697956ffb..a5af9e5e5c3aa 100644 --- a/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/policy_edit.test.ts +++ b/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/policy_edit.test.ts @@ -24,9 +24,7 @@ jest.mock('ui/i18n', () => { return { I18nContext }; }); -// We need to skip the tests until react 16.9.0 is released -// which supports asynchronous code inside act() -describe.skip('', () => { +describe('', () => { let testBed: PolicyFormTestBed; let testBedPolicyAdd: PolicyFormTestBed; const { server, httpRequestsMockHelpers } = setupEnvironment(); diff --git a/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/repository_add.test.ts b/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/repository_add.test.ts index 1f70755d5fd85..82c090bc552bb 100644 --- a/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/repository_add.test.ts +++ b/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/repository_add.test.ts @@ -21,9 +21,7 @@ jest.mock('ui/i18n', () => { return { I18nContext }; }); -// We need to skip the tests until react 16.9.0 is released -// which supports asynchronous code inside act() -describe.skip('', () => { +describe('', () => { let testBed: RepositoryAddTestBed; const { server, httpRequestsMockHelpers } = setupEnvironment(); @@ -215,7 +213,7 @@ describe.skip('', () => { // Fill step 2 form.setInputValue('locationInput', repository.settings.location); - form.selectCheckBox('compressToggle'); + form.toggleEuiSwitch('compressToggle'); await act(async () => { actions.clickSubmitButton(); @@ -240,7 +238,7 @@ describe.skip('', () => { const { component, form, actions, find, exists } = testBed; form.setInputValue('locationInput', repository.settings.location); - form.selectCheckBox('compressToggle'); + form.toggleEuiSwitch('compressToggle'); const error = { status: 400, @@ -266,7 +264,7 @@ describe.skip('', () => { // Fill step 1 required fields and go to step 2 testBed.form.setInputValue('nameInput', repository.name); testBed.actions.selectRepositoryType(repository.type); - testBed.form.selectCheckBox('sourceOnlyToggle'); // toggle source + testBed.form.toggleEuiSwitch('sourceOnlyToggle'); // toggle source testBed.actions.clickNextButton(); }); diff --git a/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/repository_edit.test.ts b/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/repository_edit.test.ts index cca81c0e74285..b850114115893 100644 --- a/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/repository_edit.test.ts +++ b/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/repository_edit.test.ts @@ -22,9 +22,7 @@ jest.mock('ui/i18n', () => { return { I18nContext }; }); -// We need to skip the tests until react 16.9.0 is released -// which supports asynchronous code inside act() -describe.skip('', () => { +describe('', () => { let testBed: TestBed; let testBedRepositoryAdd: TestBed; const { server, httpRequestsMockHelpers } = setupEnvironment(); @@ -101,7 +99,7 @@ describe.skip('', () => { const { find } = testBed; expect(find('locationInput').props().defaultValue).toBe(settings.location); - expect(find('compressToggle').props().checked).toBe(settings.compress); + expect(find('compressToggle').props()['aria-checked']).toBe(settings.compress); expect(find('chunkSizeInput').props().defaultValue).toBe(settings.chunkSize); expect(find('maxSnapshotBytesInput').props().defaultValue).toBe( settings.maxSnapshotBytesPerSec @@ -109,7 +107,7 @@ describe.skip('', () => { expect(find('maxRestoreBytesInput').props().defaultValue).toBe( settings.maxRestoreBytesPerSec ); - expect(find('readOnlyToggle').props().checked).toBe(settings.readonly); + expect(find('readOnlyToggle').props()['aria-checked']).toBe(settings.readonly); }); it('readonly repository', async () => { @@ -145,7 +143,7 @@ describe.skip('', () => { expect(find('clientInput').props().defaultValue).toBe(settings.client); expect(find('containerInput').props().defaultValue).toBe(settings.container); expect(find('basePathInput').props().defaultValue).toBe(settings.basePath); - expect(find('compressToggle').props().checked).toBe(settings.compress); + expect(find('compressToggle').props()['aria-checked']).toBe(settings.compress); expect(find('chunkSizeInput').props().defaultValue).toBe(settings.chunkSize); expect(find('maxSnapshotBytesInput').props().defaultValue).toBe( settings.maxSnapshotBytesPerSec @@ -154,7 +152,7 @@ describe.skip('', () => { settings.maxRestoreBytesPerSec ); expect(find('locationModeSelect').props().value).toBe(settings.locationMode); - expect(find('readOnlyToggle').props().checked).toBe(settings.readonly); + expect(find('readOnlyToggle').props()['aria-checked']).toBe(settings.readonly); }); it('gcs repository', async () => { @@ -176,7 +174,7 @@ describe.skip('', () => { expect(find('clientInput').props().defaultValue).toBe(settings.client); expect(find('bucketInput').props().defaultValue).toBe(settings.bucket); expect(find('basePathInput').props().defaultValue).toBe(settings.basePath); - expect(find('compressToggle').props().checked).toBe(settings.compress); + expect(find('compressToggle').props()['aria-checked']).toBe(settings.compress); expect(find('chunkSizeInput').props().defaultValue).toBe(settings.chunkSize); expect(find('maxSnapshotBytesInput').props().defaultValue).toBe( settings.maxSnapshotBytesPerSec @@ -184,7 +182,7 @@ describe.skip('', () => { expect(find('maxRestoreBytesInput').props().defaultValue).toBe( settings.maxRestoreBytesPerSec ); - expect(find('readOnlyToggle').props().checked).toBe(settings.readonly); + expect(find('readOnlyToggle').props()['aria-checked']).toBe(settings.readonly); }); it('hdfs repository', async () => { @@ -209,8 +207,8 @@ describe.skip('', () => { expect(find('uriInput').props().defaultValue).toBe('elastic.co'); expect(find('pathInput').props().defaultValue).toBe(settings.path); - expect(find('loadDefaultsToggle').props().checked).toBe(settings.loadDefault); - expect(find('compressToggle').props().checked).toBe(settings.compress); + expect(find('loadDefaultsToggle').props()['aria-checked']).toBe(settings.loadDefault); + expect(find('compressToggle').props()['aria-checked']).toBe(settings.compress); expect(find('chunkSizeInput').props().defaultValue).toBe(settings.chunkSize); expect(find('securityPrincipalInput').props().defaultValue).toBe( settings['security.principal'] @@ -221,7 +219,7 @@ describe.skip('', () => { expect(find('maxRestoreBytesInput').props().defaultValue).toBe( settings.maxRestoreBytesPerSec ); - expect(find('readOnlyToggle').props().checked).toBe(settings.readonly); + expect(find('readOnlyToggle').props()['aria-checked']).toBe(settings.readonly); const codeEditor = testBed.component.find('EuiCodeEditor'); expect(JSON.parse(codeEditor.props().value as string)).toEqual({ @@ -254,9 +252,9 @@ describe.skip('', () => { expect(find('clientInput').props().defaultValue).toBe(settings.client); expect(find('bucketInput').props().defaultValue).toBe(settings.bucket); expect(find('basePathInput').props().defaultValue).toBe(settings.basePath); - expect(find('compressToggle').props().checked).toBe(settings.compress); + expect(find('compressToggle').props()['aria-checked']).toBe(settings.compress); expect(find('chunkSizeInput').props().defaultValue).toBe(settings.chunkSize); - expect(find('serverSideEncryptionToggle').props().checked).toBe( + expect(find('serverSideEncryptionToggle').props()['aria-checked']).toBe( settings.serverSideEncryption ); expect(find('bufferSizeInput').props().defaultValue).toBe(settings.bufferSize); @@ -268,7 +266,7 @@ describe.skip('', () => { expect(find('maxRestoreBytesInput').props().defaultValue).toBe( settings.maxRestoreBytesPerSec ); - expect(find('readOnlyToggle').props().checked).toBe(settings.readonly); + expect(find('readOnlyToggle').props()['aria-checked']).toBe(settings.readonly); }); }); }); diff --git a/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_list.tsx b/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_list.tsx index dbbc0e09111eb..05bac544f924f 100644 --- a/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_list.tsx +++ b/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_list.tsx @@ -135,7 +135,7 @@ export const RepositoryList: React.FunctionComponent Date: Thu, 2 Jan 2020 12:14:39 -0500 Subject: [PATCH 2/4] set default timezone for CI --- .../__jest__/client_integration/home.test.ts | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/home.test.ts b/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/home.test.ts index 799d2bd666759..ab99a209aad06 100644 --- a/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/home.test.ts +++ b/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/home.test.ts @@ -39,6 +39,8 @@ describe('', () => { const { server, httpRequestsMockHelpers } = setupEnvironment(); let testBed: HomeTestBed; + moment.tz.setDefault('America/New_York'); + afterAll(() => { server.restore(); }); @@ -453,12 +455,11 @@ describe('', () => { test('should list them in the table', async () => { const { table } = testBed; - const { tableCellsValues } = table.getMetaData('snapshotTable'); + tableCellsValues.forEach((row, i) => { const snapshot = snapshots[i]; const startTime = moment(new Date(snapshot.startTimeInMillis)); - const timezone = moment.tz.guess(); expect(row).toEqual([ '', // Checkbox @@ -467,7 +468,7 @@ describe('', () => { snapshot.indices.length.toString(), // Indices snapshot.shards.total.toString(), // Shards snapshot.shards.failed.toString(), // Failed shards - startTime.tz(timezone).format('MMMM D, YYYY h:mm A z'), // Start time + startTime.format('MMMM D, YYYY h:mm A z'), // Start time `${Math.ceil(snapshot.durationInMillis / 1000).toString()}s`, // Duration '', ]); @@ -607,7 +608,6 @@ describe('', () => { const { find } = testBed; const startTime = moment(new Date(startTimeInMillis)); const endTime = moment(new Date(endTimeInMillis)); - const timezone = moment.tz.guess(); expect(find('snapshotDetail.version.value').text()).toBe( `${version} / ${versionId}` @@ -622,10 +622,10 @@ describe('', () => { indices.splice(0, 10).join('') ); expect(find('snapshotDetail.startTime.value').text()).toBe( - startTime.tz(timezone).format('MMMM D, YYYY h:mm A z') + startTime.format('MMMM D, YYYY h:mm A z') ); expect(find('snapshotDetail.endTime.value').text()).toBe( - endTime.tz(timezone).format('MMMM D, YYYY h:mm A z') + endTime.format('MMMM D, YYYY h:mm A z') ); }); From 3e7c96327c7edff136666f7af3254238fb419880 Mon Sep 17 00:00:00 2001 From: Alison Goryachev Date: Thu, 2 Jan 2020 20:44:47 -0500 Subject: [PATCH 3/4] mocking @kbn/i18n/react --- .../__jest__/client_integration/home.test.ts | 24 +++++++++---------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/home.test.ts b/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/home.test.ts index ab99a209aad06..c4b6f10a27924 100644 --- a/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/home.test.ts +++ b/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/home.test.ts @@ -17,16 +17,25 @@ import { } from './helpers'; import { HomeTestBed } from './helpers/home.helpers'; import { REPOSITORY_NAME } from './helpers/constant'; -import moment from 'moment-timezone'; const { setup } = pageHelpers.home; jest.mock('ui/new_platform'); + jest.mock('ui/i18n', () => { const I18nContext = ({ children }: any) => children; return { I18nContext }; }); +// Mocking FormattedDate and FormattedTime due to timezone differences on CI +jest.mock('@kbn/i18n/react', () => { + return { + ...jest.requireActual('@kbn/i18n/react'), + FormattedDate: () => '', + FormattedTime: () => '', + }; +}); + const removeWhiteSpaceOnArrayValues = (array: any[]) => array.map(value => { if (!value.trim) { @@ -39,8 +48,6 @@ describe('', () => { const { server, httpRequestsMockHelpers } = setupEnvironment(); let testBed: HomeTestBed; - moment.tz.setDefault('America/New_York'); - afterAll(() => { server.restore(); }); @@ -459,7 +466,6 @@ describe('', () => { tableCellsValues.forEach((row, i) => { const snapshot = snapshots[i]; - const startTime = moment(new Date(snapshot.startTimeInMillis)); expect(row).toEqual([ '', // Checkbox @@ -468,7 +474,7 @@ describe('', () => { snapshot.indices.length.toString(), // Indices snapshot.shards.total.toString(), // Shards snapshot.shards.failed.toString(), // Failed shards - startTime.format('MMMM D, YYYY h:mm A z'), // Start time + ' ', // Mocked start time `${Math.ceil(snapshot.durationInMillis / 1000).toString()}s`, // Duration '', ]); @@ -606,8 +612,6 @@ describe('', () => { } = snapshot1; const { find } = testBed; - const startTime = moment(new Date(startTimeInMillis)); - const endTime = moment(new Date(endTimeInMillis)); expect(find('snapshotDetail.version.value').text()).toBe( `${version} / ${versionId}` @@ -621,12 +625,6 @@ describe('', () => { expect(find('snapshotDetail.indices.value').text()).toContain( indices.splice(0, 10).join('') ); - expect(find('snapshotDetail.startTime.value').text()).toBe( - startTime.format('MMMM D, YYYY h:mm A z') - ); - expect(find('snapshotDetail.endTime.value').text()).toBe( - endTime.format('MMMM D, YYYY h:mm A z') - ); }); test('should indicate the different snapshot states', async () => { From 3602ae905f83b2dddcb09ad15b9d5606142b585f Mon Sep 17 00:00:00 2001 From: Alison Goryachev Date: Fri, 3 Jan 2020 09:07:56 -0500 Subject: [PATCH 4/4] address review feedback and fix linting error --- .../__jest__/client_integration/home.test.ts | 9 +-------- .../sections/home/repository_list/repository_list.tsx | 2 +- 2 files changed, 2 insertions(+), 9 deletions(-) diff --git a/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/home.test.ts b/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/home.test.ts index c4b6f10a27924..aa659441043ae 100644 --- a/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/home.test.ts +++ b/x-pack/legacy/plugins/snapshot_restore/__jest__/client_integration/home.test.ts @@ -602,14 +602,7 @@ describe('', () => { describe('summary tab', () => { test('should set the correct summary values', () => { - const { - version, - versionId, - uuid, - indices, - endTimeInMillis, - startTimeInMillis, - } = snapshot1; + const { version, versionId, uuid, indices } = snapshot1; const { find } = testBed; diff --git a/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_list.tsx b/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_list.tsx index 05bac544f924f..e387e844bda8c 100644 --- a/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_list.tsx +++ b/x-pack/legacy/plugins/snapshot_restore/public/app/sections/home/repository_list/repository_list.tsx @@ -135,7 +135,7 @@ export const RepositoryList: React.FunctionComponent