1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import React from 'react';
6 import { mount, configure } from 'enzyme';
7 import { GroupMembersCount, ProcessStatus, ResourceFileSize } from './renderers';
8 import Adapter from "enzyme-adapter-react-16";
9 import { Provider } from 'react-redux';
10 import configureMockStore from 'redux-mock-store'
11 import { ResourceKind } from '../../models/resource';
12 import { ContainerRequestState as CR } from '../../models/container-request';
13 import { ContainerState as C } from '../../models/container';
14 import { ProcessStatus as PS } from '../../store/processes/process';
15 import { MuiThemeProvider } from '@material-ui/core';
16 import { CustomTheme } from 'common/custom-theme';
17 import { InlinePulser} from 'components/loading/inline-pulser';
18 import { ErrorIcon } from "components/icon/icon";
20 const middlewares = [];
21 const mockStore = configureMockStore(middlewares);
23 configure({ adapter: new Adapter() });
25 describe('renderers', () => {
26 let props: any = null;
28 describe('ProcessStatus', () => {
30 uuid: 'zzzzz-xvhdp-zzzzzzzzzzzzzzz',
34 // Color values are arbitrary, but they should be
35 // representative of the colors used in the UI.
36 green800: 'rgb(0, 255, 0)',
37 red900: 'rgb(255, 0, 0)',
38 orange: 'rgb(240, 173, 78)',
39 grey600: 'rgb(128, 128, 128)',
47 white: 'rgb(255, 255, 255)',
54 // CR Status ; Priority ; C Status ; Exit Code ; C RuntimeStatus ; Expected label ; Expected bg color ; Expected fg color
55 [CR.COMMITTED, 1, C.RUNNING, null, {}, PS.RUNNING, props.theme.palette.common.white, props.theme.customs.colors.green800],
56 [CR.COMMITTED, 1, C.RUNNING, null, { error: 'whoops' }, PS.FAILING, props.theme.palette.common.white, props.theme.customs.colors.red900],
57 [CR.COMMITTED, 1, C.RUNNING, null, { warning: 'watch out!' }, PS.WARNING, props.theme.palette.common.white, props.theme.customs.colors.green800],
58 [CR.FINAL, 1, C.CANCELLED, null, {}, PS.CANCELLED, props.theme.customs.colors.red900, props.theme.palette.common.white],
59 [CR.FINAL, 1, C.COMPLETE, 137, {}, PS.FAILED, props.theme.customs.colors.red900, props.theme.palette.common.white],
60 [CR.FINAL, 1, C.COMPLETE, 0, {}, PS.COMPLETED, props.theme.customs.colors.green800, props.theme.palette.common.white],
61 [CR.COMMITTED, 0, C.LOCKED, null, {}, PS.ONHOLD, props.theme.customs.colors.grey600, props.theme.palette.common.white],
62 [CR.COMMITTED, 0, C.QUEUED, null, {}, PS.ONHOLD, props.theme.customs.colors.grey600, props.theme.palette.common.white],
63 [CR.COMMITTED, 1, C.LOCKED, null, {}, PS.QUEUED, props.theme.palette.common.white, props.theme.customs.colors.grey600],
64 [CR.COMMITTED, 1, C.QUEUED, null, {}, PS.QUEUED, props.theme.palette.common.white, props.theme.customs.colors.grey600],
65 ].forEach(([crState, crPrio, cState, exitCode, rs, eLabel, eColor, tColor]) => {
66 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)}`, () => {
67 const containerUuid = 'zzzzz-dz642-zzzzzzzzzzzzzzz';
68 const store = mockStore({
71 kind: ResourceKind.CONTAINER_REQUEST,
73 containerUuid: containerUuid,
77 kind: ResourceKind.CONTAINER,
85 const wrapper = mount(<Provider store={store}>
86 <ProcessStatus {...props} />
89 expect(wrapper.text()).toEqual(eLabel);
90 expect(getComputedStyle(wrapper.getDOMNode())
91 .getPropertyValue('color')).toEqual(tColor);
92 expect(getComputedStyle(wrapper.getDOMNode())
93 .getPropertyValue('background-color')).toEqual(eColor);
98 describe('ResourceFileSize', () => {
105 it('should render collection fileSizeTotal', () => {
107 const store = mockStore({
110 kind: ResourceKind.COLLECTION,
117 const wrapper = mount(<Provider store={store}>
118 <ResourceFileSize {...props}></ResourceFileSize>
122 expect(wrapper.text()).toContain('100 B');
125 it('should render 0 B as file size', () => {
127 const store = mockStore({ resources: {} });
130 const wrapper = mount(<Provider store={store}>
131 <ResourceFileSize {...props}></ResourceFileSize>
135 expect(wrapper.text()).toContain('0 B');
138 it('should render empty string for non collection resource', () => {
140 const store1 = mockStore({
143 kind: ResourceKind.PROJECT,
147 const store2 = mockStore({
150 kind: ResourceKind.PROJECT,
156 const wrapper1 = mount(<Provider store={store1}>
157 <ResourceFileSize {...props}></ResourceFileSize>
159 const wrapper2 = mount(<Provider store={store2}>
160 <ResourceFileSize {...props}></ResourceFileSize>
164 expect(wrapper1.text()).toContain('');
165 expect(wrapper2.text()).toContain('');
169 describe('GroupMembersCount', () => {
173 uuid: 'zzzzz-j7d0g-000000000000000',
178 "createdAt": "2020-09-24T22:52:57.546521000Z",
180 "description": "Test Group",
181 "etag": "0000000000000000000000000",
182 "frozenByUuid": null,
183 "groupClass": "role",
184 "href": `/groups/${props.uuid}`,
186 "kind": ResourceKind.GROUP,
187 "modifiedAt": "2020-09-24T22:52:57.545669000Z",
188 "modifiedByUserUuid": "zzzzz-tpzed-000000000000000",
189 "name": "System group",
190 "ownerUuid": "zzzzz-tpzed-000000000000000",
195 "zzzzz-tpzed-000000000000000",
200 it('shows loading group count when no memberCount', () => {
202 const store = mockStore({resources: {
203 [props.uuid]: fakeGroup,
206 const wrapper = mount(<Provider store={store}>
207 <MuiThemeProvider theme={CustomTheme}>
208 <GroupMembersCount {...props} />
212 expect(wrapper.find(InlinePulser)).toHaveLength(1);
215 it('shows group count when memberCount present', () => {
217 const store = mockStore({resources: {
224 const wrapper = mount(<Provider store={store}>
225 <MuiThemeProvider theme={CustomTheme}>
226 <GroupMembersCount {...props} />
230 expect(wrapper.text()).toBe("765");
233 it('shows group count error icon when memberCount is null', () => {
235 const store = mockStore({resources: {
242 const wrapper = mount(<Provider store={store}>
243 <MuiThemeProvider theme={CustomTheme}>
244 <GroupMembersCount {...props} />
248 expect(wrapper.find(ErrorIcon)).toHaveLength(1);