Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Dec 15, 2022. It is now read-only.

Commit 40b015e

Browse files
committed
WIP tests for CommitController
1 parent 99fe542 commit 40b015e

File tree

1 file changed

+40
-34
lines changed

1 file changed

+40
-34
lines changed

test/controllers/commit-controller.test.js

Lines changed: 40 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -55,45 +55,66 @@ describe('CommitController', function() {
5555
atomEnvironment.destroy();
5656
});
5757

58+
describe('when commit.template config is set', function() {
59+
it('populates the commit message with the template', async function() {
60+
const workdirPath = await cloneRepository('commit-template');
61+
const repository = await buildRepository(workdirPath);
62+
const templateCommitMessage = await repository.git.getCommitMessageFromTemplate();
63+
app = React.cloneElement(app, {repository});
64+
const wrapper = shallow(app, {disableLifecycleMethods: true});
65+
await assert.async.strictEqual(wrapper.instance().getCommitMessage(), templateCommitMessage);
66+
});
67+
68+
it('restores template after committig', async function() {
69+
const templateText = 'some commit message';
70+
const commitMsgTemplatePath = path.join(workdirPath, '.gitmessage');
71+
await fs.writeFile(commitMsgTemplatePath, templateText, {encoding: 'utf8'});
72+
await repository.git.setConfig('commit.template', commitMsgTemplatePath);
73+
74+
await fs.writeFile(path.join(workdirPath, 'a.txt'), 'some changes', {encoding: 'utf8'});
75+
await repository.git.exec(['add', '.']);
76+
77+
const wrapper = shallow(app, {disableLifecycleMethods: true});
78+
await wrapper.instance().commit('some message');
79+
assert.strictEqual(repository.getCommitMessage(), templateText);
80+
});
81+
});
82+
5883
it('correctly updates state when switching repos', async function() {
5984
const workdirPath1 = await cloneRepository('three-files');
6085
const repository1 = await buildRepository(workdirPath1);
6186
const workdirPath2 = await cloneRepository('three-files');
6287
const repository2 = await buildRepository(workdirPath2);
63-
const workdirPath3 = await cloneRepository('commit-template');
64-
const repository3 = await buildRepository(workdirPath3);
65-
const templateCommitMessage = await repository3.git.getCommitMessageFromTemplate();
88+
89+
// set commit template for repository2
90+
const templateText = 'some commit message';
91+
const commitMsgTemplatePath = path.join(workdirPath2, '.gitmessage');
92+
await fs.writeFile(commitMsgTemplatePath, templateText, {encoding: 'utf8'});
93+
await repository2.git.setConfig('commit.template', commitMsgTemplatePath);
94+
// assert.strictEqual(await repository2.getCommitMessageFromTemplate(), templateText);
95+
96+
// const workdirPath3 = await cloneRepository('commit-template');
97+
// const repository3 = await buildRepository(workdirPath3);
98+
// const templateCommitMessage = await repository3.git.getCommitMessageFromTemplate();
6699

67100
app = React.cloneElement(app, {repository: repository1});
68101
const wrapper = shallow(app, {disableLifecycleMethods: true});
69102

70103
assert.strictEqual(wrapper.instance().getCommitMessage(), '');
71104

72105
wrapper.instance().setCommitMessage('message 1');
106+
assert.equal(wrapper.instance().getCommitMessage(), 'message 1');
73107

74108
wrapper.setProps({repository: repository2});
75-
76-
assert.strictEqual(wrapper.instance().getCommitMessage(), '');
109+
await assert.async.strictEqual(wrapper.instance().getCommitMessage(), templateText);
77110

78111
wrapper.setProps({repository: repository1});
79112
assert.equal(wrapper.instance().getCommitMessage(), 'message 1');
80-
wrapper.setProps({repository: repository3});
81-
await assert.async.strictEqual(wrapper.instance().getCommitMessage(), templateCommitMessage);
82-
});
83-
84113

85-
describe('when commit.template config is set', function() {
86-
it('populates the commit message with the template', async function() {
87-
const workdirPath = await cloneRepository('commit-template');
88-
const repository = await buildRepository(workdirPath);
89-
const templateCommitMessage = await repository.git.getCommitMessageFromTemplate();
90-
app = React.cloneElement(app, {repository});
91-
const wrapper = shallow(app, {disableLifecycleMethods: true});
92-
await assert.async.strictEqual(wrapper.instance().getCommitMessage(), templateCommitMessage);
93-
});
114+
// wrapper.setProps({repository: repository3});
115+
// await assert.async.strictEqual(wrapper.instance().getCommitMessage(), templateCommitMessage);
94116
});
95117

96-
97118
describe('the passed commit message', function() {
98119
let repository;
99120

@@ -158,21 +179,6 @@ describe('CommitController', function() {
158179
assert.strictEqual(repository.getCommitMessage(), '');
159180
});
160181

161-
it('reload the commit messages from commit template', async function() {
162-
const repoPath = await cloneRepository('commit-template');
163-
const repo = await buildRepositoryWithPipeline(repoPath, {confirm, notificationManager, workspace});
164-
const templateCommitMessage = await repo.git.getCommitMessageFromTemplate();
165-
const commitStub = sinon.stub().callsFake((...args) => repo.commit(...args));
166-
const app2 = React.cloneElement(app, {repository: repo, commit: commitStub});
167-
168-
await fs.writeFile(path.join(repoPath, 'a.txt'), 'some changes', {encoding: 'utf8'});
169-
await repo.git.exec(['add', '.']);
170-
171-
const wrapper = shallow(app2, {disableLifecycleMethods: true});
172-
await wrapper.instance().commit('some message');
173-
assert.strictEqual(repo.getCommitMessage(), templateCommitMessage);
174-
});
175-
176182
it('sets the verbatim flag when committing from the mini editor', async function() {
177183
await fs.writeFile(path.join(workdirPath, 'a.txt'), 'some changes', {encoding: 'utf8'});
178184
await repository.git.exec(['add', '.']);

0 commit comments

Comments
 (0)