From 9734d581bb20c625e8aa3a4f3357105ee3111506 Mon Sep 17 00:00:00 2001 From: Harry Hogg Date: Fri, 10 Sep 2021 14:51:06 +0100 Subject: [PATCH 1/6] 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) => ( - + From 6368b764377fb39df273fa915839abd93cced89b Mon Sep 17 00:00:00 2001 From: Harry Hogg Date: Fri, 10 Sep 2021 13:34:49 +0100 Subject: [PATCH 2/6] refactor(luxon): Plugin CloudBuild - Swapped over from using moment to luxon Signed-off-by: Harry Hogg --- plugins/cloudbuild/package.json | 2 +- .../WorkflowRunsTable/WorkflowRunsTable.tsx | 8 ++++++-- yarn.lock | 12 ++++++------ 3 files changed, 13 insertions(+), 9 deletions(-) diff --git a/plugins/cloudbuild/package.json b/plugins/cloudbuild/package.json index f28a42bac6..2d4655daa7 100644 --- a/plugins/cloudbuild/package.json +++ b/plugins/cloudbuild/package.json @@ -38,7 +38,7 @@ "@material-ui/core": "^4.12.2", "@material-ui/icons": "^4.9.1", "@material-ui/lab": "4.0.0-alpha.45", - "moment": "^2.27.0", + "luxon": "^2.0.2", "qs": "^6.9.4", "react": "^16.13.1", "react-dom": "^16.13.1", diff --git a/plugins/cloudbuild/src/components/WorkflowRunsTable/WorkflowRunsTable.tsx b/plugins/cloudbuild/src/components/WorkflowRunsTable/WorkflowRunsTable.tsx index f0e71baf3f..dd8046824e 100644 --- a/plugins/cloudbuild/src/components/WorkflowRunsTable/WorkflowRunsTable.tsx +++ b/plugins/cloudbuild/src/components/WorkflowRunsTable/WorkflowRunsTable.tsx @@ -24,7 +24,7 @@ import SyncIcon from '@material-ui/icons/Sync'; import { useProjectName } from '../useProjectName'; import { Entity } from '@backstage/catalog-model'; import { buildRouteRef } from '../../routes'; -import moment from 'moment'; +import { DateTime } from 'luxon'; import { Table, TableColumn } from '@backstage/core-components'; const generatedColumns: TableColumn[] = [ @@ -84,7 +84,11 @@ const generatedColumns: TableColumn[] = [ title: 'Created', render: (row: Partial) => ( -

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

+

+ {DateTime.fromISO(row.createTime ?? DateTime.now().toISO()).toFormat( + 'dd-MM-yyyy hh:mm:ss', + )} +

), }, diff --git a/yarn.lock b/yarn.lock index 5db9fd7589..58fc4c5b0a 100644 --- a/yarn.lock +++ b/yarn.lock @@ -11040,9 +11040,9 @@ core-js@^3.0.4, core-js@^3.6.5, core-js@^3.8.2: integrity sha512-GUbtPllXMYRzIgHNZ4dTYTcUemls2cni83Q4Q/TrFONHfhcg9oEGOtaGHfb0cpzec60P96UKPvMkjX1jET8rUw== core-js@^3.6.0: - version "3.17.2" - resolved "https://registry.npmjs.org/core-js/-/core-js-3.17.2.tgz#f960eae710dc62c29cca93d5332e3660e289db10" - integrity sha512-XkbXqhcXeMHPRk2ItS+zQYliAMilea2euoMsnpRRdDad6b2VY6CQQcwz1K8AnWesfw4p165RzY0bTnr3UrbYiA== + version "3.17.3" + resolved "https://registry.npmjs.org/core-js/-/core-js-3.17.3.tgz#8e8bd20e91df9951e903cabe91f9af4a0895bc1e" + integrity sha512-lyvajs+wd8N1hXfzob1LdOCCHFU4bGMbqqmLn1Q4QlCpDqWPpGf+p0nj+LNrvDDG33j0hZXw2nsvvVpHysxyNw== core-util-is@1.0.2, core-util-is@~1.0.0: version "1.0.2" @@ -27589,9 +27589,9 @@ write-pkg@^4.0.0: write-json-file "^3.2.0" ws@7.4.5, ws@^7.4.6: - version "7.5.4" - resolved "https://registry.npmjs.org/ws/-/ws-7.5.4.tgz#56bfa20b167427e138a7795de68d134fe92e21f9" - integrity sha512-zP9z6GXm6zC27YtspwH99T3qTG7bBFv2VIkeHstMLrLlDJuzA7tQ5ls3OJ1hOGGCzTQPniNJoHXIAOS0Jljohg== + version "7.5.5" + resolved "https://registry.npmjs.org/ws/-/ws-7.5.5.tgz#8b4bc4af518cfabd0473ae4f99144287b33eb881" + integrity sha512-BAkMFcAzl8as1G/hArkxOxq3G7pjUqQ3gzYbLL0/5zNkph70e+lCoxBGnm6AW1+/aiNeV4fnKqZ8m4GZewmH2w== ws@^5.2.0: version "5.2.3" From 4e28fcdef20d48b0a2946fe588fa3a04089a56e9 Mon Sep 17 00:00:00 2001 From: Harry Hogg Date: Fri, 10 Sep 2021 14:59:02 +0100 Subject: [PATCH 3/6] fix(plugin-cloudbuild): "validateDOMNesting(...):

cannot appear as a descendant of

" error caused by unnecessary paragraph tags Signed-off-by: Harry Hogg --- .../WorkflowRunsTable/WorkflowRunsTable.tsx | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/plugins/cloudbuild/src/components/WorkflowRunsTable/WorkflowRunsTable.tsx b/plugins/cloudbuild/src/components/WorkflowRunsTable/WorkflowRunsTable.tsx index dd8046824e..0d00347183 100644 --- a/plugins/cloudbuild/src/components/WorkflowRunsTable/WorkflowRunsTable.tsx +++ b/plugins/cloudbuild/src/components/WorkflowRunsTable/WorkflowRunsTable.tsx @@ -45,7 +45,7 @@ const generatedColumns: TableColumn[] = [ width: '150px', render: (row: Partial) => ( -

{row.id?.substring(0, 8)}

+ {row.id?.substring(0, 8)}
), }, @@ -68,7 +68,7 @@ const generatedColumns: TableColumn[] = [ title: 'Ref', render: (row: Partial) => ( -

{row.substitutions?.BRANCH_NAME}

+ {row.substitutions?.BRANCH_NAME}
), }, @@ -76,7 +76,7 @@ const generatedColumns: TableColumn[] = [ title: 'Commit', render: (row: Partial) => ( -

{row.substitutions?.SHORT_SHA}

+ {row.substitutions?.SHORT_SHA}
), }, @@ -84,11 +84,9 @@ const generatedColumns: TableColumn[] = [ title: 'Created', render: (row: Partial) => ( -

- {DateTime.fromISO(row.createTime ?? DateTime.now().toISO()).toFormat( - 'dd-MM-yyyy hh:mm:ss', - )} -

+ {DateTime.fromISO(row.createTime ?? DateTime.now().toISO()).toFormat( + 'dd-MM-yyyy hh:mm:ss', + )}
), }, From 4e4daf3c740fed233c89084cbbcc462f47498d23 Mon Sep 17 00:00:00 2001 From: Harry Hogg Date: Fri, 10 Sep 2021 15:13:45 +0100 Subject: [PATCH 4/6] docs(changeset): Added changeset Signed-off-by: Harry Hogg --- .changeset/wicked-jars-move.md | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 .changeset/wicked-jars-move.md diff --git a/.changeset/wicked-jars-move.md b/.changeset/wicked-jars-move.md new file mode 100644 index 0000000000..d2e9bc5446 --- /dev/null +++ b/.changeset/wicked-jars-move.md @@ -0,0 +1,6 @@ +--- +'@backstage/plugin-cloudbuild': patch +--- + +- Swaps over the plugin CloudBuild from using MomentJS to using Luxon for date formatting. +- Fixes some React warnings generated by nested

