From fb53cdee60b446a873ecafab115b4ebc4e06f5b1 Mon Sep 17 00:00:00 2001 From: Sarah Rudder Date: Thu, 5 Dec 2024 10:16:53 -0600 Subject: [PATCH] chore: Test shared/GithubBuildBranchLink #4670 --- frontend/shared/GithubBuildBranchLink.jsx | 4 +-- .../shared/GithubBuildBranchLink.test.jsx | 35 +++++++++++++++++++ 2 files changed, 37 insertions(+), 2 deletions(-) create mode 100644 frontend/shared/GithubBuildBranchLink.test.jsx diff --git a/frontend/shared/GithubBuildBranchLink.jsx b/frontend/shared/GithubBuildBranchLink.jsx index 6e4903e83..d7b7736a1 100644 --- a/frontend/shared/GithubBuildBranchLink.jsx +++ b/frontend/shared/GithubBuildBranchLink.jsx @@ -2,7 +2,7 @@ import React from 'react'; import PropTypes from 'prop-types'; import GitHubLink from './GitHubLink'; -export default function GithubBuildShaLink({ build, site }) { +export default function GithubBuildBranchLink({ build, site }) { const { owner, repository } = site; const { branch } = build; @@ -18,7 +18,7 @@ export default function GithubBuildShaLink({ build, site }) { ); } -GithubBuildShaLink.propTypes = { +GithubBuildBranchLink.propTypes = { build: PropTypes.shape({ branch: PropTypes.string.isRequired, }).isRequired, diff --git a/frontend/shared/GithubBuildBranchLink.test.jsx b/frontend/shared/GithubBuildBranchLink.test.jsx new file mode 100644 index 000000000..946524f70 --- /dev/null +++ b/frontend/shared/GithubBuildBranchLink.test.jsx @@ -0,0 +1,35 @@ +import React from 'react'; +import { render, screen } from '@testing-library/react'; +import '@testing-library/jest-dom'; + +import GithubBuildBranchLink from './GithubBuildBranchLink'; + +const defaultBuild = { + branch: 'branch_name', +} +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('branch-link'); + expect(anchor).toHaveAttribute('title', 'View branch on GitHub'); + }); + it('uses the build’s branch and the site’s repo and owner', () => { + const props = {...defaultProps}; + render(); + + const anchor = screen.getByRole('link'); + + expect(anchor).toHaveAttribute('href', 'https://github.com/repo_owner/repo_name/tree/branch_name'); + expect(anchor).toHaveTextContent('branch_name'); + }); +});