Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import { setup as repositoryEditSetup } from './repository_edit.helpers';
import { setup as policyAddSetup } from './policy_add.helpers';
import { setup as policyEditSetup } from './policy_edit.helpers';
import { setup as restoreSnapshotSetup } from './restore_snapshot.helpers';
import { setup as snapshotListSetup } from './snapshot_list.helpers';

export type { TestBed } from '@kbn/test/jest';
export { nextTick, getRandomString, findTestSubject, delay } from '@kbn/test/jest';
Expand All @@ -25,4 +26,5 @@ export const pageHelpers = {
policyAdd: { setup: policyAddSetup },
policyEdit: { setup: policyEditSetup },
restoreSnapshot: { setup: restoreSnapshotSetup },
snapshotList: { setup: snapshotListSetup },
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
/*
* Copyright Elasticsearch B.V. and/or licensed to Elasticsearch B.V. under one
* or more contributor license agreements. Licensed under the Elastic License
* 2.0; you may not use this file except in compliance with the Elastic License
* 2.0.
*/

import { act } from 'react-dom/test-utils';
import { TestBedConfig, registerTestBed, TestBed } from '@kbn/test/jest';

import { BASE_PATH } from '../../../public/application/constants';
import { SnapshotList } from '../../../public/application/sections/home/snapshot_list';
import { WithAppDependencies } from './setup_environment';

const getTestBedConfig = (query?: string): TestBedConfig => ({
memoryRouter: {
initialEntries: [`${BASE_PATH}/snapshots${query ?? ''}`],
componentRoutePath: `${BASE_PATH}/snapshots/:repositoryName?/:snapshotId*`,
},
});

const initTestBed = (query?: string) =>
registerTestBed(WithAppDependencies(SnapshotList), getTestBedConfig(query))();

export interface SnapshotListTestBed extends TestBed {
actions: {
setSearchText: (value: string, advanceTime?: boolean) => void;
searchErrorExists: () => boolean;
getSearchErrorText: () => string;
};
}

const searchBarSelector = 'snapshotListSearch';
const searchErrorSelector = 'snapshotListSearchError';

export const setup = async (query?: string): Promise<SnapshotListTestBed> => {
const testBed = await initTestBed(query);
const { form, component, find, exists } = testBed;

const setSearchText = async (value: string, advanceTime = true) => {
await act(async () => {
form.setInputValue(searchBarSelector, value);
});
component.update();
if (advanceTime) {
await act(async () => {
jest.advanceTimersByTime(500);
});
component.update();
}
};

const searchErrorExists = (): boolean => {
return exists(searchErrorSelector);
};

const getSearchErrorText = (): string => {
return find(searchErrorSelector).text();
};

return {
...testBed,
actions: {
setSearchText,
searchErrorExists,
getSearchErrorText,
},
};
};
Original file line number Diff line number Diff line change
Expand Up @@ -32,16 +32,6 @@ jest.mock('@kbn/i18n-react', () => {
};
});

jest.mock('../../common/constants', () => {
const original = jest.requireActual('../../common/constants');

return {
...original,
// Mocking this value to a lower number in order to more easily trigger the max snapshots warning in the tests
SNAPSHOT_LIST_MAX_SIZE: 2,
};
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This old mock was used for testing a warning callout about only showing a limited number of snapshots. The warning was removed in #110266

const removeWhiteSpaceOnArrayValues = (array: any[]) =>
array.map((value) => {
if (!value.trim) {
Expand Down
Loading