Skip to content

Commit

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

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

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

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(<GithubBuildShaLink {...props} />);
expect(container).toBeEmptyDOMElement();
});
});

0 comments on commit 6f77c88

Please sign in to comment.