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 17b6a7e
Showing 1 changed file with 52 additions and 0 deletions.
52 changes: 52 additions & 0 deletions frontend/shared/GithubBuildShaLink.test.jsx
Original file line number Diff line number Diff line change
@@ -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('<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 17b6a7e

Please sign in to comment.