Skip to content

Commit

Permalink
chore: cleaned up tests, only one assertion in waitFor and use findBy (
Browse files Browse the repository at this point in the history
  • Loading branch information
specter-flq authored Sep 30, 2024
1 parent 34201d2 commit 010bdc0
Showing 1 changed file with 16 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ describe('CitrixRDPConfiguration', () => {

await user.click(panelSwitch);

const panelDialogTitle = screen.getByText(dialogTitle, { exact: false });
const panelDialogTitle = await screen.findByText(dialogTitle, { exact: false });
const panelDialogDescription = screen.getByText(/analysis has been added with citrix configuration/i);

expect(panelSwitch).toBeInTheDocument();
Expand All @@ -95,11 +95,9 @@ describe('CitrixRDPConfiguration', () => {

await user.click(cancelButton);

await waitFor(() => {
expect(panelDialogTitle).not.toBeInTheDocument();
expect(panelDialogDescription).not.toBeInTheDocument();
expect(panelSwitch).not.toBeChecked();
});
await waitFor(() => expect(panelDialogTitle).not.toBeInTheDocument());
expect(panelDialogDescription).not.toBeInTheDocument();
expect(panelSwitch).not.toBeChecked();
});

it('on clicking switch shows modal and when clicking confirm closes it and switch changes to enabled', async () => {
Expand All @@ -108,7 +106,7 @@ describe('CitrixRDPConfiguration', () => {

await user.click(panelSwitch);

const panelDialogTitle = screen.getByText(dialogTitle, { exact: false });
const panelDialogTitle = await screen.findByText(dialogTitle, { exact: false });
const panelDialogDescription = screen.getByText(/analysis has been added with citrix configuration/i);

expect(panelSwitch).toBeInTheDocument();
Expand All @@ -120,11 +118,9 @@ describe('CitrixRDPConfiguration', () => {

await user.click(confirmButton);

await waitFor(() => {
expect(panelDialogTitle).not.toBeInTheDocument();
expect(panelDialogDescription).not.toBeInTheDocument();
expect(panelSwitch).toBeChecked();
});
await waitFor(() => expect(panelDialogTitle).not.toBeInTheDocument());
expect(panelDialogDescription).not.toBeInTheDocument();
expect(panelSwitch).toBeChecked();
});
});
describe('Click on switch to disable', () => {
Expand All @@ -139,7 +135,7 @@ describe('CitrixRDPConfiguration', () => {

await user.click(panelSwitch);

const panelDialogTitle = screen.getByText(dialogTitle, { exact: false });
const panelDialogTitle = await screen.findByText(dialogTitle, { exact: false });
const panelDialogDescription = screen.getByText(/analysis has been removed with citrix configuration/i);

expect(panelSwitch).toBeInTheDocument();
Expand All @@ -151,19 +147,17 @@ describe('CitrixRDPConfiguration', () => {

await user.click(cancelButton);

await waitFor(() => {
expect(panelDialogTitle).not.toBeInTheDocument();
expect(panelDialogDescription).not.toBeInTheDocument();
expect(panelSwitch).toBeChecked();
});
await waitFor(() => expect(panelDialogTitle).not.toBeInTheDocument());
expect(panelDialogDescription).not.toBeInTheDocument();
expect(panelSwitch).toBeChecked();
});
it('on clicking switch shows modal and when clicking confirm closes it and switch changes to disabled', async () => {
const panelSwitch = screen.getByRole('switch');
const user = userEvent.setup();

await user.click(panelSwitch);

const panelDialogTitle = screen.getByText(dialogTitle, { exact: false });
const panelDialogTitle = await screen.findByText(dialogTitle, { exact: false });
const panelDialogDescription = screen.getByText(/analysis has been removed with citrix configuration/i);

expect(panelSwitch).toBeInTheDocument();
Expand All @@ -175,11 +169,9 @@ describe('CitrixRDPConfiguration', () => {

await user.click(confirmButton);

await waitFor(() => {
expect(panelDialogTitle).not.toBeInTheDocument();
expect(panelDialogDescription).not.toBeInTheDocument();
expect(panelSwitch).not.toBeChecked();
});
await waitFor(() => expect(panelDialogTitle).not.toBeInTheDocument());
expect(panelDialogDescription).not.toBeInTheDocument();
expect(panelSwitch).not.toBeChecked();
});
});
});

0 comments on commit 010bdc0

Please sign in to comment.