diff --git a/src/__mocks__/mockedBootCImageData.json b/src/__mocks__/mockedBootCImageData.json new file mode 100644 index 000000000..b51b95ee2 --- /dev/null +++ b/src/__mocks__/mockedBootCImageData.json @@ -0,0 +1,39 @@ +[ + { + "image": "India Pale Ale", + "hashCommitCount": 2, + "systemCount": 3, + "hashes": [ + { + "image_digest": "Hazy", + "hashSystemCount": 2 + }, + { + "image_digest": "West Coast", + "hashSystemCount": 1 + } + ] + }, + { + "image": "Belgian", + "hashCommitCount": 1, + "systemCount": 1, + "hashes": [ + { + "image_digest": "Dubbel", + "hashSystemCount": 1 + } + ] + }, + { + "image": "Stout", + "hashCommitCount": 1, + "systemCount": 1, + "hashes": [ + { + "image_digest": "Bourbon Barrell Aged", + "hashSystemCount": 1 + } + ] + } +] \ No newline at end of file diff --git a/src/__mocks__/mockedBootCStatusData.json b/src/__mocks__/mockedBootCStatusData.json new file mode 100644 index 000000000..f7374f45c --- /dev/null +++ b/src/__mocks__/mockedBootCStatusData.json @@ -0,0 +1,288 @@ +{ + "total": 5, + "count": 5, + "page": 1, + "per_page": 50, + "results": [ + { + "id": "6de30d78-f052-41d4-b123-125017443a98", + "system_profile": { + "arch": "x86_64", + "cpu_flags": [ "fpu" ], + "yum_repos": [ + { + "name": "Extra Packages for Enterprise Linux 7 - Testing - $basearch", + "enabled": false, + "gpgcheck": true + } + ], + "os_release": "7.4", + "bios_vendor": "SeaBIOS", + "bios_version": "1.10.2-2.fc27", + "kernel_modules": [ "veth" ], + "last_boot_time": "2018-03-14T17:06:10", + "number_of_cpus": 1, + "cores_per_socket": 1, + "enabled_services": [ "auditd" ], + "bios_release_date": "04\/01\/2014", + "number_of_sockets": 1, + "os_kernel_version": "3.10.0", + "running_processes": [ "qmgr" ], + "satellite_managed": false, + "installed_packages": [ "0:GeoIP-1.5.0-11.el7" ], + "installed_services": [ "arp-ethers" ], + "network_interfaces": [ + { + "mtu": 65536, + "name": "lo", + "type": "loopback", + "state": "UNKNOWN", + "mac_address": "00:00:00:00:00:00", + "ipv4_addresses": [ + "127.0.0.1" + ], + "ipv6_addresses": [ + "::1" + ] + } + ], + "infrastructure_type": "virtual", + "system_memory_bytes": 512073728, + "infrastructure_vendor": "qemu", + "system_purpose": { + "usage": "Production" + }, + "bootc_status": { + "booted": { + "image": "India Pale Ale", + "image_digest": "Hazy" + } + } + } + }, + { + "id": "08a06e04-afbb-4e3c-b923-91aa1c17acc1", + "system_profile": { + "arch": "x86_64", + "cpu_flags": [ "fpu" ], + "yum_repos": [ + { + "name": "Extra Packages for Enterprise Linux 7 - Testing - $basearch", + "enabled": false, + "gpgcheck": true + } + ], + "os_release": "8.4", + "bios_vendor": "SeaBIOS", + "bios_version": "1.10.2-2.fc27", + "kernel_modules": [ "veth" ], + "last_boot_time": "2018-03-14T17:06:10", + "number_of_cpus": 1, + "cores_per_socket": 1, + "enabled_services": [ "auditd" ], + "bios_release_date": "04\/01\/2014", + "number_of_sockets": 1, + "os_kernel_version": "3.10.0", + "running_processes": [ "qmgr" ], + "satellite_managed": false, + "installed_packages": [ "0:GeoIP-1.5.0-11.el7" ], + "installed_services": [ "arp-ethers" ], + "network_interfaces": [ + { + "mtu": 65536, + "name": "lo", + "type": "loopback", + "state": "UNKNOWN", + "mac_address": "00:00:00:00:00:00", + "ipv4_addresses": [ + "127.0.0.1" + ], + "ipv6_addresses": [ + "::1" + ] + } + ], + "infrastructure_type": "virtual", + "system_memory_bytes": 512073728, + "infrastructure_vendor": "qemu", + "system_purpose": { + "usage": "Production" + }, + "bootc_status": { + "booted": { + "image": "India Pale Ale", + "image_digest": "Hazy" + } + } + } + }, + { + "id": "4ef68d04-79fa-42ea-a0fe-b40ee257ff0e", + "system_profile": { + "arch": "x86_64", + "cpu_flags": [ "fpu" ], + "yum_repos": [ + { + "name": "Extra Packages for Enterprise Linux 7 - Testing - $basearch", + "enabled": false, + "gpgcheck": true + } + ], + "os_release": "8.5", + "bios_vendor": "SeaBIOS", + "bios_version": "1.10.2-2.fc27", + "kernel_modules": [ "veth" ], + "last_boot_time": "2018-03-14T17:06:10", + "number_of_cpus": 1, + "cores_per_socket": 1, + "enabled_services": [ "auditd" ], + "bios_release_date": "04\/01\/2014", + "number_of_sockets": 1, + "os_kernel_version": "3.10.0", + "running_processes": [ "qmgr" ], + "satellite_managed": false, + "installed_packages": [ "0:GeoIP-1.5.0-11.el7" ], + "installed_services": [ "arp-ethers" ], + "network_interfaces": [ + { + "mtu": 65536, + "name": "lo", + "type": "loopback", + "state": "UNKNOWN", + "mac_address": "00:00:00:00:00:00", + "ipv4_addresses": [ + "127.0.0.1" + ], + "ipv6_addresses": [ + "::1" + ] + } + ], + "infrastructure_type": "virtual", + "system_memory_bytes": 512073728, + "infrastructure_vendor": "qemu", + "system_purpose": { + "usage": "Production" + }, + "bootc_status": { + "booted": { + "image": "India Pale Ale", + "image_digest": "West Coast" + } + } + } + }, + { + "id": "b6197999-06f8-4301-a936-651832aa8b31", + "system_profile": { + "arch": "x86_64", + "cpu_flags": [ "fpu" ], + "yum_repos": [ + { + "name": "Extra Packages for Enterprise Linux 7 - Testing - $basearch", + "enabled": false, + "gpgcheck": true + } + ], + "os_release": "8.5", + "bios_vendor": "SeaBIOS", + "bios_version": "1.10.2-2.fc27", + "kernel_modules": [ "veth" ], + "last_boot_time": "2018-03-14T17:06:10", + "number_of_cpus": 1, + "cores_per_socket": 1, + "enabled_services": [ "auditd" ], + "bios_release_date": "04\/01\/2014", + "number_of_sockets": 1, + "os_kernel_version": "3.10.0", + "running_processes": [ "qmgr" ], + "satellite_managed": false, + "installed_packages": [ "0:GeoIP-1.5.0-11.el7" ], + "installed_services": [ "arp-ethers" ], + "network_interfaces": [ + { + "mtu": 65536, + "name": "lo", + "type": "loopback", + "state": "UNKNOWN", + "mac_address": "00:00:00:00:00:00", + "ipv4_addresses": [ + "127.0.0.1" + ], + "ipv6_addresses": [ + "::1" + ] + } + ], + "infrastructure_type": "virtual", + "system_memory_bytes": 512073728, + "infrastructure_vendor": "qemu", + "system_purpose": { + "usage": "Production" + }, + "bootc_status": { + "booted": { + "image": "Belgian", + "image_digest": "Dubbel" + } + } + } + }, + { + "id": "8499b198-5352-4eda-8650-ca09e002fdc1", + "system_profile": { + "arch": "x86_64", + "cpu_flags": [ "fpu" ], + "yum_repos": [ + { + "name": "Extra Packages for Enterprise Linux 7 - Testing - $basearch", + "enabled": false, + "gpgcheck": true + } + ], + "os_release": "8.2", + "bios_vendor": "SeaBIOS", + "bios_version": "1.10.2-2.fc27", + "kernel_modules": [ "veth" ], + "last_boot_time": "2018-03-14T17:06:10", + "number_of_cpus": 1, + "cores_per_socket": 1, + "enabled_services": [ "auditd" ], + "bios_release_date": "04\/01\/2014", + "number_of_sockets": 1, + "os_kernel_version": "3.10.0", + "running_processes": [ "qmgr" ], + "satellite_managed": false, + "installed_packages": [ "0:GeoIP-1.5.0-11.el7" ], + "installed_services": [ "arp-ethers" ], + "network_interfaces": [ + { + "mtu": 65536, + "name": "lo", + "type": "loopback", + "state": "UNKNOWN", + "mac_address": "00:00:00:00:00:00", + "ipv4_addresses": [ + "127.0.0.1" + ], + "ipv6_addresses": [ + "::1" + ] + } + ], + "infrastructure_type": "virtual", + "system_memory_bytes": 512073728, + "infrastructure_vendor": "qemu", + "system_purpose": { + "usage": "Production" + }, + "bootc_status": { + "booted": { + "image": "Stout", + "image_digest": "Bourbon Barrell Aged" + } + } + } + } + ] +} diff --git a/src/routes/InventoryComponents/BifrostPage.test.js b/src/routes/InventoryComponents/BifrostPage.test.js new file mode 100644 index 000000000..fe24eb4c2 --- /dev/null +++ b/src/routes/InventoryComponents/BifrostPage.test.js @@ -0,0 +1,35 @@ +import React from 'react'; +import { render, waitFor } from '@testing-library/react'; +import '@testing-library/jest-dom'; +import axios from 'axios'; +import BifrostPage from './BifrostPage'; +import mockedBootCStatusData from '../../__mocks__/mockedBootCStatusData.json'; +import { + INVENTORY_TOTAL_FETCH_URL_SERVER, + INVENTORY_FETCH_BOOTC, + INVENTORY_FETCH_NON_BOOTC, + INVENTORY_FILTER_NO_HOST_TYPE, +} from '../../Utilities/constants'; + +jest.mock('axios'); + +describe('BifrostPage', () => { + beforeEach(() => { + axios.get.mockResolvedValue({ + data: mockedBootCStatusData, + }); + }); + + test('should fetch bootc_status', async () => { + render(); + await waitFor(() => + expect(axios.get).toHaveBeenCalledWith( + `${INVENTORY_TOTAL_FETCH_URL_SERVER}${INVENTORY_FETCH_BOOTC}&fields[system_profile]=bootc_status` + ) + ); + + expect(axios.get).toHaveBeenCalledWith( + `${INVENTORY_TOTAL_FETCH_URL_SERVER}${INVENTORY_FETCH_NON_BOOTC}&${INVENTORY_FILTER_NO_HOST_TYPE}&per_page=1` + ); + }); +}); diff --git a/src/routes/InventoryComponents/BifrostTable.test.js b/src/routes/InventoryComponents/BifrostTable.test.js new file mode 100644 index 000000000..71b84bddb --- /dev/null +++ b/src/routes/InventoryComponents/BifrostTable.test.js @@ -0,0 +1,77 @@ +import React from 'react'; +import { render, screen, within } from '@testing-library/react'; +import userEvent from '@testing-library/user-event'; +import '@testing-library/jest-dom'; +import BifrostTable from './BifrostTable'; +import mockedBootCImageData from '../../__mocks__/mockedBootCImageData.json'; + +describe('BifrostTable', () => { + test('should render Skeleton table', () => { + render(); + + expect( + screen.getByRole('grid', { + name: /loading/i, + }) + ).toBeVisible(); + }); + + test('should render table', () => { + render(); + + expect( + screen.getByRole('cell', { + name: /india pale ale/i, + }) + ).toBeVisible(); + + expect( + screen.getByRole('cell', { + name: /belgian/i, + }) + ).toBeVisible(); + + expect( + screen.getByRole('cell', { + name: /stout/i, + }) + ).toBeVisible(); + }); + + test('should open and close expanded rows', async () => { + render(); + expect( + screen.queryByRole('cell', { + name: /hash commit table/i, + }) + ).not.toBeInTheDocument(); + + const row = screen.getByRole('row', { + name: /details india pale ale 2 3/i, + }); + + await userEvent.click( + within(row).getByRole('button', { + name: /details/i, + }) + ); + + expect( + screen.getByRole('cell', { + name: /hash commit table/i, + }) + ).toBeVisible(); + + await userEvent.click( + within(row).getByRole('button', { + name: /details/i, + }) + ); + + expect( + screen.queryByRole('cell', { + name: /hash commit table/i, + }) + ).not.toBeInTheDocument(); + }); +}); diff --git a/src/routes/InventoryComponents/BifrostTableRows.test.js b/src/routes/InventoryComponents/BifrostTableRows.test.js new file mode 100644 index 000000000..302e439e8 --- /dev/null +++ b/src/routes/InventoryComponents/BifrostTableRows.test.js @@ -0,0 +1,68 @@ +import React from 'react'; +import { render, screen } from '@testing-library/react'; +import '@testing-library/jest-dom'; +import BifrostTableRows from './BifrostTableRows'; +import mockedBootCImageData from '../../__mocks__/mockedBootCImageData.json'; +import { imageTableColumns, hashTableColumns } from './BifrostTableColumns'; + +describe('BifrostTableRows', () => { + test('should render image name column', () => { + render( + + ); + + expect(screen.getByText(/india pale ale/i)).toBeVisible(); + expect(screen.queryByText(/2/i)).not.toBeInTheDocument(); + }); + + test('should render hash commits column', () => { + render( + + ); + + expect(screen.getByText(/2/i)).toBeVisible(); + expect(screen.queryByText(/india pale ale/i)).not.toBeInTheDocument(); + }); + + test('should render systems column', () => { + render( + + ); + + expect(screen.getByText(/3/i)).toBeVisible(); + expect(screen.queryByText(/india pale ale/i)).not.toBeInTheDocument(); + }); + + test('should render image digest column', () => { + render( + + ); + + expect(screen.getByText(/hazy/i)).toBeVisible(); + expect(screen.queryByText(/2/i)).not.toBeInTheDocument(); + }); + + test('should render hash system count column', () => { + render( + + ); + + expect(screen.getByText(/2/i)).toBeVisible(); + expect(screen.queryByText(/hazy/i)).not.toBeInTheDocument(); + }); +}); diff --git a/src/routes/InventoryComponents/NestedHashTable.js b/src/routes/InventoryComponents/NestedHashTable.js index d2bef75bd..97ae28101 100644 --- a/src/routes/InventoryComponents/NestedHashTable.js +++ b/src/routes/InventoryComponents/NestedHashTable.js @@ -6,7 +6,7 @@ import BifrostTableRows from './BifrostTableRows'; const NestedHashTable = ({ hashes }) => { return ( - +
{hashTableColumns.map((col) => { diff --git a/src/routes/InventoryComponents/NestedHashTable.test.js b/src/routes/InventoryComponents/NestedHashTable.test.js new file mode 100644 index 000000000..9275c7e78 --- /dev/null +++ b/src/routes/InventoryComponents/NestedHashTable.test.js @@ -0,0 +1,23 @@ +import React from 'react'; +import { render, screen } from '@testing-library/react'; +import '@testing-library/jest-dom'; +import NestedHashTable from './NestedHashTable'; +import mockedBootCImageData from '../../__mocks__/mockedBootCImageData.json'; + +describe('NestedHashTable', () => { + test('Nested hash table', () => { + render(); + + expect( + screen.getByRole('cell', { + name: /hazy/i, + }) + ).toBeVisible(); + + expect( + screen.getByRole('cell', { + name: /west coast/i, + }) + ).toBeVisible(); + }); +});