Skip to content

Commit

Permalink
patch: Update API usage for multi-arch support
Browse files Browse the repository at this point in the history
Signed-off-by: Raul Kele <[email protected]>
  • Loading branch information
raulkele committed Mar 6, 2023
1 parent 1cf9b3c commit 4db0c2e
Show file tree
Hide file tree
Showing 12 changed files with 196 additions and 172 deletions.
4 changes: 4 additions & 0 deletions src/__tests__/TagPage/DependsOn.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const mockDependenciesList = {
{
RepoName: 'project-stacker/c3/static-ubuntu-amd64',
Tag: 'tag1',
Manifests: [],
Vulnerabilities: {
MaxSeverity: 'HIGH',
Count: 5
Expand All @@ -20,6 +21,7 @@ const mockDependenciesList = {
{
RepoName: 'tag2',
Tag: 'tag2',
Manifests: [],
Vulnerabilities: {
MaxSeverity: 'CRITICAL',
Count: 2
Expand All @@ -28,6 +30,7 @@ const mockDependenciesList = {
{
RepoName: 'tag3',
Tag: 'tag3',
Manifests: [],
Vulnerabilities: {
MaxSeverity: 'LOW',
Count: 7
Expand All @@ -36,6 +39,7 @@ const mockDependenciesList = {
{
RepoName: 'tag4',
Tag: 'tag4',
Manifests: [],
Vulnerabilities: {
MaxSeverity: 'HIGH',
Count: 5
Expand Down
22 changes: 4 additions & 18 deletions src/__tests__/TagPage/HistoryLayers.test.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { render, screen, waitFor, fireEvent } from '@testing-library/react';
import { api } from 'api';
import HistoryLayers from 'components/Tag/Tabs/HistoryLayers';
import React from 'react';

const mockLayersList = [
{
Layer: { Size: '2806054', Digest: '213ec9aee27d8be045c6a92b7eac22c9a64b44558193775a1a7f626352392b49', Score: null },
Layer: { Size: '2806054', Digest: '213ec9aee27d8be045c6a92b7eac22c9a64b44558193775a1a7f626352392b49' },
HistoryDescription: {
Created: '2022-08-09T17:19:53.274069586Z',
CreatedBy: '/bin/sh -c #(nop) ADD file:2a949686d9886ac7c10582a6c29116fd29d3077d02755e87e111870d63607725 in / ',
Expand Down Expand Up @@ -33,33 +32,20 @@ afterEach(() => {

describe('Layers page', () => {
it('renders the layers if there are any', async () => {
jest.spyOn(api, 'get').mockResolvedValue({ status: 200, data: { data: { Image: { History: mockLayersList } } } });
render(<HistoryLayers name="alpine:latest" />);
render(<HistoryLayers name="alpine:latest" history={mockLayersList} />);
expect(await screen.findAllByTestId('layer-card-container')).toHaveLength(1);
});

it('renders no layers if there are not any', async () => {
jest.spyOn(api, 'get').mockResolvedValue({
status: 200,
data: { data: { History: { Tag: '', mockLayersList: [] } } }
});
render(<HistoryLayers name="alpine:latest" />);
render(<HistoryLayers name="alpine:latest" history={[]} />);
await waitFor(() => expect(screen.getAllByText(/No Layer data available/i)).toHaveLength(1));
});

it('opens dropdown and renders layer command and digest', async () => {
jest.spyOn(api, 'get').mockResolvedValue({ status: 200, data: { data: { Image: { History: mockLayersList } } } });
render(<HistoryLayers name="alpine:latest" />);
render(<HistoryLayers name="alpine:latest" history={mockLayersList} />);
expect(screen.queryAllByText(/DIGEST/i)).toHaveLength(0);
const openDetails = await screen.findAllByText(/details/i);
fireEvent.click(openDetails[0]);
expect(await screen.findAllByText(/DIGEST/i)).toHaveLength(1);
});

it("should log an error when data can't be fetched", async () => {
jest.spyOn(api, 'get').mockRejectedValue({ status: 500, data: {} });
const error = jest.spyOn(console, 'error').mockImplementation(() => {});
render(<HistoryLayers name="alpine:latest" />);
await waitFor(() => expect(error).toBeCalledTimes(1));
});
});
4 changes: 4 additions & 0 deletions src/__tests__/TagPage/IsDependentOn.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ const mockDependentsList = {
{
RepoName: 'project-stacker/c3/static-ubuntu-amd64',
Tag: 'tag1',
Manifests: [],
Vulnerabilities: {
MaxSeverity: 'HIGH',
Count: 5
Expand All @@ -20,6 +21,7 @@ const mockDependentsList = {
{
RepoName: 'tag2',
Tag: 'tag2',
Manifests: [],
Vulnerabilities: {
MaxSeverity: 'CRITICAL',
Count: 2
Expand All @@ -28,6 +30,7 @@ const mockDependentsList = {
{
RepoName: 'tag3',
Tag: 'tag3',
Manifests: [],
Vulnerabilities: {
MaxSeverity: 'LOW',
Count: 5
Expand All @@ -36,6 +39,7 @@ const mockDependentsList = {
{
RepoName: 'tag4',
Tag: 'tag4',
Manifests: [],
Vulnerabilities: {
MaxSeverity: 'HIGH',
Count: 3
Expand Down
Loading

0 comments on commit 4db0c2e

Please sign in to comment.