Skip to content

Commit

Permalink
Merge branch 'develop' into feature/storbyook-wait-fonts
Browse files Browse the repository at this point in the history
  • Loading branch information
vtsvetkov-splunk authored Jan 30, 2025
2 parents a01010d + 2a418dd commit da84e12
Show file tree
Hide file tree
Showing 5 changed files with 71 additions and 50 deletions.
60 changes: 35 additions & 25 deletions ui/src/components/CustomControl/CustomControl.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { render, screen } from '@testing-library/react';
import { act, render, screen, waitFor } from '@testing-library/react';
import React from 'react';
import userEvent from '@testing-library/user-event';
import CustomControl from './CustomControl';
Expand All @@ -18,48 +18,58 @@ const mockClearErrorMsg = jest.fn();

const FIELD_NAME = 'testCustomField';

beforeEach(() => {
const setup = async () => {
const mockConfig = getGlobalConfigMock();
setUnifiedConfig(mockConfig);

jest.mock(`${getBuildDirPath()}/custom/${MODULE}.js`, () => mockCustomControlMockForTest, {
virtual: true,
});

render(
<CustomControl
data={{
value: 'input_default',
mode: 'create',
serviceName: 'serviceName',
}}
field={FIELD_NAME}
handleChange={handleChange}
controlOptions={{
src: MODULE,
type: 'external',
}}
addCustomValidator={addingCustomValidation}
utilCustomFunctions={{
setState: mockSetState,
setErrorFieldMsg: mockSetErrorFieldMsg,
clearAllErrorMsg: mockClearErrorMsg,
setErrorMsg: mockSetErrorMsg,
}}
/>
);
});
await act(async () => {
render(
<CustomControl
data={{
value: 'input_default',
mode: 'create',
serviceName: 'serviceName',
}}
field={FIELD_NAME}
handleChange={handleChange}
controlOptions={{
src: MODULE,
type: 'external',
}}
addCustomValidator={addingCustomValidation}
utilCustomFunctions={{
setState: mockSetState,
setErrorFieldMsg: mockSetErrorFieldMsg,
clearAllErrorMsg: mockClearErrorMsg,
setErrorMsg: mockSetErrorMsg,
}}
/>
);

const loading = screen.queryByText('Loading...');
if (loading) {
await waitFor(() => expect(loading).not.toHaveTextContent('Loading...'));
}
});
};

it('should render custom component correctly', async () => {
await setup();
const renderedModal = await screen.findByTestId('customSelect');
expect(renderedModal).toBeInTheDocument();
});

it('should try to add validator', async () => {
await setup();
expect(addingCustomValidation).toHaveBeenCalled();
});

