-
Notifications
You must be signed in to change notification settings - Fork 297
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Refs #38107 - add test for BootedContainerImagesPage
- Loading branch information
Showing
2 changed files
with
85 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
webpack/scenes/BootedContainerImages/__tests__/bootedContainerImages.fixtures.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
import Immutable from 'seamless-immutable'; | ||
|
||
const bootedContainerImagesResponse = Immutable({ | ||
total: 2, | ||
page: 1, | ||
per_page: 20, | ||
subtotal: 2, | ||
results: [ | ||
{ | ||
bootc_booted_image: 'quay.io/centos-bootc/centos-bootc:stream10', | ||
digests: [ | ||
{ | ||
bootc_booted_digest: 'sha256:54256a998f0c62e16f3927c82b570f90bd8449a52e03daabd5fd16d6419fd572', | ||
host_count: 1, | ||
}, | ||
{ | ||
bootc_booted_digest: 'sha256:54256a998f0c62e16f3927c82b570f90bd8449a52e03daabd5fd16d6419fd573', | ||
host_count: 1, | ||
}, | ||
{ | ||
bootc_booted_digest: 'sha256:54256a998f0c62e16f3927c82b570f90bd8449a52e03daabd5fd16d6419fd574', | ||
host_count: 1, | ||
}, | ||
{ | ||
bootc_booted_digest: 'sha256:54256a998f0c62e16f3927c82b570f90bd8449a52e03daabd5fd16d6419fd575', | ||
host_count: 1, | ||
}, | ||
], | ||
}, | ||
{ | ||
bootc_booted_image: 'quay.io/centos-bootc/centos-bootc:stream9', | ||
digests: [ | ||
{ | ||
bootc_booted_digest: 'sha256:54256a998f0c62e16f3927c82b570f90bd8449a52e03daabd5fd16d6419fd576', | ||
host_count: 1, | ||
}, | ||
], | ||
}, | ||
], | ||
}); | ||
|
||
export default bootedContainerImagesResponse; |
43 changes: 43 additions & 0 deletions
43
webpack/scenes/BootedContainerImages/__tests__/bootedContainerImagesPage.test.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
import React from 'react'; | ||
import { renderWithRedux, patientlyWaitFor, act } from 'react-testing-lib-wrapper'; | ||
import { nockInstance, assertNockRequest, mockAutocomplete } from '../../../test-utils/nockWrapper'; | ||
import api from '../../../services/api'; | ||
import BOOTED_CONTAINER_IMAGES_KEY from '../BootedContainerImagesConstants'; | ||
import BootedContainerImagesPage from '../BootedContainerImagesPage'; | ||
import bootcImagesData from './bootedContainerImages.fixtures'; | ||
|
||
// const bootedContainerImagesIndexPath = api.getApiUrl('/booted_container_images'); | ||
// const renderOptions = { apiNamespace: BOOTED_CONTAINER_IMAGES_KEY }; | ||
const bootcImagesUrl = '/api/v2/hosts/bootc_images'; | ||
const autocompleteUrl = '/host_bootc_images/auto_complete_search'; | ||
const autocompleteQuery = { | ||
search: '', | ||
}; | ||
|
||
let firstImage; | ||
let secondImage; | ||
beforeEach(() => { | ||
const { results } = bootcImagesData; | ||
[firstImage, secondImage] = results; | ||
}); | ||
|
||
test('BootedContainerImagesPage renders correctly', async (done) => { | ||
const autocompleteScope = mockAutocomplete(nockInstance, autocompleteUrl, autocompleteQuery); | ||
const scope = nockInstance | ||
.get(bootcImagesUrl) | ||
.query(true) | ||
// Why does the page load twice? | ||
.times(2) | ||
.reply(200, bootcImagesData); | ||
|
||
const { queryByText, queryAllByText } = renderWithRedux(<BootedContainerImagesPage />); | ||
expect(queryByText(firstImage.bootc_booted_image)).toBeNull(); | ||
|
||
await patientlyWaitFor(() => { | ||
expect(queryByText(firstImage.bootc_booted_image)).toBeInTheDocument(); | ||
}); | ||
|
||
assertNockRequest(autocompleteScope); | ||
assertNockRequest(scope, done); | ||
act(done); | ||
}); |