Skip to content

Commit

Permalink
[SR] Enable component integration tests (elastic#53893)
Browse files Browse the repository at this point in the history
  • Loading branch information
alisonelizabeth committed Jan 3, 2020
1 parent 6942d0b commit 45e227b
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 53 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand All @@ -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('<SnapshotRestoreHome />', () => {
describe('<SnapshotRestoreHome />', () => {
const { server, httpRequestsMockHelpers } = setupEnvironment();
let testBed: HomeTestBed;

Expand Down Expand Up @@ -455,12 +462,10 @@ describe.skip('<SnapshotRestoreHome />', () => {

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
Expand All @@ -469,7 +474,7 @@ describe.skip('<SnapshotRestoreHome />', () => {
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
'',
]);
Expand Down Expand Up @@ -597,19 +602,9 @@ describe.skip('<SnapshotRestoreHome />', () => {

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}`
Expand All @@ -623,12 +618,6 @@ describe.skip('<SnapshotRestoreHome />', () => {
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 () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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('<PolicyAdd />', () => {
describe('<PolicyAdd />', () => {
let testBed: PolicyFormTestBed;

const { server, httpRequestsMockHelpers } = setupEnvironment();
Expand Down Expand Up @@ -195,6 +193,7 @@ describe.skip('<PolicyAdd />', () => {

const expected = {
config: {},
isManagedPolicy: false,
name: POLICY_NAME,
repository: repository.name,
retention: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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('<PolicyEdit />', () => {
describe('<PolicyEdit />', () => {
let testBed: PolicyFormTestBed;
let testBedPolicyAdd: PolicyFormTestBed;
const { server, httpRequestsMockHelpers } = setupEnvironment();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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('<RepositoryAdd />', () => {
describe('<RepositoryAdd />', () => {
let testBed: RepositoryAddTestBed;

const { server, httpRequestsMockHelpers } = setupEnvironment();
Expand Down Expand Up @@ -215,7 +213,7 @@ describe.skip('<RepositoryAdd />', () => {

// Fill step 2
form.setInputValue('locationInput', repository.settings.location);
form.selectCheckBox('compressToggle');
form.toggleEuiSwitch('compressToggle');

await act(async () => {
actions.clickSubmitButton();
Expand All @@ -240,7 +238,7 @@ describe.skip('<RepositoryAdd />', () => {
const { component, form, actions, find, exists } = testBed;

form.setInputValue('locationInput', repository.settings.location);
form.selectCheckBox('compressToggle');
form.toggleEuiSwitch('compressToggle');

const error = {
status: 400,
Expand All @@ -266,7 +264,7 @@ describe.skip('<RepositoryAdd />', () => {
// 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();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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('<RepositoryEdit />', () => {
describe('<RepositoryEdit />', () => {
let testBed: TestBed<RepositoryEditTestSubjects>;
let testBedRepositoryAdd: TestBed<RepositoryAddTestSubjects>;
const { server, httpRequestsMockHelpers } = setupEnvironment();
Expand Down Expand Up @@ -101,15 +99,15 @@ describe.skip('<RepositoryEdit />', () => {
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
);
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 () => {
Expand Down Expand Up @@ -145,7 +143,7 @@ describe.skip('<RepositoryEdit />', () => {
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
Expand All @@ -154,7 +152,7 @@ describe.skip('<RepositoryEdit />', () => {
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 () => {
Expand All @@ -176,15 +174,15 @@ describe.skip('<RepositoryEdit />', () => {
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
);
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 () => {
Expand All @@ -209,8 +207,8 @@ describe.skip('<RepositoryEdit />', () => {

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']
Expand All @@ -221,7 +219,7 @@ describe.skip('<RepositoryEdit />', () => {
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({
Expand Down Expand Up @@ -254,9 +252,9 @@ describe.skip('<RepositoryEdit />', () => {
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);
Expand All @@ -268,7 +266,7 @@ describe.skip('<RepositoryEdit />', () => {
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);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,7 @@ export const RepositoryList: React.FunctionComponent<RouteComponentProps<MatchPa
content = (
<RepositoryTable
repositories={repositories || []}
managedRepository={managedRepository.name}
managedRepository={managedRepository?.name}
reload={reload}
openRepositoryDetailsUrl={openRepositoryDetailsUrl}
onRepositoryDeleted={onRepositoryDeleted}
Expand Down

0 comments on commit 45e227b

Please sign in to comment.