it('should correctly call handler on change', async () => {
await setup();
const selectElem = document.querySelector('select');
expect(selectElem).toBeInTheDocument();
const SELECTED_OPTION = 'input_one';
Expand Down
14 changes: 8 additions & 6 deletions ui/src/components/EntityModal/EntityModal.test.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import React from 'react';
import { render, screen, waitFor } from '@testing-library/react';
import { act, render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { http, HttpResponse } from 'msw';
import EntityModal, { EntityModalProps } from './EntityModal';
Expand Down Expand Up @@ -491,12 +491,12 @@ describe('Oauth - separated endpoint authorization', () => {

// triggering manually external oauth window behaviour after success authorization
const code = '200';
window.getMessage({ code, state: stateCodeFromUrl, error: undefined });

await waitFor(async () => {
expect(requestHandler).toHaveBeenCalledTimes(1);
await act(async () => {
window.getMessage({ code, state: stateCodeFromUrl, error: undefined });
});

expect(requestHandler).toHaveBeenCalledTimes(1);

const receivedRequest: Request = requestHandler.mock.calls[0][0];
const receivedBody = await receivedRequest.text();

Expand Down Expand Up @@ -534,7 +534,9 @@ describe('Oauth - separated endpoint authorization', () => {
// triggering manually external oauth window behaviour after success authorization
const code = '200';
const passedState = `tests${stateCodeFromUrl}`;
window.getMessage({ code, state: passedState, error: undefined });
await act(async () => {
window.getMessage({ code, state: passedState, error: undefined });
});

expect(screen.getByText(ERROR_STATE_MISSING_TRY_AGAIN)).toBeInTheDocument();
});
Expand Down
31 changes: 19 additions & 12 deletions ui/src/components/InteractAllStatusButton.test.tsx
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import React from 'react';

import { render, screen } from '@testing-library/react';
import { userEvent } from '@testing-library/user-event';
import { InputRowData, InteractAllStatusButtons } from './InteractAllStatusButton';

describe('InteractAllStatusButtons', () => {
Expand Down Expand Up @@ -95,15 +96,16 @@ describe('InteractAllStatusButtons', () => {
});

it('Deactivate All enabled rows correctly', async () => {
const user = userEvent.setup();
const disableBtn = await screen.findByText('Deactivate all');
expect(disableBtn).toBeInTheDocument();

disableBtn.click();
await user.click(disableBtn);

const yesPopUpBtn = await screen.findByText('Yes');
expect(yesPopUpBtn).toBeInTheDocument();

yesPopUpBtn.click();
await user.click(yesPopUpBtn);

expect(handleToggleStatusChange).toHaveBeenCalledWith(
allDataRowsMockUp.find((x) => x.name === 'aaaaa')
Expand All @@ -118,15 +120,16 @@ describe('InteractAllStatusButtons', () => {
});

it('Activate All disabled rows correctly', async () => {
const user = userEvent.setup();
const enableBtn = await screen.findByText('Activate all');
expect(enableBtn).toBeInTheDocument();

enableBtn.click();
await user.click(enableBtn);

const yesPopUpBtn = await screen.findByText('Yes');
expect(yesPopUpBtn).toBeInTheDocument();

yesPopUpBtn.click();
await user.click(yesPopUpBtn);

expect(handleToggleStatusChange).toHaveBeenCalledWith(
allDataRowsMockUp.find((x) => x.name === 'cccccc')
Expand All @@ -141,57 +144,61 @@ describe('InteractAllStatusButtons', () => {
});

it('Do not disable status if rejected', async () => {
const user = userEvent.setup();
const disableBtn = await screen.findByText('Deactivate all');
expect(disableBtn).toBeInTheDocument();

disableBtn.click();
await user.click(disableBtn);

const noPopUpBtn = await screen.findByText('No');
expect(noPopUpBtn).toBeInTheDocument();

noPopUpBtn.click();
await user.click(noPopUpBtn);

expect(handleToggleStatusChange).toHaveBeenCalledTimes(0);
});

it('Do not enable status if rejected', async () => {
const user = userEvent.setup();
const enableBtn = await screen.findByText('Activate all');
expect(enableBtn).toBeInTheDocument();

enableBtn.click();
await user.click(enableBtn);

const noPopUpBtn = await screen.findByText('No');
expect(noPopUpBtn).toBeInTheDocument();

noPopUpBtn.click();
await user.click(noPopUpBtn);

expect(handleToggleStatusChange).toHaveBeenCalledTimes(0);
});

it('Do not enable status if popup modal closed by X', async () => {
const user = userEvent.setup();
const enableBtn = await screen.findByText('Activate all');
expect(enableBtn).toBeInTheDocument();

enableBtn.click();
await user.click(enableBtn);

const closeXBtn = screen.getByTestId('close');
expect(closeXBtn).toBeInTheDocument();

closeXBtn.click();
await user.click(closeXBtn);

expect(handleToggleStatusChange).toHaveBeenCalledTimes(0);
});

it('Do not disable status if popup modal closed by X', async () => {
const user = userEvent.setup();
const disableBtn = await screen.findByText('Deactivate all');
expect(disableBtn).toBeInTheDocument();

disableBtn.click();
await user.click(disableBtn);

const closeXBtn = screen.getByTestId('close');
expect(closeXBtn).toBeInTheDocument();

closeXBtn.click();
await user.click(closeXBtn);

expect(handleToggleStatusChange).toHaveBeenCalledTimes(0);
});
Expand Down
7 changes: 5 additions & 2 deletions ui/src/components/table/tests/CustomTableRow.test.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { render, screen, within } from '@testing-library/react';
import { userEvent } from '@testing-library/user-event';
import React from 'react';

import { BrowserRouter } from 'react-router-dom';
Expand Down Expand Up @@ -52,7 +53,8 @@ it('Render action icons correctly', async () => {
});

it('Correctly call action handlers for page dialog', async () => {
(await screen.findAllByRole('button', { name: /edit/i }))[0].click();
const user = userEvent.setup();
await user.click((await screen.findAllByRole('button', { name: /edit/i }))[0]);

expect(handleOpenPageStyleDialog).toHaveBeenCalledWith(expect.objectContaining({}), 'edit');

Expand All @@ -66,8 +68,9 @@ it('Correctly call action handlers for page dialog', async () => {
});

it('Correctly render modal for delete action click', async () => {
const user = userEvent.setup();
// Clicking delete renders modal
(await screen.findAllByRole('button', { name: /delete/i }))[0].click();
await user.click((await screen.findAllByRole('button', { name: /delete/i }))[0]);

expect(await screen.findByRole('dialog')).toHaveTextContent('Delete Confirmation');
});
Expand Down
9 changes: 4 additions & 5 deletions ui/src/components/table/tests/TableExpansionRow.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -103,12 +103,11 @@ function setup() {
}

async function expectIntervalInExpandedRow(inputRow: HTMLElement, expectedInterval: number) {
const arrow = within(inputRow).getByRole('cell', { name: /expandable/i });
const isExpanded = arrow.getAttribute('aria-expanded');
if (isExpanded === 'false') {
await userEvent.click(arrow);
const expandable = within(inputRow).queryByRole('cell', { name: /expand/i });
if (expandable && expandable.getAttribute('aria-expanded') === 'false') {
await userEvent.click(expandable);
await waitFor(() => expect(expandable.getAttribute('aria-expanded')).not.toBe('false'));
}
await waitFor(() => expect(arrow.getAttribute('aria-expanded')).not.toBe('false'));
const loading = screen.queryByText('Loading...');
if (loading) {
await waitForElementToBeRemoved(loading);
Expand Down

0 comments on commit da84e12

Please sign in to comment.