|
1 | 1 | import React from 'react'; |
2 | 2 | import { expect, assert } from 'chai'; |
3 | 3 | import proxyquire from 'proxyquire'; |
4 | | -import sinon from 'sinon'; |
5 | 4 | import { mount } from 'enzyme'; |
6 | 5 |
|
7 | | -import api from '../../../../frontend/util/federalistApi'; |
8 | 6 | import LoadingIndicator from '../../../../frontend/components/LoadingIndicator'; |
9 | 7 |
|
10 | | -proxyquire.noCallThru(); |
11 | | - |
12 | | -const fetchBuildMock = sinon.stub(); |
13 | | -const buildActions = { |
14 | | - fetchBuild: fetchBuildMock, |
15 | | -}; |
16 | 8 | const CommitSummary = proxyquire( |
17 | 9 | '../../../../frontend/components/site/CommitSummary', |
18 | 10 | { |
19 | 11 | '../icons': { |
20 | 12 | IconBranch: () => <span />, |
21 | 13 | }, |
22 | | - '../../actions/buildActions': buildActions, |
23 | 14 | } |
24 | 15 | ).default; |
25 | 16 |
|
26 | 17 | const defaultProps = { |
27 | | - buildId: 1, |
| 18 | + buildDetails: { |
| 19 | + site: { |
| 20 | + owner: 'user', |
| 21 | + repository: 'repo', |
| 22 | + }, |
| 23 | + branch: 'branch', |
| 24 | + username: 'username', |
| 25 | + clonedCommitSha: 'sha4567890abcdef', |
| 26 | + createdAt: new Date(), |
| 27 | + } |
28 | 28 | }; |
29 | 29 |
|
30 | 30 | describe('<CommitSummary />', () => { |
31 | | - afterEach(() => { |
32 | | - sinon.restore(); |
33 | | - }); |
34 | | - |
35 | 31 | it('should exist', () => { |
36 | 32 | assert.isDefined(CommitSummary); |
37 | 33 | }); |
38 | 34 |
|
39 | | - it('renders a loading state whie loading', () => { |
40 | | - const stub = sinon.stub(api, 'fetchBuild'); |
41 | | - stub.resolves([]); |
42 | | - |
43 | | - const wrapper = mount(<CommitSummary {...defaultProps} />); |
| 35 | + it('renders a loading state while loading', () => { |
| 36 | + const wrapper = mount(<CommitSummary { ...{ buildDetails: null } } />); |
44 | 37 | expect(wrapper.find(LoadingIndicator)).to.have.length(1); |
45 | 38 | }); |
46 | 39 |
|
47 | | - // no useEffect in tests |
48 | | - // it('requests build information once on load', () => { |
49 | | - // const wrapper = mountStore(<CommitSummary {...defaultProps} />, defaultState); |
50 | | - // const buildId = 1; |
51 | | - // expect(fetchBuildMock.callCount).to.be.greaterThanOrEqual(1); |
52 | | - // fetchBuildMock.resetHistory(); |
53 | | - // sinon.restore(); |
54 | | - // }); |
55 | | - |
56 | | - // describe('after load', () => { |
57 | | - // let wrapper; |
58 | | - // let loadedState = lodashClonedeep(defaultState); |
59 | | - // loadedState.build = { |
60 | | - // isLoading: false, |
61 | | - // data: { ...defaultBuildData } |
62 | | - // }; |
63 | | - |
64 | | - // it('renders the branch and github user name for the commit', () => { |
65 | | - // wrapper = mountStore(<CommitSummary {...defaultProps} />, loadedState); |
66 | | - // expect(wrapper.find('.commit-branch')).to.have.length(1); |
67 | | - // expect(wrapper.find('.commit-branch').text()).to.contain(defaultBuildData.branch); |
68 | | - // expect(wrapper.find('.commit-username')).to.have.length(1); |
69 | | - // expect(wrapper.find('.commit-username').text()).to.equal(defaultBuildData.username); |
70 | | - // }); |
71 | | - |
72 | | - // it('formats a sha link correctly and limits to first 7 chars', () => { |
73 | | - // wrapper = mountStore(<CommitSummary {...defaultProps} />, loadedState); |
74 | | - // expect(wrapper.find('.sha-link')).to.have.length(1); |
75 | | - // expect(defaultBuildData.clonedCommitSha).to.contain(wrapper.find('.sha-link').text()); |
76 | | - // expect(wrapper.find('.sha-link').text()).to.have.length(7); |
77 | | - // }); |
78 | | - // }); |
| 40 | + describe('after load', () => { |
| 41 | + const build = defaultProps.buildDetails; |
| 42 | + |
| 43 | + it('renders the branch and github user name for the commit', () => { |
| 44 | + const wrapper = mount(<CommitSummary {...defaultProps} />); |
| 45 | + expect(wrapper.find('.commit-branch')).to.have.length(1); |
| 46 | + expect(wrapper.find('.commit-branch').text()).to.contain(build.branch); |
| 47 | + expect(wrapper.find('.commit-username')).to.have.length(1); |
| 48 | + expect(wrapper.find('.commit-username').text()).to.equal(build.username); |
| 49 | + }); |
| 50 | + |
| 51 | + it('formats a sha link correctly and limits to first 7 chars', () => { |
| 52 | + const wrapper = mount(<CommitSummary {...defaultProps} />); |
| 53 | + expect(wrapper.find('.sha-link')).to.have.length(1); |
| 54 | + expect(build.clonedCommitSha).to.contain(wrapper.find('.sha-link').text()); |
| 55 | + expect(wrapper.find('.sha-link').text()).to.have.length(7); |
| 56 | + }); |
| 57 | + }); |
79 | 58 | }); |
0 commit comments