Skip to content

Commit

Permalink
Merge pull request #4689 from cloud-gov/chore-test-shared/GithubBuild…
Browse files Browse the repository at this point in the history
…BranchLink-4670

Chore: test shared/GithubBuildBranchLink.jsx #4670
  • Loading branch information
sknep authored Dec 11, 2024
2 parents aa290c0 + 0045a6f commit 59880f1
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 2 deletions.
4 changes: 2 additions & 2 deletions frontend/shared/GithubBuildBranchLink.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -18,7 +18,7 @@ export default function GithubBuildShaLink({ build, site }) {
);
}

GithubBuildShaLink.propTypes = {
GithubBuildBranchLink.propTypes = {
build: PropTypes.shape({
branch: PropTypes.string.isRequired,
}).isRequired,
Expand Down
36 changes: 36 additions & 0 deletions frontend/shared/GithubBuildBranchLink.test.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
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('<GithubBuildBranchLink/>', () => {
it('renders', () => {
render(<GithubBuildBranchLink {...defaultProps} />);

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', () => {
render(<GithubBuildBranchLink {...defaultProps} />);

const anchor = screen.getByRole('link');

expect(anchor).toHaveAttribute(
'href',
'https://github.com/repo_owner/repo_name/tree/branch_name',
);
expect(anchor).toHaveTextContent('branch_name');
});
});

0 comments on commit 59880f1

Please sign in to comment.