From baefa79bb81a795e1367eee03e5a28c7ced499a7 Mon Sep 17 00:00:00 2001 From: Thomas Lavocat Date: Tue, 8 Aug 2023 15:19:54 +0200 Subject: [PATCH] tests/wizard/azure: separate tests A weird error occurs because when the tests are executing together. To avoid that, as a temporary measure, separate the last test in a separate file to ensure insolation from its peers. --- .../CreateImageWizard.azure.beta.2.test.js | 69 +++++++++++++++++++ .../CreateImageWizard.azure.beta.test.js | 14 ---- 2 files changed, 69 insertions(+), 14 deletions(-) create mode 100644 src/test/Components/CreateImageWizard/CreateImageWizard.azure.beta.2.test.js diff --git a/src/test/Components/CreateImageWizard/CreateImageWizard.azure.beta.2.test.js b/src/test/Components/CreateImageWizard/CreateImageWizard.azure.beta.2.test.js new file mode 100644 index 00000000..196089e0 --- /dev/null +++ b/src/test/Components/CreateImageWizard/CreateImageWizard.azure.beta.2.test.js @@ -0,0 +1,69 @@ +import '@testing-library/jest-dom'; + +import { screen } from '@testing-library/react'; +import { rest } from 'msw'; + +import { PROVISIONING_API } from '../../../constants.js'; +import { server } from '../../mocks/server.js'; +import { + clickNext, + renderWithReduxRouter, +} from '../../testUtils'; + +jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({ + useChrome: () => ({ + auth: { + getUser: () => { + return { + identity: { + internal: { + org_id: 5, + }, + }, + }; + }, + }, + isBeta: () => true, + isProd: () => true, + getEnvironment: () => 'prod', + }), +})); + +describe('Step Upload to Azure', () => { + beforeAll(() => { + // scrollTo is not defined in jsdom + window.HTMLElement.prototype.scrollTo = function () {}; + }); + + afterEach(() => { + jest.clearAllMocks(); + }); + + const setUp = async () => { + renderWithReduxRouter('imagewizard', {}); + // select aws as upload destination + const azureTile = screen.getByTestId('upload-azure'); + azureTile.click(); + + await clickNext(); + + expect(screen.getByRole('heading', { level: 1 })).toHaveTextContent( + 'Target environment - Microsoft Azure' + ); + }; + + test('component renders error state correctly', async () => { + setUp(); + server.use( + rest.get(`${PROVISIONING_API}/sources`, (req, res, ctx) => + res(ctx.status(500)) + ) + ); + + await screen.findByText( + /Sources cannot be reached, try again later or enter an account info for upload manually\./i + ); + // + }); + // set test timeout on 10 seconds +}, 15000); diff --git a/src/test/Components/CreateImageWizard/CreateImageWizard.azure.beta.test.js b/src/test/Components/CreateImageWizard/CreateImageWizard.azure.beta.test.js index cd0df61c..bac3e396 100644 --- a/src/test/Components/CreateImageWizard/CreateImageWizard.azure.beta.test.js +++ b/src/test/Components/CreateImageWizard/CreateImageWizard.azure.beta.test.js @@ -156,19 +156,5 @@ describe('Step Upload to Azure', () => { expect(groups).toBeInTheDocument(); expect(screen.getByLabelText('Resource group theirGroup2')).toBeVisible(); }); - - test('component renders error state correctly', async () => { - setUp(); - server.use( - rest.get(`${PROVISIONING_API}/sources`, (req, res, ctx) => - res(ctx.status(500)) - ) - ); - - await screen.findByText( - /Sources cannot be reached, try again later or enter an account info for upload manually\./i - ); - // - }); // set test timeout on 10 seconds }, 15000);