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

Skip to content

Commit d66bf93

Browse files
committed
🎨 Move commit tests into commit describe block
1 parent 819184d commit d66bf93

File tree

1 file changed

+58
-68
lines changed

1 file changed

+58
-68
lines changed

test/controllers/commit-view-controller.test.js

Lines changed: 58 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -91,17 +91,21 @@ describe('CommitViewController', function() {
9191
});
9292

9393
describe('committing', function() {
94-
let controller, resolve, reject;
94+
let controller, resolve, reject, workdirPath;
9595

9696
beforeEach(async function() {
97-
const workdirPath = await cloneRepository('three-files');
97+
workdirPath = await cloneRepository('three-files');
9898
const repository = await buildRepository(workdirPath);
9999
const commit = () => new Promise((resolver, rejecter) => {
100100
resolve = resolver;
101101
reject = rejecter;
102102
});
103103

104-
controller = new CommitViewController({commandRegistry, notificationManager, lastCommit, repository, commit});
104+
controller = new CommitViewController({workspace, commandRegistry, notificationManager, grammars, lastCommit, repository, commit});
105+
});
106+
107+
afterEach(() => {
108+
controller.destroy();
105109
});
106110

107111
it('clears the regular and amending commit messages', async function() {
@@ -133,76 +137,62 @@ describe('CommitViewController', function() {
133137
assert.equal(controller.regularCommitMessage, 'regular');
134138
assert.equal(controller.amendingCommitMessage, 'amending');
135139
});
136-
});
137-
138-
describe('toggling between commit box and commit editor', function() {
139-
let controller, workdirPath;
140-
beforeEach(async () => {
141-
workdirPath = await cloneRepository('three-files');
142-
const repository = await buildRepository(workdirPath);
143-
144-
controller = new CommitViewController({
145-
workspace, commandRegistry, notificationManager, grammars, lastCommit, repository,
146-
});
147-
});
148-
149-
afterEach(() => {
150-
controller.destroy();
151-
});
152140

153-
it('transfers the commit message contents', async function() {
154-
controller.refs.commitView.editor.setText('message in box');
155-
156-
commandRegistry.dispatch(atomEnvironment.views.getView(workspace), 'github:edit-commit-message-in-editor');
157-
let editor;
158-
await until(() => {
159-
editor = workspace.getActiveTextEditor();
160-
if (editor) {
161-
return path.basename(editor.getPath()) === 'ATOM_COMMIT_EDITMSG';
162-
} else {
163-
return false;
164-
}
141+
describe('toggling between commit box and commit editor', function() {
142+
it('transfers the commit message contents', async function() {
143+
controller.refs.commitView.editor.setText('message in box');
144+
145+
commandRegistry.dispatch(atomEnvironment.views.getView(workspace), 'github:edit-commit-message-in-editor');
146+
let editor;
147+
await until(() => {
148+
editor = workspace.getActiveTextEditor();
149+
if (editor) {
150+
return path.basename(editor.getPath()) === 'ATOM_COMMIT_EDITMSG';
151+
} else {
152+
return false;
153+
}
154+
});
155+
assert.equal(editor.getText(), 'message in box');
156+
157+
editor.setText('message in editor');
158+
editor.save();
159+
editor.destroy();
160+
await assert.async.equal(controller.refs.commitView.editor.getText(), 'message in editor');
165161
});
166-
assert.equal(editor.getText(), 'message in box');
167162

168-
editor.setText('message in editor');
169-
editor.save();
170-
editor.destroy();
171-
await assert.async.equal(controller.refs.commitView.editor.getText(), 'message in editor');
172-
});
173-
174-
it('activates editor if already opened', async function() {
175-
commandRegistry.dispatch(atomEnvironment.views.getView(workspace), 'github:edit-commit-message-in-editor');
176-
let editor;
177-
await until(() => {
178-
editor = workspace.getActiveTextEditor();
179-
if (editor) {
180-
return path.basename(editor.getPath()) === 'ATOM_COMMIT_EDITMSG';
181-
} else {
182-
return false;
183-
}
163+
it('activates editor if already opened', async function() {
164+
commandRegistry.dispatch(atomEnvironment.views.getView(workspace), 'github:edit-commit-message-in-editor');
165+
let editor;
166+
await until(() => {
167+
editor = workspace.getActiveTextEditor();
168+
if (editor) {
169+
return path.basename(editor.getPath()) === 'ATOM_COMMIT_EDITMSG';
170+
} else {
171+
return false;
172+
}
173+
});
174+
175+
await workspace.open(path.join(workdirPath, 'a.txt'));
176+
workspace.getActivePane().splitRight();
177+
await workspace.open(path.join(workdirPath, 'b.txt'));
178+
assert.notEqual(workspace.getActiveTextEditor(), editor);
179+
180+
commandRegistry.dispatch(atomEnvironment.views.getView(workspace), 'github:edit-commit-message-in-editor');
181+
await assert.async.equal(workspace.getActiveTextEditor(), editor);
184182
});
185183

186-
await workspace.open(path.join(workdirPath, 'a.txt'));
187-
workspace.getActivePane().splitRight();
188-
await workspace.open(path.join(workdirPath, 'b.txt'));
189-
assert.notEqual(workspace.getActiveTextEditor(), editor);
190-
191-
commandRegistry.dispatch(atomEnvironment.views.getView(workspace), 'github:edit-commit-message-in-editor');
192-
await assert.async.equal(workspace.getActiveTextEditor(), editor);
193-
});
194-
195-
// TODO: Why is this not passing? get text.plain.null-grammar
196-
xit('uses git commit grammar in the editor', async function() {
197-
commandRegistry.dispatch(atomEnvironment.views.getView(workspace), 'github:edit-commit-message-in-editor');
198-
let editor;
199-
await until(() => {
200-
editor = workspace.getActiveTextEditor();
201-
if (editor) {
202-
return editor.getGrammar().scopeName === COMMIT_GRAMMAR_SCOPE;
203-
} else {
204-
return false;
205-
}
184+
// TODO: Why is this not passing? get text.plain.null-grammar
185+
xit('uses git commit grammar in the editor', async function() {
186+
commandRegistry.dispatch(atomEnvironment.views.getView(workspace), 'github:edit-commit-message-in-editor');
187+
let editor;
188+
await until(() => {
189+
editor = workspace.getActiveTextEditor();
190+
if (editor) {
191+
return editor.getGrammar().scopeName === COMMIT_GRAMMAR_SCOPE;
192+
} else {
193+
return false;
194+
}
195+
});
206196
});
207197
});
208198
});

0 commit comments

Comments
 (0)