-
Notifications
You must be signed in to change notification settings - Fork 73
/
Copy pathGitHubLink.test.jsx
77 lines (62 loc) · 2.14 KB
/
GitHubLink.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
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import GitHubLink from './GitHubLink';
describe('<GitHubLink/>', () => {
it('renders', () => {
const props = { owner: 'owner', repository: 'a-repo', text: 'link text' };
render(<GitHubLink {...props} />);
const anchor = screen.getByRole('link');
expect(anchor).toHaveClass('repo-link');
expect(anchor).toHaveAttribute('href', 'https://github.com/owner/a-repo');
expect(anchor).toHaveAttribute('title', 'View repository on GitHub');
expect(anchor).toHaveTextContent('link text');
// TODO: actually render svg with https://react-svgr.com/docs/node-api/ in tests
// const icon = screen.getByTitle('icon-github');
// expect(icon).toBeInTheDocument();
});
it('can link to a branch', () => {
const props = {
text: 'link text',
owner: 'pumpkin-pie',
repository: 'candle',
branch: 'the-branch',
};
render(<GitHubLink {...props} />);
const anchor = screen.getByRole('link');
expect(anchor).toHaveClass('repo-link');
expect(anchor).toHaveAttribute(
'href',
'https://github.com/pumpkin-pie/candle/tree/the-branch',
);
expect(anchor).toHaveAttribute('title', 'View branch on GitHub');
});
it('encodes the branch name', () => {
const props = {
text: 'boop',
owner: 'spam',
repository: 'potato',
branch: '#-hash-#',
};
render(<GitHubLink {...props} />);
const anchor = screen.getByRole('link');
expect(anchor).toHaveClass('repo-link');
expect(anchor).toHaveAttribute(
'href',
'https://github.com/spam/potato/tree/%23-hash-%23',
);
});
it('links to a specific commit', () => {
const props = {
text: 'boop',
owner: 'zookeeni',
repository: 'veggies',
sha: '123A',
};
render(<GitHubLink {...props} />);
const anchor = screen.getByRole('link');
expect(anchor).toHaveClass('repo-link');
const commitUrl = `https://github.com/${props.owner}/${props.repository}/commit/${props.sha}`;
expect(anchor).toHaveAttribute('href', commitUrl);
});
});