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

Commit bf25a63

Browse files
committed
Wait for editors to open in ResultsView spec
1 parent d1898e9 commit bf25a63

File tree

2 files changed

+40
-49
lines changed

2 files changed

+40
-49
lines changed

lib/project/results-view.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -390,7 +390,7 @@ class ResultsView {
390390
const result = this.model.getResultAt(this.selectedResultIndex);
391391
if (result) {
392392
const match = result.matches[this.selectedMatchIndex];
393-
atom.workspace
393+
return atom.workspace
394394
.open(result.filePath, {
395395
pending,
396396
split: reverseDirections[atom.config.get('find-and-replace.projectSearchResultsPaneSplitDirection')]

spec/results-view-spec.js

Lines changed: 39 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -257,44 +257,44 @@ describe('ResultsView', () => {
257257
});
258258

259259
describe("core:move-to-top and core:move-to-bottom", () => {
260-
beforeEach(async () => {
261-
workspaceElement.style.height = '300px';
262-
projectFindView.findEditor.setText('so');
263-
projectFindView.confirm();
264-
await searchPromise;
265-
resultsView = getResultsView();
266-
});
260+
beforeEach(async () => {
261+
workspaceElement.style.height = '300px';
262+
projectFindView.findEditor.setText('so');
263+
projectFindView.confirm();
264+
await searchPromise;
265+
resultsView = getResultsView();
266+
});
267267

268-
it("selects the first/last item when core:move-to-top/move-to-bottom is triggered", async () => {
269-
const {listView} = resultsView.refs;
270-
expect(listView.element.querySelectorAll('li').length).toBeLessThan(resultsView.model.getPathCount() + resultsView.model.getMatchCount());
268+
it("selects the first/last item when core:move-to-top/move-to-bottom is triggered", async () => {
269+
const {listView} = resultsView.refs;
270+
expect(listView.element.querySelectorAll('li').length).toBeLessThan(resultsView.model.getPathCount() + resultsView.model.getMatchCount());
271271

272-
await resultsView.moveToBottom();
273-
expect(listView.element.querySelectorAll('li')[1]).not.toHaveClass('selected');
274-
expect(_.last(listView.element.querySelectorAll('li'))).toHaveClass('selected');
275-
expect(listView.element.scrollTop).not.toBe(0);
272+
await resultsView.moveToBottom();
273+
expect(listView.element.querySelectorAll('li')[1]).not.toHaveClass('selected');
274+
expect(_.last(listView.element.querySelectorAll('li'))).toHaveClass('selected');
275+
expect(listView.element.scrollTop).not.toBe(0);
276276

277-
await resultsView.moveToTop();
278-
expect(listView.element.querySelector('.match-line')).toHaveClass('selected');
279-
expect(listView.element.scrollTop).toBe(0);
280-
});
277+
await resultsView.moveToTop();
278+
expect(listView.element.querySelector('.match-line')).toHaveClass('selected');
279+
expect(listView.element.scrollTop).toBe(0);
280+
});
281281

282-
it("selects the path when when core:move-to-bottom is triggered and last item is collapsed", async () => {
283-
await resultsView.moveToBottom();
284-
resultsView.collapseResult();
285-
await resultsView.moveToBottom();
282+
it("selects the path when when core:move-to-bottom is triggered and last item is collapsed", async () => {
283+
await resultsView.moveToBottom();
284+
resultsView.collapseResult();
285+
await resultsView.moveToBottom();
286286

287-
expect(_.last(resultsView.element.querySelectorAll('li')).closest('.path')).toHaveClass('selected');
288-
});
287+
expect(_.last(resultsView.element.querySelectorAll('li')).closest('.path')).toHaveClass('selected');
288+
});
289289

290-
it("selects the path when when core:move-to-top is triggered and first item is collapsed", async () => {
291-
await resultsView.moveToTop();
292-
atom.commands.dispatch(resultsView.element, 'core:move-left');
293-
await resultsView.moveToTop();
290+
it("selects the path when when core:move-to-top is triggered and first item is collapsed", async () => {
291+
await resultsView.moveToTop();
292+
atom.commands.dispatch(resultsView.element, 'core:move-left');
293+
await resultsView.moveToTop();
294294

295-
expect(resultsView.refs.listView.element.querySelector('li').closest('.path')).toHaveClass('selected');
296-
});
295+
expect(resultsView.refs.listView.element.querySelector('li').closest('.path')).toHaveClass('selected');
297296
});
297+
});
298298

299299
describe("expanding and collapsing results", () => {
300300
it('preserves the selected file when collapsing all results', async () => {
@@ -424,41 +424,32 @@ describe('ResultsView', () => {
424424
expect(atom.views.getView(editor)).toHaveFocus();
425425
})
426426

427-
describe("when `projectSearchResultsPaneSplitDirection` option is none", () => {
427+
describe("the `projectSearchResultsPaneSplitDirection` option", () => {
428428
beforeEach(() => {
429-
atom.config.set('find-and-replace.projectSearchResultsPaneSplitDirection', 'none');
429+
spyOn(atom.workspace, 'open').andCallThrough()
430430
});
431431

432-
it("does not specify a pane to split", () => {
433-
spyOn(atom.workspace, 'open').andCallThrough();
432+
it("does not create a split when the option is 'none'", async () => {
433+
atom.config.set('find-and-replace.projectSearchResultsPaneSplitDirection', 'none');
434434
atom.commands.dispatch(resultsView.element, 'core:move-down');
435435
atom.commands.dispatch(resultsView.element, 'core:confirm');
436+
await paneItemOpening()
436437
expect(atom.workspace.open.mostRecentCall.args[1].split).toBeUndefined();
437438
});
438-
});
439439

440-
describe("when `projectSearchResultsPaneSplitDirection` option is right", () => {
441-
beforeEach(() => {
440+
it("always opens the file in the left pane when the option is 'right'", async () => {
442441
atom.config.set('find-and-replace.projectSearchResultsPaneSplitDirection', 'right');
443-
});
444-
445-
it("always opens the file in the left pane", () => {
446-
spyOn(atom.workspace, 'open').andCallThrough();
447442
atom.commands.dispatch(resultsView.element, 'core:move-down');
448443
atom.commands.dispatch(resultsView.element, 'core:confirm');
444+
await paneItemOpening()
449445
expect(atom.workspace.open.mostRecentCall.args[1].split).toBe('left');
450446
});
451-
});
452447

453-
describe("when `projectSearchResultsPaneSplitDirection` option is down", () => {
454-
beforeEach(() => {
448+
it("always opens the file in the pane above when the options is 'down'", async () => {
455449
atom.config.set('find-and-replace.projectSearchResultsPaneSplitDirection', 'down')
456-
});
457-
458-
it("always opens the file in the up pane", () => {
459-
spyOn(atom.workspace, 'open').andCallThrough();
460450
atom.commands.dispatch(resultsView.element, 'core:move-down');
461451
atom.commands.dispatch(resultsView.element, 'core:confirm');
452+
await paneItemOpening()
462453
expect(atom.workspace.open.mostRecentCall.args[1].split).toBe('up');
463454
});
464455
});

0 commit comments

Comments
 (0)