forked from cloud-gov/pages-core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathGithubBuildShaLink.test.jsx
58 lines (47 loc) · 1.73 KB
/
GithubBuildShaLink.test.jsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
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();
});
});