From 9734d581bb20c625e8aa3a4f3357105ee3111506 Mon Sep 17 00:00:00 2001 From: Harry Hogg Date: Fri, 10 Sep 2021 14:51:06 +0100 Subject: [PATCH] test(plugin-cloudbuild): Added some tests for WorkflowRunsTableView Signed-off-by: Harry Hogg --- .../WorkflowRunsTable.test.tsx | 103 ++++++++++++++++++ .../WorkflowRunsTable/WorkflowRunsTable.tsx | 5 +- 2 files changed, 106 insertions(+), 2 deletions(-) create mode 100644 plugins/cloudbuild/src/components/WorkflowRunsTable/WorkflowRunsTable.test.tsx diff --git a/plugins/cloudbuild/src/components/WorkflowRunsTable/WorkflowRunsTable.test.tsx b/plugins/cloudbuild/src/components/WorkflowRunsTable/WorkflowRunsTable.test.tsx new file mode 100644 index 0000000000..ac28c5bedf --- /dev/null +++ b/plugins/cloudbuild/src/components/WorkflowRunsTable/WorkflowRunsTable.test.tsx @@ -0,0 +1,103 @@ +/* + * Copyright 2020 The Backstage Authors + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +import { renderInTestApp } from '@backstage/test-utils'; +import React from 'react'; +import { WorkflowRunsTableView } from './WorkflowRunsTable'; +import { WorkflowRun } from '../useWorkflowRuns'; + +describe('', () => { + let runs: WorkflowRun[] = []; + + beforeEach(() => { + runs = [ + { + id: 'run_id_1', + message: 'A workflow message', + rerun: jest.fn(), + url: 'https://cloudbuild.run/', + googleUrl: 'https://google.com', + status: 'success', + substitutions: { + COMMIT_SHA: 'e3adasd2e3adasd2e3adasd2', + SHORT_SHA: 'f12j1231', + BRANCH_NAME: 'main', + REPO_NAME: 'backstage', + REVISION_ID: 'g123123', + }, + createTime: '2014-10-02T15:01:23.045123456Z', + }, + ]; + }); + + it('row has a link to the run', async () => { + const { getByTestId } = await renderInTestApp( + , + ); + + expect(getByTestId('cell-source')).toHaveAttribute('href', '/run_id_1'); + }); + + it('row has the time it was created', async () => { + const { getByTestId } = await renderInTestApp( + , + ); + + expect(getByTestId('cell-created')).toHaveTextContent( + '02-10-2014 03:01:23', + ); + }); + + it('row with an action to rerun', async () => { + const { getByTestId } = await renderInTestApp( + , + ); + + const rerunActionElement = getByTestId('action-rerun'); + rerunActionElement.click(); + expect(runs[0].rerun).toHaveBeenCalled(); + }); +}); diff --git a/plugins/cloudbuild/src/components/WorkflowRunsTable/WorkflowRunsTable.tsx b/plugins/cloudbuild/src/components/WorkflowRunsTable/WorkflowRunsTable.tsx index 8fbf89cdce..f0e71baf3f 100644 --- a/plugins/cloudbuild/src/components/WorkflowRunsTable/WorkflowRunsTable.tsx +++ b/plugins/cloudbuild/src/components/WorkflowRunsTable/WorkflowRunsTable.tsx @@ -57,6 +57,7 @@ const generatedColumns: TableColumn[] = [ render: (row: Partial) => ( {row.message} @@ -82,7 +83,7 @@ const generatedColumns: TableColumn[] = [ { title: 'Created', render: (row: Partial) => ( - +

{moment(row.createTime).format('DD-MM-YYYY hh:mm:ss')}

), @@ -91,7 +92,7 @@ const generatedColumns: TableColumn[] = [ title: 'Actions', render: (row: Partial) => ( - +