From 45e227b2b56e914297d4f0f8a04cd13f950b2874 Mon Sep 17 00:00:00 2001 From: Alison Goryachev Date: Fri, 3 Jan 2020 10:26:17 -0500 Subject: [PATCH] [SR] Enable component integration tests (#53893) --- .../__jest__/client_integration/home.test.ts | 39 +++++++------------ .../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, 35 insertions(+), 53 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 69b5ca9e2b68f9..aa659441043ae4 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) { @@ -35,9 +44,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; @@ -455,12 +462,10 @@ describe.skip('', () => { 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 @@ -469,7 +474,7 @@ describe.skip('', () => { 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 + ' ', // Mocked start time `${Math.ceil(snapshot.durationInMillis / 1000).toString()}s`, // Duration '', ]); @@ -597,19 +602,9 @@ describe.skip('', () => { 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; - 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}` @@ -623,12 +618,6 @@ describe.skip('', () => { expect(find('snapshotDetail.indices.value').text()).toContain( indices.splice(0, 10).join('') ); - expect(find('snapshotDetail.startTime.value').text()).toBe( - startTime.tz(timezone).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') - ); }); test('should indicate the different snapshot states', async () => { 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 3dc7d94ce67d5a..09757c4774314a 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 1222697956ffba..a5af9e5e5c3aa0 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 1f70755d5fd85a..82c090bc552bb1 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 cca81c0e74285e..b850114115893b 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 dbbc0e09111ebb..e387e844bda8c7 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