X-Git-Url: https://git.arvados.org/arvados-workbench2.git/blobdiff_plain/3c7e3cdc547ad5468421e1c049daa94b0d4b8bc0..refs/heads/18881-process-runtime-status:/src/views-components/data-explorer/renderers.test.tsx

diff --git a/src/views-components/data-explorer/renderers.test.tsx b/src/views-components/data-explorer/renderers.test.tsx
index f0efdf74..229d9909 100644
--- a/src/views-components/data-explorer/renderers.test.tsx
+++ b/src/views-components/data-explorer/renderers.test.tsx
@@ -4,11 +4,14 @@
 
 import React from 'react';
 import { mount, configure } from 'enzyme';
-import { ResourceFileSize } from './renderers';
+import { ProcessStatus, ResourceFileSize } from './renderers';
 import Adapter from "enzyme-adapter-react-16";
 import { Provider } from 'react-redux';
 import configureMockStore from 'redux-mock-store'
 import { ResourceKind } from '../../models/resource';
+import { ContainerRequestState as CR } from '../../models/container-request';
+import { ContainerState as C } from '../../models/container';
+import { ProcessStatus as PS } from '../../store/processes/process';
 
 const middlewares = [];
 const mockStore = configureMockStore(middlewares);
@@ -18,6 +21,75 @@ configure({ adapter: new Adapter() });
 describe('renderers', () => {
     let props = null;
 
+    describe('ProcessStatus', () => {
+        props = {
+            uuid: 'zzzzz-xvhdp-zzzzzzzzzzzzzzz',
+            theme: {
+                customs: {
+                    colors: {
+                        // Color values are arbitrary, but they should be
+                        // representative of the colors used in the UI.
+                        blue500: 'rgb(0, 0, 255)',
+                        green700: 'rgb(0, 255, 0)',
+                        yellow700: 'rgb(255, 255, 0)',
+                        red900: 'rgb(255, 0, 0)',
+                        grey500: 'rgb(128, 128, 128)',
+                    }
+                },
+                spacing: {
+                    unit: 8,
+                },
+                palette: {
+                    common: {
+                        white: 'rgb(255, 255, 255)',
+                    },
+                },
+            },
+        };
+
+        [
+            // CR Status ; Priority ; C Status ; Exit Code ; C RuntimeStatus ; Expected label ; Expected Color
+            [CR.COMMITTED, 1, C.RUNNING, null, {}, PS.RUNNING, props.theme.customs.colors.blue500],
+            [CR.COMMITTED, 1, C.RUNNING, null, {error: 'whoops'}, PS.FAILING, props.theme.customs.colors.red900],
+            [CR.COMMITTED, 1, C.RUNNING, null, {warning: 'watch out!'}, PS.WARNING, props.theme.customs.colors.yellow700],
+            [CR.FINAL, 1, C.CANCELLED, null, {}, PS.CANCELLED, props.theme.customs.colors.red900],
+            [CR.FINAL, 1, C.COMPLETE, 137, {}, PS.FAILED, props.theme.customs.colors.red900],
+            [CR.FINAL, 1, C.COMPLETE, 0, {}, PS.COMPLETED, props.theme.customs.colors.green700],
+            [CR.COMMITTED, 0, C.LOCKED, null, {}, PS.ONHOLD, props.theme.customs.colors.grey500],
+            [CR.COMMITTED, 0, C.QUEUED, null, {}, PS.ONHOLD, props.theme.customs.colors.grey500],
+            [CR.COMMITTED, 1, C.LOCKED, null, {}, PS.QUEUED, props.theme.customs.colors.grey500],
+            [CR.COMMITTED, 1, C.QUEUED, null, {}, PS.QUEUED, props.theme.customs.colors.grey500],
+        ].forEach(([crState, crPrio, cState, exitCode, rs, eLabel, eColor]) => {
+            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)}`, () => {
+                const containerUuid = 'zzzzz-dz642-zzzzzzzzzzzzzzz';
+                const store = mockStore({ resources: {
+                    [props.uuid]: {
+                        kind: ResourceKind.CONTAINER_REQUEST,
+                        state: crState,
+                        containerUuid: containerUuid,
+                        priority: crPrio,
+                    },
+                    [containerUuid]: {
+                        kind: ResourceKind.CONTAINER,
+                        state: cState,
+                        runtimeStatus: rs,
+                        exitCode: exitCode,
+                    },
+                }});
+
+                const wrapper = mount(<Provider store={store}>
+                        <ProcessStatus {...props} />
+                    </Provider>);
+
+                expect(wrapper.text()).toEqual(eLabel);
+                expect(getComputedStyle(wrapper.getDOMNode())
+                    .getPropertyValue('color')).toEqual(props.theme.palette.common.white);
+                expect(getComputedStyle(wrapper.getDOMNode())
+                    .getPropertyValue('background-color')).toEqual(eColor);
+            });
+        })
+    });
+
     describe('ResourceFileSize', () => {
         beforeEach(() => {
             props = {
