From 18f08a190f19db99b9eb3840de5b1ba273469a48 Mon Sep 17 00:00:00 2001 From: regexowl Date: Wed, 8 May 2024 17:23:59 +0200 Subject: [PATCH] test: Update tests after adding SaveAndBuild modal This updates tests with a `openAndDismissSaveAndBuildModal` function that handles closing the SaveAndBuild modal after clicking on Create blueprint for the first time. --- .../steps/Review/Footer/CreateDropdown.tsx | 7 ++++++- .../CreateImageWizardV2/CreateImageWizard.test.tsx | 14 ++++++++++---- .../steps/Details/Details.test.tsx | 4 ++++ .../FileSystemConfiguration.test.tsx | 4 ++++ .../steps/FirstBoot/Firstboot.test.tsx | 4 ++++ .../steps/ImageOutput/TargetEnvironment.test.tsx | 12 ++++++------ .../CreateImageWizardV2/steps/Oscap/Oscap.test.tsx | 4 ++++ .../steps/Packages/Packages.test.tsx | 4 ++++ .../steps/Registration/Registration.test.tsx | 4 ++++ .../steps/Repositories/Repositories.test.tsx | 4 ++++ .../steps/Snapshot/Snapshot.test.tsx | 11 ++++++----- .../steps/TargetEnvironment/Aws/AwsTarget.test.tsx | 4 ++++ .../TargetEnvironment/Azure/AzureTarget.test.tsx | 4 ++++ .../steps/TargetEnvironment/GCPTarget.test.tsx | 4 ++++ .../TargetEnvironment/TargetEnvironment.test.tsx | 4 ++++ .../CreateImageWizardV2/wizardTestUtils.tsx | 11 +++++++++++ 16 files changed, 83 insertions(+), 16 deletions(-) diff --git a/src/Components/CreateImageWizardV2/steps/Review/Footer/CreateDropdown.tsx b/src/Components/CreateImageWizardV2/steps/Review/Footer/CreateDropdown.tsx index d6c46651f8..96990bddd4 100644 --- a/src/Components/CreateImageWizardV2/steps/Review/Footer/CreateDropdown.tsx +++ b/src/Components/CreateImageWizardV2/steps/Review/Footer/CreateDropdown.tsx @@ -82,7 +82,12 @@ export const CreateSaveButton = ({ onClose={handleClose} width="50%" actions={[ - , ]} diff --git a/src/test/Components/CreateImageWizardV2/CreateImageWizard.test.tsx b/src/test/Components/CreateImageWizardV2/CreateImageWizard.test.tsx index 499a18bb69..f02964f6d3 100644 --- a/src/test/Components/CreateImageWizardV2/CreateImageWizard.test.tsx +++ b/src/test/Components/CreateImageWizardV2/CreateImageWizard.test.tsx @@ -12,7 +12,10 @@ import { import userEvent from '@testing-library/user-event'; import { rest } from 'msw'; -import { enterBlueprintName } from './wizardTestUtils'; +import { + enterBlueprintName, + openAndDismissSaveAndBuildModal, +} from './wizardTestUtils'; import CreateImageWizard from '../../../Components/CreateImageWizardV2/CreateImageWizard'; import ShareImageModal from '../../../Components/ShareImageModal/ShareImageModal'; @@ -421,6 +424,9 @@ describe('Step Upload to AWS', () => { await clickNext(); await enterBlueprintName(); await clickNext(); + // informational modal pops up in the first test only as it's tied + // to a 'imageBuilder.saveAndBuildModalSeen' variable in localStorage + await openAndDismissSaveAndBuildModal(); await user.click( await screen.findByRole('button', { name: /Create blueprint/ }) @@ -1084,9 +1090,9 @@ describe('Step Review', () => { test('has Registration expandable section for rhel', async () => { await setUp(); const targetExpandable = screen.getByText(/target environments/i); - const registrationExpandable = screen.getByRole('button', { - name: /registration/i, - }); + const registrationExpandable = screen.getByTestId( + 'registration-expandable' + ); const contentExpandable = await screen.findByTestId('content-expandable'); const fscExpandable = screen.getByTestId( diff --git a/src/test/Components/CreateImageWizardV2/steps/Details/Details.test.tsx b/src/test/Components/CreateImageWizardV2/steps/Details/Details.test.tsx index e12446d1c3..5338f8870e 100644 --- a/src/test/Components/CreateImageWizardV2/steps/Details/Details.test.tsx +++ b/src/test/Components/CreateImageWizardV2/steps/Details/Details.test.tsx @@ -10,6 +10,7 @@ import { enterBlueprintName, goToRegistrationStep, interceptBlueprintRequest, + openAndDismissSaveAndBuildModal, renderCreateMode, } from '../../wizardTestUtils'; @@ -87,6 +88,9 @@ describe('registration request generated correctly', () => { await goToDetailsStep(); await enterBlueprintName(); await goToReviewStep(); + // informational modal pops up in the first test only as it's tied + // to a 'imageBuilder.saveAndBuildModalSeen' variable in localStorage + await openAndDismissSaveAndBuildModal(); const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT); const expectedRequest = { ...blueprintRequest }; diff --git a/src/test/Components/CreateImageWizardV2/steps/FileSystemConfiguration/FileSystemConfiguration.test.tsx b/src/test/Components/CreateImageWizardV2/steps/FileSystemConfiguration/FileSystemConfiguration.test.tsx index 1e259ec9e2..c4b24d27e2 100644 --- a/src/test/Components/CreateImageWizardV2/steps/FileSystemConfiguration/FileSystemConfiguration.test.tsx +++ b/src/test/Components/CreateImageWizardV2/steps/FileSystemConfiguration/FileSystemConfiguration.test.tsx @@ -13,6 +13,7 @@ import { clickRegisterLater, enterBlueprintName, interceptBlueprintRequest, + openAndDismissSaveAndBuildModal, renderCreateMode, } from '../../wizardTestUtils'; @@ -114,6 +115,9 @@ describe('file system configuration request generated correctly', () => { await goToFileSystemConfigurationStep(); await clickManuallyConfigurePartitions(); await goToReviewStep(); + // informational modal pops up in the first test only as it's tied + // to a 'imageBuilder.saveAndBuildModalSeen' variable in localStorage + await openAndDismissSaveAndBuildModal(); const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT); const expectedRequest = { diff --git a/src/test/Components/CreateImageWizardV2/steps/FirstBoot/Firstboot.test.tsx b/src/test/Components/CreateImageWizardV2/steps/FirstBoot/Firstboot.test.tsx index bc3bc9fbcf..8abbb4ead7 100644 --- a/src/test/Components/CreateImageWizardV2/steps/FirstBoot/Firstboot.test.tsx +++ b/src/test/Components/CreateImageWizardV2/steps/FirstBoot/Firstboot.test.tsx @@ -13,6 +13,7 @@ import { clickRegisterLater, enterBlueprintName, interceptBlueprintRequest, + openAndDismissSaveAndBuildModal, renderCreateMode, } from '../../wizardTestUtils'; @@ -110,6 +111,9 @@ describe('First Boot step', () => { await openCodeEditor(); await uploadFile(); await goToReviewStep(); + // informational modal pops up in the first test only as it's tied + // to a 'imageBuilder.saveAndBuildModalSeen' variable in localStorage + await openAndDismissSaveAndBuildModal(); const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT); const expectedRequest = { diff --git a/src/test/Components/CreateImageWizardV2/steps/ImageOutput/TargetEnvironment.test.tsx b/src/test/Components/CreateImageWizardV2/steps/ImageOutput/TargetEnvironment.test.tsx index 7eab7189dd..78bc7e366a 100644 --- a/src/test/Components/CreateImageWizardV2/steps/ImageOutput/TargetEnvironment.test.tsx +++ b/src/test/Components/CreateImageWizardV2/steps/ImageOutput/TargetEnvironment.test.tsx @@ -332,9 +332,9 @@ describe('set target using query parameter', () => { test('image-installer (query parameter provided)', async () => { await renderCreateMode({ target: 'iso' }); await clickToReview(); - const targetExpandable = await screen.findByRole('button', { - name: /Target environments/, - }); + const targetExpandable = await screen.findByTestId( + 'target-environments-expandable' + ); await userEvent.click(targetExpandable); await screen.findByText('Bare metal - Installer (.iso)'); }); @@ -342,9 +342,9 @@ describe('set target using query parameter', () => { test('guest-installer (query parameter provided)', async () => { await renderCreateMode({ target: 'qcow2' }); await clickToReview(); - const targetExpandable = await screen.findByRole('button', { - name: /Target environments/, - }); + const targetExpandable = await screen.findByTestId( + 'target-environments-expandable' + ); await userEvent.click(targetExpandable); await screen.findByText('Virtualization - Guest image (.qcow2)'); }); diff --git a/src/test/Components/CreateImageWizardV2/steps/Oscap/Oscap.test.tsx b/src/test/Components/CreateImageWizardV2/steps/Oscap/Oscap.test.tsx index 0ca583a40b..93ef788bbc 100644 --- a/src/test/Components/CreateImageWizardV2/steps/Oscap/Oscap.test.tsx +++ b/src/test/Components/CreateImageWizardV2/steps/Oscap/Oscap.test.tsx @@ -14,6 +14,7 @@ import { enterBlueprintName, interceptBlueprintRequest, interceptEditBlueprintRequest, + openAndDismissSaveAndBuildModal, renderCreateMode, renderEditMode, } from '../../wizardTestUtils'; @@ -123,6 +124,9 @@ describe('oscap', () => { await goToOscapStep(); await selectProfile(); await goToReviewStep(); + // informational modal pops up in the first test only as it's tied + // to a 'imageBuilder.saveAndBuildModalSeen' variable in localStorage + await openAndDismissSaveAndBuildModal(); const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT); diff --git a/src/test/Components/CreateImageWizardV2/steps/Packages/Packages.test.tsx b/src/test/Components/CreateImageWizardV2/steps/Packages/Packages.test.tsx index cd0e10aea3..16fcf79d63 100644 --- a/src/test/Components/CreateImageWizardV2/steps/Packages/Packages.test.tsx +++ b/src/test/Components/CreateImageWizardV2/steps/Packages/Packages.test.tsx @@ -9,6 +9,7 @@ import { clickRegisterLater, enterBlueprintName, interceptBlueprintRequest, + openAndDismissSaveAndBuildModal, renderCreateMode, } from '../../wizardTestUtils'; @@ -108,6 +109,9 @@ describe('packages request generated correctly', () => { await searchForPackage(); await selectFirstPackage(); await goToReviewStep(); + // informational modal pops up in the first test only as it's tied + // to a 'imageBuilder.saveAndBuildModalSeen' variable in localStorage + await openAndDismissSaveAndBuildModal(); const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT); const expectedRequest: CreateBlueprintRequest = { diff --git a/src/test/Components/CreateImageWizardV2/steps/Registration/Registration.test.tsx b/src/test/Components/CreateImageWizardV2/steps/Registration/Registration.test.tsx index 157579c32e..aa30743ae3 100644 --- a/src/test/Components/CreateImageWizardV2/steps/Registration/Registration.test.tsx +++ b/src/test/Components/CreateImageWizardV2/steps/Registration/Registration.test.tsx @@ -13,6 +13,7 @@ import { interceptBlueprintRequest, goToRegistrationStep, clickRegisterLater, + openAndDismissSaveAndBuildModal, } from '../../wizardTestUtils'; jest.mock('@redhat-cloud-services/frontend-components/useChrome', () => ({ @@ -99,6 +100,9 @@ describe('registration request generated correctly', () => { await goToRegistrationStep(); await selectActivationKey(); await goToReviewStep(); + // informational modal pops up in the first test only as it's tied + // to a 'imageBuilder.saveAndBuildModalSeen' variable in localStorage + await openAndDismissSaveAndBuildModal(); const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT); const expectedSubscription = { diff --git a/src/test/Components/CreateImageWizardV2/steps/Repositories/Repositories.test.tsx b/src/test/Components/CreateImageWizardV2/steps/Repositories/Repositories.test.tsx index c61c8395d7..ef8c3c1027 100644 --- a/src/test/Components/CreateImageWizardV2/steps/Repositories/Repositories.test.tsx +++ b/src/test/Components/CreateImageWizardV2/steps/Repositories/Repositories.test.tsx @@ -13,6 +13,7 @@ import { clickRegisterLater, enterBlueprintName, interceptBlueprintRequest, + openAndDismissSaveAndBuildModal, renderCreateMode, } from '../../wizardTestUtils'; @@ -129,6 +130,9 @@ describe('repositories request generated correctly', () => { await goToRepositoriesStep(); await selectFirstRepository(); await goToReviewStep(); + // informational modal pops up in the first test only as it's tied + // to a 'imageBuilder.saveAndBuildModalSeen' variable in localStorage + await openAndDismissSaveAndBuildModal(); const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT); const expectedRequest: CreateBlueprintRequest = { diff --git a/src/test/Components/CreateImageWizardV2/steps/Snapshot/Snapshot.test.tsx b/src/test/Components/CreateImageWizardV2/steps/Snapshot/Snapshot.test.tsx index 8a53c04f5a..2776d73e05 100644 --- a/src/test/Components/CreateImageWizardV2/steps/Snapshot/Snapshot.test.tsx +++ b/src/test/Components/CreateImageWizardV2/steps/Snapshot/Snapshot.test.tsx @@ -13,6 +13,7 @@ import { clickRegisterLater, enterBlueprintName, interceptBlueprintRequest, + openAndDismissSaveAndBuildModal, renderCreateMode, } from '../../wizardTestUtils'; @@ -76,11 +77,7 @@ const updateDatePickerWithValue = async (date: string) => { }; const clickContentDropdown = async () => { - await userEvent.click( - ( - await screen.findAllByRole('button', { name: /Content/i }) - )[1] - ); + await userEvent.click(await screen.findByTestId('content-expandable')); }; const getSnapshotMethodElement = async () => @@ -127,6 +124,10 @@ describe('repository snapshot tab - ', () => { // Check that the button is clickable (has 1 repo selected) expect(snapshotMethodElement).toHaveAttribute('aria-disabled', 'false'); + // informational modal pops up in the first test only as it's tied + // to a 'imageBuilder.saveAndBuildModalSeen' variable in localStorage + await openAndDismissSaveAndBuildModal(); + // Check the date was passed correctly to the blueprint const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT); blueprintRequest.image_requests[0].snapshot_date = '2024-04-22'; diff --git a/src/test/Components/CreateImageWizardV2/steps/TargetEnvironment/Aws/AwsTarget.test.tsx b/src/test/Components/CreateImageWizardV2/steps/TargetEnvironment/Aws/AwsTarget.test.tsx index 8f4612d228..0e1c0755ab 100644 --- a/src/test/Components/CreateImageWizardV2/steps/TargetEnvironment/Aws/AwsTarget.test.tsx +++ b/src/test/Components/CreateImageWizardV2/steps/TargetEnvironment/Aws/AwsTarget.test.tsx @@ -12,6 +12,7 @@ import { clickRegisterLater, enterBlueprintName, interceptBlueprintRequest, + openAndDismissSaveAndBuildModal, renderCreateMode, } from '../../../wizardTestUtils'; @@ -101,6 +102,9 @@ describe('aws image type request generated correctly', () => { await goToAwsStep(); await selectSource(); await goToReview(); + // informational modal pops up in the first test only as it's tied + // to a 'imageBuilder.saveAndBuildModalSeen' variable in localStorage + await openAndDismissSaveAndBuildModal(); const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT); const expectedImageRequest: ImageRequest = { diff --git a/src/test/Components/CreateImageWizardV2/steps/TargetEnvironment/Azure/AzureTarget.test.tsx b/src/test/Components/CreateImageWizardV2/steps/TargetEnvironment/Azure/AzureTarget.test.tsx index af6967740e..895e9a155f 100644 --- a/src/test/Components/CreateImageWizardV2/steps/TargetEnvironment/Azure/AzureTarget.test.tsx +++ b/src/test/Components/CreateImageWizardV2/steps/TargetEnvironment/Azure/AzureTarget.test.tsx @@ -12,6 +12,7 @@ import { clickRegisterLater, enterBlueprintName, interceptBlueprintRequest, + openAndDismissSaveAndBuildModal, renderCreateMode, } from '../../../wizardTestUtils'; @@ -128,6 +129,9 @@ describe('azure image type request generated correctly', () => { await selectSource(); await selectResourceGroup(); await goToReview(); + // informational modal pops up in the first test only as it's tied + // to a 'imageBuilder.saveAndBuildModalSeen' variable in localStorage + await openAndDismissSaveAndBuildModal(); const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT); const expectedImageRequest: ImageRequest = { diff --git a/src/test/Components/CreateImageWizardV2/steps/TargetEnvironment/GCPTarget.test.tsx b/src/test/Components/CreateImageWizardV2/steps/TargetEnvironment/GCPTarget.test.tsx index b553e0a10f..86ad566aad 100644 --- a/src/test/Components/CreateImageWizardV2/steps/TargetEnvironment/GCPTarget.test.tsx +++ b/src/test/Components/CreateImageWizardV2/steps/TargetEnvironment/GCPTarget.test.tsx @@ -15,6 +15,7 @@ import { enterBlueprintName, imageRequest, interceptBlueprintRequest, + openAndDismissSaveAndBuildModal, renderCreateMode, } from '../../wizardTestUtils'; @@ -97,6 +98,9 @@ describe('gcp image type request generated correctly', () => { await clickGCPTarget(); await selectGoogleAccount('google-account'); await goToReview(); + // informational modal pops up in the first test only as it's tied + // to a 'imageBuilder.saveAndBuildModalSeen' variable in localStorage + await openAndDismissSaveAndBuildModal(); const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT); const expectedImageRequest = createGCPCloudImage('gcp', { diff --git a/src/test/Components/CreateImageWizardV2/steps/TargetEnvironment/TargetEnvironment.test.tsx b/src/test/Components/CreateImageWizardV2/steps/TargetEnvironment/TargetEnvironment.test.tsx index cb1f80ce75..1044142f5c 100644 --- a/src/test/Components/CreateImageWizardV2/steps/TargetEnvironment/TargetEnvironment.test.tsx +++ b/src/test/Components/CreateImageWizardV2/steps/TargetEnvironment/TargetEnvironment.test.tsx @@ -22,6 +22,7 @@ import { goToRegistrationStep, imageRequest, interceptBlueprintRequest, + openAndDismissSaveAndBuildModal, renderCreateMode, } from '../../wizardTestUtils'; @@ -134,6 +135,9 @@ describe('distribution request generated correctly', () => { await renderCreateMode(); await selectRhel8(); await goToReviewStep(); + // informational modal pops up in the first test only as it's tied + // to a 'imageBuilder.saveAndBuildModalSeen' variable in localStorage + await openAndDismissSaveAndBuildModal(); const receivedRequest = await interceptBlueprintRequest(CREATE_BLUEPRINT); const expectedRequest: CreateBlueprintRequest = { diff --git a/src/test/Components/CreateImageWizardV2/wizardTestUtils.tsx b/src/test/Components/CreateImageWizardV2/wizardTestUtils.tsx index bb033557dd..cdc8bac32a 100644 --- a/src/test/Components/CreateImageWizardV2/wizardTestUtils.tsx +++ b/src/test/Components/CreateImageWizardV2/wizardTestUtils.tsx @@ -108,6 +108,17 @@ export const enterBlueprintName = async (name: string = 'Red Velvet') => { await userEvent.type(blueprintName, name); }; +export const openAndDismissSaveAndBuildModal = async () => { + await userEvent.click( + await screen.findByRole('button', { + name: 'Create blueprint', + }) + ); + await userEvent.click( + await screen.findByTestId('close-button-saveandbuild-modal') + ); +}; + export const interceptBlueprintRequest = async (requestPathname: string) => { const receivedRequestPromise = spyOnRequest(requestPathname, 'POST');