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",
184 "kind": ResourceKind.GROUP,
185 "modifiedAt": "2020-09-24T22:52:57.545669000Z",
186 "modifiedByUserUuid": "zzzzz-tpzed-000000000000000",
187 "name": "System group",
188 "ownerUuid": "zzzzz-tpzed-000000000000000",
193 "zzzzz-tpzed-000000000000000",
198 it('shows loading group count when no memberCount', () => {
200 const store = mockStore({resources: {
201 [props.uuid]: fakeGroup,
204 const wrapper = cy.mount(<Provider store={store}>
205 <StyledEngineProvider injectFirst>
206 <ThemeProvider theme={CustomTheme}>
207 <GroupMembersCount {...props} />
209 </StyledEngineProvider>
212 cy.get('[data-testid=three-dots-svg]').should('exist');
215 it('shows group count when memberCount present', () => {
217 const store = mockStore({resources: {
224 cy.mount(<Provider store={store}>
225 <StyledEngineProvider injectFirst>
226 <ThemeProvider theme={CustomTheme}>
227 <GroupMembersCount {...props} />
229 </StyledEngineProvider>
232 cy.get('p').should('have.text', '765');
235 it('shows group count error icon when memberCount is null', () => {
237 const store = mockStore({resources: {
244 cy.mount(<Provider store={store}>
245 <StyledEngineProvider injectFirst>
246 <ThemeProvider theme={CustomTheme}>
247 <GroupMembersCount {...props} />
249 </StyledEngineProvider>
252 cy.get('[data-testid=ErrorRoundedIcon]').should('exist');