Skip to content

Commit

Permalink
Refs #38107 - add test for BootedContainerImagesPage
Browse files Browse the repository at this point in the history
  • Loading branch information
ianballou committed Jan 21, 2025
1 parent 1567d5d commit 9623c1c
Show file tree
Hide file tree
Showing 2 changed files with 85 additions and 0 deletions.
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;
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);
});

0 comments on commit 9623c1c

Please sign in to comment.