Skip to content
Open
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
3 changes: 2 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@
],
"testRegex": ".*\\.spec\\.(ts|tsx|js|jsx)$",
"testEnvironmentOptions": {
"url": "http://localhost"
"url": "http://localhost",
"globalsCleanup": "on"
},
"setupFiles": [
"./__mocks__/fetch.ts",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,13 @@ import * as coreApi from '../core-api';
import * as internalApi from '../internal-api';

describe('@openshift-console/dynamic-plugin-sdk/lib/api/core-api', () => {
Object.entries(coreApi).forEach(([exportName, exportValue]) => {
it(`should export ${exportName}`, () => {
expect(exportValue).toBeDefined();
});
it.each(Object.entries(coreApi))('should export %s (export %$)', (_name, exportValue) => {
expect(exportValue).toBeDefined();
});
});

describe('@openshift-console/dynamic-plugin-sdk-internal/lib/api/internal-api', () => {
Object.entries(internalApi).forEach(([exportName, exportValue]) => {
it(`should export ${exportName}`, () => {
expect(exportValue).toBeDefined();
});
it.each(Object.entries(internalApi))('should export %s (export %$)', (_name, exportValue) => {
expect(exportValue).toBeDefined();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ describe('ResourceDropdown', () => {
});

it('should callback selected item from dropdown and change the title to selected item', async () => {
const user = userEvent.setup();
const spy = jest.fn();

const { rerender } = render(
Expand Down Expand Up @@ -229,7 +230,7 @@ describe('ResourceDropdown', () => {

// Click the dropdown button to open it
const dropdownButton = screen.getByRole('button');
await userEvent.click(dropdownButton);
await user.click(dropdownButton);

// Wait for dropdown to open and find the menu item
await waitFor(() => {
Expand All @@ -238,7 +239,7 @@ describe('ResourceDropdown', () => {

// Find and click the third item (app-group-3)
const menuItem = screen.getByRole('option', { name: /app-group-3/ });
await userEvent.click(menuItem);
await user.click(menuItem);

// Verify the dropdown button text has changed
await waitFor(() => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ describe('EnvironmentVariablesSection', () => {
});

it('should update formik data', async () => {
const user = userEvent.setup();
const initialValues: EnvironmentVariablesSectionFormData = {
formData: {
environmentVariables: [],
Expand All @@ -132,25 +133,25 @@ describe('EnvironmentVariablesSection', () => {
</Wrapper>,
);

await userEvent.click(renderResult.getByText('Add value'));
await userEvent.click(renderResult.getByText('Add value'));
await user.click(renderResult.getByText('Add value'));
await user.click(renderResult.getByText('Add value'));

expect(renderResult.queryAllByPlaceholderText('Name')).toHaveLength(3);
expect(renderResult.queryAllByPlaceholderText('Value')).toHaveLength(3);

const [name1, name2, name3] = renderResult.queryAllByPlaceholderText('Name');
const [value1, value2, value3] = renderResult.queryAllByPlaceholderText('Value');

await userEvent.type(name1, 'env key 1');
await userEvent.type(value1, 'env value 1');
await userEvent.type(name2, 'env key 2');
await userEvent.type(value2, 'env value 2');
await userEvent.type(name3, 'env key 3');
await userEvent.type(value3, 'env value 3');
await user.type(name1, 'env key 1');
await user.type(value1, 'env value 1');
await user.type(name2, 'env key 2');
await user.type(value2, 'env value 2');
await user.type(name3, 'env key 3');
await user.type(value3, 'env value 3');

// Submit
const submitButton = renderResult.getByRole('button', { name: 'Submit' });
await userEvent.click(submitButton);
await user.click(submitButton);
await waitFor(() => {
expect(onSubmit).toHaveBeenCalledTimes(1);
});
Expand All @@ -165,5 +166,5 @@ describe('EnvironmentVariablesSection', () => {
},
};
expect(onSubmit).toHaveBeenLastCalledWith(expectedFormData, expect.anything());
});
}, 30000); // userEvent.type is slow
});
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ describe('HooksSection', () => {
});

it('should render more fields when checkbox is clicked', async () => {
const user = userEvent.setup();
const initialValues: HooksSectionFormData = {
formData: {
hooks: {
Expand All @@ -88,7 +89,7 @@ describe('HooksSection', () => {
const [checkbox] = renderResult.getAllByRole('checkbox') as HTMLInputElement[];
expect(checkbox.checked).toBeFalsy();

await userEvent.click(checkbox);
await user.click(checkbox);

await waitFor(() => {
expect(checkbox.checked).toBeTruthy();
Expand Down Expand Up @@ -144,6 +145,7 @@ describe('HooksSection', () => {
});

it('should not render commands when hook type is changed to script', async () => {
const user = userEvent.setup();
const initialValues: HooksSectionFormData = {
formData: {
hooks: {
Expand All @@ -167,8 +169,8 @@ describe('HooksSection', () => {
expect(renderResult.queryAllByPlaceholderText('Command')).toHaveLength(2);
expect(renderResult.queryAllByPlaceholderText('Argument')).toHaveLength(2);

await userEvent.click(renderResult.getByTestId('type'));
await userEvent.click(renderResult.getByText('Shell script'));
await user.click(renderResult.getByTestId('type'));
await user.click(renderResult.getByText('Shell script'));

await waitFor(() => {
expect(renderResult.baseElement.querySelector('textarea')).toBeTruthy();
Expand All @@ -178,6 +180,7 @@ describe('HooksSection', () => {
});

it('should not render commands when hook type is changed to argsOnly', async () => {
const user = userEvent.setup();
const initialValues: HooksSectionFormData = {
formData: {
hooks: {
Expand All @@ -201,8 +204,8 @@ describe('HooksSection', () => {
expect(renderResult.queryAllByPlaceholderText('Command')).toHaveLength(2);
expect(renderResult.queryAllByPlaceholderText('Argument')).toHaveLength(2);

await userEvent.click(renderResult.getByTestId('type'));
await userEvent.click(renderResult.getByText('Arguments to default image entry point'));
await user.click(renderResult.getByTestId('type'));
await user.click(renderResult.getByText('Arguments to default image entry point'));

await waitFor(() => {
expect(renderResult.baseElement.querySelector('textarea')).toBeFalsy();
Expand All @@ -212,6 +215,7 @@ describe('HooksSection', () => {
});

it('should update formik data', async () => {
const user = userEvent.setup();
const initialValues: HooksSectionFormData = {
formData: {
hooks: {
Expand All @@ -232,7 +236,7 @@ describe('HooksSection', () => {
);

const [checkbox] = renderResult.getAllByRole('checkbox') as HTMLInputElement[];
await userEvent.click(checkbox);
await user.click(checkbox);

// Wait for subform
await waitFor(() => {
Expand All @@ -246,16 +250,16 @@ describe('HooksSection', () => {

// Fill out subform
const [command1] = renderResult.getAllByPlaceholderText('Command');
await userEvent.type(command1, 'echo');
await userEvent.click(renderResult.getByText('Add argument'));
await userEvent.click(renderResult.getByText('Add argument'));
await user.type(command1, 'echo');
await user.click(renderResult.getByText('Add argument'));
await user.click(renderResult.getByText('Add argument'));
const [argument1, argument2] = renderResult.getAllByPlaceholderText('Argument');
await userEvent.type(argument1, 'hello');
await userEvent.type(argument2, 'world');
await user.type(argument1, 'hello');
await user.type(argument2, 'world');

// Submit
const submitButton = renderResult.getByRole('button', { name: 'Submit' });
await userEvent.click(submitButton);
await user.click(submitButton);
await waitFor(() => {
expect(onSubmit).toHaveBeenCalledTimes(1);
});
Expand All @@ -272,5 +276,5 @@ describe('HooksSection', () => {
},
};
expect(onSubmit).toHaveBeenLastCalledWith(expectedFormData, expect.anything());
});
}, 30000); // userEvent.type is slow
});
Loading