elements. From 90648a3f605d7bc860bc8b90cd5eb8958c9e0179 Mon Sep 17 00:00:00 2001 From: Harry Hogg Date: Mon, 13 Sep 2021 10:35:32 +0100 Subject: [PATCH 5/6] chore(backstage-cli): Set global jest timezone to UTC Signed-off-by: Harry Hogg --- packages/cli/src/commands/testCommand.ts | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/packages/cli/src/commands/testCommand.ts b/packages/cli/src/commands/testCommand.ts index d885e1aec9..24a4e06f9e 100644 --- a/packages/cli/src/commands/testCommand.ts +++ b/packages/cli/src/commands/testCommand.ts @@ -63,6 +63,13 @@ export default async (cmd: Command) => { (process.env as any).NODE_ENV = 'test'; } + // This is to have a consistent timezone for when running tests that involve checking + // the formatting of date/times. + // https://stackoverflow.com/questions/56261381/how-do-i-set-a-timezone-in-my-jest-config + if (!process.env.TZ) { + process.env.TZ = 'UTC'; + } + // eslint-disable-next-line jest/no-jest-import await require('jest').run(args); }; From 15e324ce6086271fc9e85225fb2117b240f09417 Mon Sep 17 00:00:00 2001 From: Harry Hogg Date: Mon, 13 Sep 2021 13:11:45 +0100 Subject: [PATCH 6/6] docs(Changeset): Added a changeset for the backstage-cli TZ change Signed-off-by: Harry Hogg --- .changeset/gorgeous-pugs-deliver.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/gorgeous-pugs-deliver.md diff --git a/.changeset/gorgeous-pugs-deliver.md b/.changeset/gorgeous-pugs-deliver.md new file mode 100644 index 0000000000..82820baa67 --- /dev/null +++ b/.changeset/gorgeous-pugs-deliver.md @@ -0,0 +1,5 @@ +--- +'@backstage/cli': patch +--- + +Set the default TZ (Timezone) env for the test command to be UTC so any date related tests are consistent across timezones.