forked from atom/github
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcommit-preview-container.test.js
More file actions
74 lines (57 loc) · 2.26 KB
/
commit-preview-container.test.js
File metadata and controls
74 lines (57 loc) · 2.26 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
73
74
import React from 'react';
import {mount} from 'enzyme';
import CommitPreviewContainer from '../../lib/containers/commit-preview-container';
import CommitPreviewItem from '../../lib/items/commit-preview-item';
import {cloneRepository, buildRepository} from '../helpers';
describe('CommitPreviewContainer', function() {
let atomEnv, repository;
beforeEach(async function() {
atomEnv = global.buildAtomEnvironment();
const workdir = await cloneRepository();
repository = await buildRepository(workdir);
});
afterEach(function() {
atomEnv.destroy();
});
function buildApp(override = {}) {
const props = {
repository,
itemType: CommitPreviewItem,
workspace: atomEnv.workspace,
commands: atomEnv.commands,
keymaps: atomEnv.keymaps,
tooltips: atomEnv.tooltips,
config: atomEnv.config,
destroy: () => {},
discardLines: () => {},
undoLastDiscard: () => {},
surfaceToCommitPreviewButton: () => {},
...override,
};
return <CommitPreviewContainer {...props} />;
}
it('renders a loading spinner while the repository is loading', function() {
const wrapper = mount(buildApp());
assert.isTrue(wrapper.find('LoadingView').exists());
});
it('renders a loading spinner while the file patch is being loaded', async function() {
await repository.getLoadPromise();
const patchPromise = repository.getStagedChangesPatch();
let resolveDelayedPromise = () => {};
const delayedPromise = new Promise(resolve => {
resolveDelayedPromise = resolve;
});
sinon.stub(repository, 'getStagedChangesPatch').returns(delayedPromise);
const wrapper = mount(buildApp());
assert.isTrue(wrapper.find('LoadingView').exists());
resolveDelayedPromise(patchPromise);
await assert.async.isFalse(wrapper.update().find('LoadingView').exists());
});
it('renders a CommitPreviewController once the file patch is loaded', async function() {
await repository.getLoadPromise();
const patch = await repository.getStagedChangesPatch();
const wrapper = mount(buildApp());
await assert.async.isTrue(wrapper.update().find('CommitPreviewController').exists());
assert.strictEqual(wrapper.find('CommitPreviewController').prop('multiFilePatch'), patch);
});
});