This repository was archived by the owner on Apr 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 299
Expand file tree
/
Copy pathVersionControlComponents.test.tsx
More file actions
72 lines (61 loc) · 2.67 KB
/
VersionControlComponents.test.tsx
File metadata and controls
72 lines (61 loc) · 2.67 KB
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
import { mount, shallow } from "enzyme"
import { shallowToJson } from "enzyme-to-json"
import * as React from "react"
import Octicon from "./../../browser/src/UI/components/Octicon"
import {
Branch,
BranchNameContainer,
} from "./../../browser/src/UI/components/VersionControl/Branch"
describe("<Branch />", () => {
const diff = {
insertions: 2,
deletions: 8,
files: null as any,
}
it("Should render without crashing", () => {
const wrapper = shallow(<Branch branch="test-branch" diff={diff} />)
expect(wrapper.length).toEqual(1)
})
it("Should render the correct branch name", () => {
const wrapper = shallow(<Branch branch="test-branch" diff={diff} />)
const name = wrapper
.find(BranchNameContainer)
.dive()
.text()
expect(name).toBe("test-branch < />")
})
it("should match last known snapshot unless we make a change", () => {
const wrapper = shallow(<Branch branch="test-branch" diff={diff} />)
expect(shallowToJson(wrapper)).toMatchSnapshot()
})
it("Should show the correct number of additions", () => {
const wrapper = mount(<Branch branch="test-branch" diff={diff} />)
const additions = wrapper.find("[data-test='addition-2']")
expect(additions.find("span").text()).toEqual("2")
})
it("Should show the correct number of deletions", () => {
const wrapper = mount(<Branch branch="test-branch" diff={diff} />)
const deletions = wrapper.find("[data-test='deletion-8']")
expect(deletions.find("span").text()).toEqual("8")
})
it("should render the correct icon for additions", () => {
const wrapper = mount(<Branch branch="test-branch" diff={diff} />)
const hasAdded = wrapper.contains(<Octicon name="diff-added" />)
expect(hasAdded).toBe(true)
})
it("should render the correct icon for deletions", () => {
const wrapper = mount(<Branch branch="test-branch" diff={diff} />)
const hasDeleted = wrapper.contains(<Octicon name="diff-removed" />)
expect(hasDeleted).toBe(true)
})
it("Should not render an icon if there were no insertions", () => {
const wrapper = mount(<Branch branch="test-branch" diff={{ ...diff, insertions: 0 }} />)
const icon = wrapper.contains(<Octicon name="diff-added" />)
expect(icon).toBe(false)
})
it("Should not render an icon if there were no deletions", () => {
const wrapper = mount(<Branch branch="test-branch" diff={{ ...diff, deletions: 0 }} />)
const icon = wrapper.contains(<Octicon name="diff-removed" />)
expect(icon).toBe(false)
})
})