Skip to content

Commit

Permalink
chore: Test shared/GithubBuildBranchLink #4670
Browse files Browse the repository at this point in the history
  • Loading branch information
sknep committed Dec 6, 2024
1 parent e3d8f75 commit fb53cde
Show file tree
Hide file tree
Showing 2 changed files with 37 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
35 changes: 35 additions & 0 deletions frontend/shared/GithubBuildBranchLink.test.jsx
Original file line number Diff line number Diff line change
@@ -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('<GithubBuildBranchLink/>', () => {
it('renders', () => {
const props = {...defaultProps};
render(<GithubBuildBranchLink {...props} />);

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(<GithubBuildBranchLink {...props} />);

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 fb53cde

Please sign in to comment.