From 68954d854b57bf4689f0102e0218df150d1ddc06 Mon Sep 17 00:00:00 2001 From: Sanne Raymaekers Date: Mon, 9 Nov 2020 16:55:51 +0100 Subject: [PATCH] test: Expand ImageTable test --- .../ImageBuildStatus/ImageBuildStatus.scss | 2 +- .../ImagesTable/ImagesTable.test.js | 57 +++++++++++++++++++ 2 files changed, 58 insertions(+), 1 deletion(-) create mode 100644 src/test/SmartComponents/ImagesTable/ImagesTable.test.js diff --git a/src/PresentationalComponents/ImageBuildStatus/ImageBuildStatus.scss b/src/PresentationalComponents/ImageBuildStatus/ImageBuildStatus.scss index a397ddc7..1bf099e2 100644 --- a/src/PresentationalComponents/ImageBuildStatus/ImageBuildStatus.scss +++ b/src/PresentationalComponents/ImageBuildStatus/ImageBuildStatus.scss @@ -3,4 +3,4 @@ } .success { color: var(--pf-global--success-color--100); -} \ No newline at end of file +} diff --git a/src/test/SmartComponents/ImagesTable/ImagesTable.test.js b/src/test/SmartComponents/ImagesTable/ImagesTable.test.js new file mode 100644 index 00000000..068d7f18 --- /dev/null +++ b/src/test/SmartComponents/ImagesTable/ImagesTable.test.js @@ -0,0 +1,57 @@ +import React from 'react'; +import { screen, render } from '@testing-library/react'; +import { renderWithReduxRouter } from '../../testUtils'; +import ImagesTable from '../../../SmartComponents/ImagesTable/ImagesTable'; +import ImageBuildStatus from '../../../PresentationalComponents/ImageBuildStatus/ImageBuildStatus'; +import '@testing-library/jest-dom'; + +const store = { + composes: { + 'c1cfa347-4c37-49b5-8e73-6aa1d1746cfa': { + status: 'building', + distribution: 'fedora-31', + architecture: 'x86_64', + image_type: 'qcow2' + }, + '61b0effa-c901-4ee5-86b9-2010b47f1b22': { + status: 'uploading', + distribution: 'fedora-31', + architecture: 'x86_64', + image_type: 'qcow2' + }, + '551de6f6-1533-4b46-a69f-7924051f9bc6': { + status: 'success', + distribution: 'fedora-31', + architecture: 'x86_64', + image_type: 'qcow2' + } + } +}; + +describe('Images Table', () => { + beforeEach(() => { + renderWithReduxRouter(, store); + }); + + test('render ImagesTable', () => { + // check action loads + screen.getByTestId('create-image-action'); + + // check table + const table = screen.getByTestId('images-table'); + expect(table.rows).toHaveLength(4); + for (const row of table.rows) { + const col1 = row.cells[0].textContent; + if (col1 === 'Image') // skip header + {continue;} + + const compose = store.composes[col1]; + expect(compose).toBeTruthy(); + + // render the expected and compare the text content + let testElement = document.createElement('testElement'); + render(, { container: testElement }); + expect(row.cells[3]).toHaveTextContent(testElement.textContent); + } + }); +});