1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { GroupMembersCount, ProcessStatus, ResourceFileSize } from './renderers';
7 import { Provider } from 'react-redux';
8 import configureMockStore from 'redux-mock-store'
9 import { ResourceKind } from '../../models/resource';
10 import { ContainerRequestState as CR } from '../../models/container-request';
11 import { ContainerState as C } from '../../models/container';
12 import { ProcessStatus as PS } from '../../store/processes/process';
13 import { ThemeProvider, Theme, StyledEngineProvider } from '@mui/material';
14 import { CustomTheme } from 'common/custom-theme';
16 const middlewares = [];
17 const mockStore = configureMockStore(middlewares);
19 describe('renderers', () => {
22 describe('ProcessStatus', () => {
24 uuid: 'zzzzz-xvhdp-zzzzzzzzzzzzzzz',
28 // Color values are arbitrary, but they should be
29 // representative of the colors used in the UI.
30 green800: 'rgb(0, 255, 0)',
31 red900: 'rgb(255, 0, 0)',
32 orange: 'rgb(240, 173, 78)',
33 grey600: 'rgb(128, 128, 128)',
36 spacing: (value) => value * 8,
39 white: 'rgb(255, 255, 255)',
46 // CR Status ; Priority ; C Status ; Exit Code ; C RuntimeStatus ; Expected label ; Expected bg color ; Expected fg color
47 [CR.COMMITTED, 1, C.RUNNING, null, {}, PS.RUNNING, props.theme.palette.common.white, props.theme.customs.colors.green800],
48 [CR.COMMITTED, 1, C.RUNNING, null, { error: 'whoops' }, PS.FAILING, props.theme.palette.common.white, props.theme.customs.colors.red900],
49 [CR.COMMITTED, 1, C.RUNNING, null, { warning: 'watch out!' }, PS.WARNING, props.theme.palette.common.white, props.theme.customs.colors.green800],
50 [CR.FINAL, 1, C.CANCELLED, null, {}, PS.CANCELLED, props.theme.customs.colors.red900, props.theme.palette.common.white],
51 [CR.FINAL, 1, C.COMPLETE, 137, {}, PS.FAILED, props.theme.customs.colors.red900, props.theme.palette.common.white],
52 [CR.FINAL, 1, C.COMPLETE, 0, {}, PS.COMPLETED, props.theme.customs.colors.green800, props.theme.palette.common.white],
53 [CR.COMMITTED, 0, C.LOCKED, null, {}, PS.ONHOLD, props.theme.customs.colors.grey600, props.theme.palette.common.white],
54 [CR.COMMITTED, 0, C.QUEUED, null, {}, PS.ONHOLD, props.theme.customs.colors.grey600, props.theme.palette.common.white],
55 [CR.COMMITTED, 1, C.LOCKED, null, {}, PS.QUEUED, props.theme.palette.common.white, props.theme.customs.colors.grey600],
56 [CR.COMMITTED, 1, C.QUEUED, null, {}, PS.QUEUED, props.theme.palette.common.white, props.theme.customs.colors.grey600],
57 ].forEach(([crState, crPrio, cState, exitCode, rs, eLabel, eColor, tColor]) => {
58 it(`should render the state label '${eLabel}' and color '${eColor}' for CR state=${crState}, priority=${crPrio}, C state=${cState}, exitCode=${exitCode} and RuntimeStatus=${JSON.stringify(rs)}`, () => {
59 const containerUuid = 'zzzzz-dz642-zzzzzzzzzzzzzzz';
60 const store = mockStore({
63 kind: ResourceKind.CONTAINER_REQUEST,
65 containerUuid: containerUuid,
69 kind: ResourceKind.CONTAINER,
78 <Provider store={store}>
79 <ThemeProvider theme={CustomTheme}>
80 <ProcessStatus {...props} />
84 cy.get('span').should('have.text', eLabel);
85 cy.get('span').should('have.css', 'color', tColor);
86 cy.get('[data-cy=process-status-chip]').should('have.css', 'background-color', eColor);
91 describe('ResourceFileSize', () => {
98 it('should render collection fileSizeTotal', () => {
100 const store = mockStore({
103 kind: ResourceKind.COLLECTION,
110 cy.mount(<Provider store={store}>
111 <ResourceFileSize {...props}></ResourceFileSize>
115 cy.get('p').should('have.text', '100 B');
118 it('should render 0 B as file size', () => {
120 const store = mockStore({ resources: {} });
123 cy.mount(<Provider store={store}>
124 <ResourceFileSize {...props}></ResourceFileSize>
128 cy.get('p').should('have.text', '0 B');
131 it('should render empty string for non collection resource', () => {
133 const store1 = mockStore({
136 kind: ResourceKind.PROJECT,
141 const store2 = mockStore({
144 kind: ResourceKind.PROCESS,
151 cy.mount(<Provider store={store1}>
152 <ResourceFileSize {...props}></ResourceFileSize>
156 cy.get('p').should('have.text', '-');
159 cy.mount(<Provider store={store2}>
160 <ResourceFileSize {...props}></ResourceFileSize>
164 cy.get('p').should('have.text', '-');
168 describe('GroupMembersCount', () => {
172 uuid: 'zzzzz-j7d0g-000000000000000',
177 "createdAt": "2020-09-24T22:52:57.546521000Z",
179 "description": "Test Group",
180 "etag": "0000000000000000000000000",
181 "frozenByUuid": null,
182 "groupClass": "role",
183 "href": `/groups/${props.uuid}`,
185 "kind": ResourceKind.GROUP,
186 "modifiedAt": "2020-09-24T22:52:57.545669000Z",
187 "modifiedByUserUuid": "zzzzz-tpzed-000000000000000",
188 "name": "System group",
189 "ownerUuid": "zzzzz-tpzed-000000000000000",
194 "zzzzz-tpzed-000000000000000",
199 it('shows loading group count when no memberCount', () => {
201 const store = mockStore({resources: {
202 [props.uuid]: fakeGroup,
205 const wrapper = cy.mount(<Provider store={store}>
206 <StyledEngineProvider injectFirst>
207 <ThemeProvider theme={CustomTheme}>
208 <GroupMembersCount {...props} />
210 </StyledEngineProvider>
213 cy.get('[data-testid=three-dots-svg]').should('exist');
216 it('shows group count when memberCount present', () => {
218 const store = mockStore({resources: {
225 cy.mount(<Provider store={store}>
226 <StyledEngineProvider injectFirst>
227 <ThemeProvider theme={CustomTheme}>
228 <GroupMembersCount {...props} />
230 </StyledEngineProvider>
233 cy.get('p').should('have.text', '765');
236 it('shows group count error icon when memberCount is null', () => {
238 const store = mockStore({resources: {
245 cy.mount(<Provider store={store}>
246 <StyledEngineProvider injectFirst>
247 <ThemeProvider theme={CustomTheme}>
248 <GroupMembersCount {...props} />
250 </StyledEngineProvider>
253 cy.get('[data-testid=ErrorRoundedIcon]').should('exist');