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 { 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';
16 const middlewares = [];
17 const mockStore = configureMockStore(middlewares);
19 configure({ adapter: new Adapter() });
21 describe('renderers', () => {
24 describe('ProcessStatus', () => {
26 uuid: 'zzzzz-xvhdp-zzzzzzzzzzzzzzz',
30 // Color values are arbitrary, but they should be
31 // representative of the colors used in the UI.
32 blue500: 'rgb(0, 0, 255)',
33 green700: 'rgb(0, 255, 0)',
34 yellow700: 'rgb(255, 255, 0)',
35 red900: 'rgb(255, 0, 0)',
36 orange: 'rgb(240, 173, 78)',
37 grey500: 'rgb(128, 128, 128)',
45 white: 'rgb(255, 255, 255)',
52 // CR Status ; Priority ; C Status ; Exit Code ; C RuntimeStatus ; Expected label ; Expected Color
53 [CR.COMMITTED, 1, C.RUNNING, null, {}, PS.RUNNING, props.theme.customs.colors.blue500],
54 [CR.COMMITTED, 1, C.RUNNING, null, {error: 'whoops'}, PS.FAILING, props.theme.customs.colors.orange],
55 [CR.COMMITTED, 1, C.RUNNING, null, {warning: 'watch out!'}, PS.WARNING, props.theme.customs.colors.yellow700],
56 [CR.FINAL, 1, C.CANCELLED, null, {}, PS.CANCELLED, props.theme.customs.colors.red900],
57 [CR.FINAL, 1, C.COMPLETE, 137, {}, PS.FAILED, props.theme.customs.colors.red900],
58 [CR.FINAL, 1, C.COMPLETE, 0, {}, PS.COMPLETED, props.theme.customs.colors.green700],
59 [CR.COMMITTED, 0, C.LOCKED, null, {}, PS.ONHOLD, props.theme.customs.colors.grey500],
60 [CR.COMMITTED, 0, C.QUEUED, null, {}, PS.ONHOLD, props.theme.customs.colors.grey500],
61 [CR.COMMITTED, 1, C.LOCKED, null, {}, PS.QUEUED, props.theme.customs.colors.grey500],
62 [CR.COMMITTED, 1, C.QUEUED, null, {}, PS.QUEUED, props.theme.customs.colors.grey500],
63 ].forEach(([crState, crPrio, cState, exitCode, rs, eLabel, eColor]) => {
64 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)}`, () => {
65 const containerUuid = 'zzzzz-dz642-zzzzzzzzzzzzzzz';
66 const store = mockStore({ resources: {
68 kind: ResourceKind.CONTAINER_REQUEST,
70 containerUuid: containerUuid,
74 kind: ResourceKind.CONTAINER,
81 const wrapper = mount(<Provider store={store}>
82 <ProcessStatus {...props} />
85 expect(wrapper.text()).toEqual(eLabel);
86 expect(getComputedStyle(wrapper.getDOMNode())
87 .getPropertyValue('color')).toEqual(props.theme.palette.common.white);
88 expect(getComputedStyle(wrapper.getDOMNode())
89 .getPropertyValue('background-color')).toEqual(eColor);
94 describe('ResourceFileSize', () => {
101 it('should render collection fileSizeTotal', () => {
103 const store = mockStore({ resources: {
105 kind: ResourceKind.COLLECTION,
111 const wrapper = mount(<Provider store={store}>
112 <ResourceFileSize {...props}></ResourceFileSize>
116 expect(wrapper.text()).toContain('100 B');
119 it('should render 0 B as file size', () => {
121 const store = mockStore({ resources: {} });
124 const wrapper = mount(<Provider store={store}>
125 <ResourceFileSize {...props}></ResourceFileSize>
129 expect(wrapper.text()).toContain('0 B');
132 it('should render empty string for non collection resource', () => {
134 const store1 = mockStore({ resources: {
136 kind: ResourceKind.PROJECT,
139 const store2 = mockStore({ resources: {
141 kind: ResourceKind.PROJECT,
146 const wrapper1 = mount(<Provider store={store1}>
147 <ResourceFileSize {...props}></ResourceFileSize>
149 const wrapper2 = mount(<Provider store={store2}>
150 <ResourceFileSize {...props}></ResourceFileSize>
154 expect(wrapper1.text()).toContain('');
155 expect(wrapper2.text()).toContain('');