From 6a65b98be5ef14572182e13f53de4491330df65e Mon Sep 17 00:00:00 2001 From: Sarah Rudder Date: Wed, 4 Dec 2024 19:10:58 -0600 Subject: [PATCH] chore: Test shared/GithubBuildShaLink #4669 --- frontend/shared/GithubBuildShaLink.test.jsx | 52 +++++++++++++++++++++ package.json | 1 + yarn.lock | 33 ++++++++++--- 3 files changed, 79 insertions(+), 7 deletions(-) create mode 100644 frontend/shared/GithubBuildShaLink.test.jsx diff --git a/frontend/shared/GithubBuildShaLink.test.jsx b/frontend/shared/GithubBuildShaLink.test.jsx new file mode 100644 index 000000000..719895017 --- /dev/null +++ b/frontend/shared/GithubBuildShaLink.test.jsx @@ -0,0 +1,52 @@ +import React from 'react'; +import { render, screen } from '@testing-library/react'; +import '@testing-library/jest-dom'; + +import GithubBuildShaLink from './GithubBuildShaLink'; + +const defaultBuild = { + clonedCommitSha: 'cloned_sha', + requestedCommitSha: 'requested_sha' +} +const defaultSite = { + owner: 'repo_owner', + repository: 'repo_name' +}; +const defaultProps = {...{ build: defaultBuild, site: defaultSite}} + +describe('', () => { + it('renders', () => { + const props = {...defaultProps}; + render(); + + const anchor = screen.getByRole('link'); + expect(anchor).toHaveClass('sha-link'); + expect(anchor).toHaveAttribute('title', 'View commit on GitHub'); + + }); + it('uses clonedCommitSha by default, if provided', () => { + const props = {...defaultProps}; + render(); + + const anchor = screen.getByRole('link'); + + expect(anchor).toHaveAttribute('href', 'https://github.com/repo_owner/repo_name/commit/cloned_sha'); + expect(anchor).toHaveTextContent('cloned_'); + + }); + it('uses requestedCommitSha if clonedCommitSha is not provided', () => { + const props = {...{ build: { requestedCommitSha: '1234567890'}, site: defaultSite}}; + render(); + + const anchor = screen.getByRole('link'); + + expect(anchor).toHaveAttribute('href', 'https://github.com/repo_owner/repo_name/commit/1234567890'); + expect(anchor).toHaveTextContent('1234567'); + + }); + it('renders nothing if no sha is provided', () => { + const props = {...{ build: {}, site: defaultSite}}; + const { container } = render(); + expect(container.innerHTML).toBe(''); + }); +}); diff --git a/package.json b/package.json index c0f66b620..b36fafa95 100644 --- a/package.json +++ b/package.json @@ -8,6 +8,7 @@ "@aws-sdk/client-s3": "^3.620.1", "@bull-board/api": "6.5.3", "@bull-board/express": "6.5.3", + "@cfaester/enzyme-adapter-react-18": "^0.8.0", "@json2csv/plainjs": "^7.0.1", "@octokit/rest": "^18.5.2", "@socket.io/redis-adapter": "^7.0.0", diff --git a/yarn.lock b/yarn.lock index caff31c36..66dfedf36 100644 --- a/yarn.lock +++ b/yarn.lock @@ -1827,6 +1827,17 @@ dependencies: "@bull-board/api" "6.5.3" +"@cfaester/enzyme-adapter-react-18@^0.8.0": + version "0.8.0" + resolved "https://registry.yarnpkg.com/@cfaester/enzyme-adapter-react-18/-/enzyme-adapter-react-18-0.8.0.tgz#313814eb79658a6e74209f9f1743bcefff14a46f" + integrity sha512-3Z3ThTUouHwz8oIyhTYQljEMNRFtlVyc3VOOHCbxs47U6cnXs8K9ygi/c1tv49s7MBlTXeIcuN+Ttd9aPtILFQ== + dependencies: + enzyme-shallow-equal "^1.0.0" + function.prototype.name "^1.1.6" + has "^1.0.4" + react-is "^18.2.0" + react-shallow-renderer "^16.15.0" + "@colors/colors@1.5.0": version "1.5.0" resolved "https://registry.yarnpkg.com/@colors/colors/-/colors-1.5.0.tgz#bb504579c1cae923e6576a4f5da43d25f97bdbd9" @@ -5585,7 +5596,7 @@ envinfo@^7.7.3: resolved "https://registry.yarnpkg.com/envinfo/-/envinfo-7.14.0.tgz#26dac5db54418f2a4c1159153a0b2ae980838aae" integrity sha512-CO40UI41xDQzhLB1hWyqUKgFhs250pNcGbyGKe1l/e4FSaI/+YE4IMG76GDt0In67WLPACIITC+sOi08x4wIvg== -enzyme-shallow-equal@^1.0.1: +enzyme-shallow-equal@^1.0.0, enzyme-shallow-equal@^1.0.1: version "1.0.7" resolved "https://registry.yarnpkg.com/enzyme-shallow-equal/-/enzyme-shallow-equal-1.0.7.tgz#4e3aa678022387a68e6c47aff200587851885b5e" integrity sha512-/um0GFqUXnpM9SvKtje+9Tjoz3f1fpBC3eXRFrNs8kpYn69JljciYP7KZTqM/YQbUY9KUjvKB4jo/q+L6WGGvg== @@ -6896,7 +6907,7 @@ has-tostringtag@^1.0.0, has-tostringtag@^1.0.2: dependencies: has-symbols "^1.0.3" -has@^1.0.3: +has@^1.0.3, has@^1.0.4: version "1.0.4" resolved "https://registry.yarnpkg.com/has/-/has-1.0.4.tgz#2eb2860e000011dae4f1406a86fe80e530fb2ec6" integrity sha512-qdSAmqLF6209RFj4VVItywPMbm3vWylknmB3nvNiUIs72xAimcM8nVYxYr7ncvZq5qzk9MKIZR8ijqD/1QuYjQ== @@ -9784,6 +9795,11 @@ react-highlight@^0.15.0: dependencies: highlight.js "^10.5.0" +"react-is@^16.12.0 || ^17.0.0 || ^18.0.0", react-is@^18.0.0, react-is@^18.2.0: + version "18.3.1" + resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.3.1.tgz#e83557dc12eae63a99e003a46388b1dcbb44db7e" + integrity sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg== + react-is@^16.13.1, react-is@^16.4.2, react-is@^16.7.0: version "16.13.1" resolved "https://registry.yarnpkg.com/react-is/-/react-is-16.13.1.tgz#789729a4dc36de2999dc156dd6c1d9c18cea56a4" @@ -9794,11 +9810,6 @@ react-is@^17.0.1, react-is@^17.0.2: resolved "https://registry.yarnpkg.com/react-is/-/react-is-17.0.2.tgz#e691d4a8e9c789365655539ab372762b0efb54f0" integrity sha512-w2GsyukL62IJnlaff/nRegPQR94C/XXamvMWmSHRJ4y7Ts/4ocGRmTHvOs8PSE6pB3dWOrD/nueuU5sduBsQ4w== -react-is@^18.0.0: - version "18.3.1" - resolved "https://registry.yarnpkg.com/react-is/-/react-is-18.3.1.tgz#e83557dc12eae63a99e003a46388b1dcbb44db7e" - integrity sha512-/LLMVyas0ljjAtoYiPqYiL8VWXzUUdThrmU5+n20DZv+a+ClRoevUzw5JxU+Ieh5/c87ytoTBV9G1FiKfNJdmg== - react-notification-system-redux@^2.0.1: version "2.0.1" resolved "https://registry.yarnpkg.com/react-notification-system-redux/-/react-notification-system-redux-2.0.1.tgz#e1f47e788d344fac9b5183402bb96c73033e5854" @@ -9843,6 +9854,14 @@ react-router@6.28.0: dependencies: "@remix-run/router" "1.21.0" +react-shallow-renderer@^16.15.0: + version "16.15.0" + resolved "https://registry.yarnpkg.com/react-shallow-renderer/-/react-shallow-renderer-16.15.0.tgz#48fb2cf9b23d23cde96708fe5273a7d3446f4457" + integrity sha512-oScf2FqQ9LFVQgA73vr86xl2NaOIX73rh+YFqcOp68CWj56tSfgtGKrEbyhCj0rSijyG9M1CYprTh39fBi5hzA== + dependencies: + object-assign "^4.1.1" + react-is "^16.12.0 || ^17.0.0 || ^18.0.0" + react@^18.2.0: version "18.3.1" resolved "https://registry.yarnpkg.com/react/-/react-18.3.1.tgz#49ab892009c53933625bd16b2533fc754cab2891"