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

Commit 6e116d1

Browse files
committed
Sync open-files-find-view-spec with changes to project-find-view-spec
1 parent 5840cf7 commit 6e116d1

File tree

2 files changed

+71
-44
lines changed

2 files changed

+71
-44
lines changed

spec/open-files-find-view-spec.js

Lines changed: 69 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
11
/** @babel */
22

3-
const os = require('os');
43
const path = require('path');
5-
const temp = require('temp');
4+
const temp = require('temp').track();
65
const fs = require('fs-plus');
76
const {TextBuffer} = require('atom');
87
const {PathReplacer, PathSearcher} = require('scandal');
@@ -34,17 +33,17 @@ describe('OpenFilesFindView', () => {
3433
return getExistingResultsPane().refs.resultsView;
3534
}
3635

37-
beforeEach(async () => {
36+
beforeEach(() => {
3837
pathSearcher = new PathSearcher();
3938
workspaceElement = atom.views.getView(atom.workspace);
4039
atom.config.set('core.excludeVcsIgnoredPaths', false);
4140
atom.project.setPaths([path.join(__dirname, 'fixtures')]);
42-
await atom.workspace.open(path.join(__dirname, 'fixtures', 'one-long-line.coffee'));
43-
await atom.workspace.open(path.join(__dirname, 'fixtures', 'sample.js'));
4441
jasmine.attachToDOM(workspaceElement);
4542

46-
activationPromise = atom.packages.activatePackage("find-and-replace").then(function({mainModule}) {
43+
activationPromise = atom.packages.activatePackage("find-and-replace").then(async function({mainModule}) {
4744
mainModule.createViews();
45+
await atom.workspace.open(path.join(__dirname, 'fixtures', 'one-long-line.coffee'));
46+
await atom.workspace.open(path.join(__dirname, 'fixtures', 'sample.js'));
4847
({findView, openFilesFindView} = mainModule);
4948
const spy = spyOn(openFilesFindView, 'search').andCallFake((options) => {
5049
return searchPromise = spy.originalValue.call(openFilesFindView, options);
@@ -53,7 +52,7 @@ describe('OpenFilesFindView', () => {
5352
});
5453

5554
describe("when open-files-find:show is triggered", () => {
56-
it("attaches openFilesFindView to the root view", async () => {
55+
it("attaches OpenFilesFindView to the root view", async () => {
5756
atom.commands.dispatch(workspaceElement, 'open-files-find:show');
5857
await activationPromise;
5958

@@ -147,6 +146,7 @@ describe('OpenFilesFindView', () => {
147146
beforeEach(async () => {
148147
editor = await atom.workspace.open('sample.js');
149148
editorElement = atom.views.getView(editor);
149+
await atom.workspace.open('sample.coffee');
150150
atom.commands.dispatch(workspaceElement, 'open-files-find:show');
151151
await activationPromise;
152152
workspaceElement.style.height = '800px'
@@ -156,7 +156,6 @@ describe('OpenFilesFindView', () => {
156156
beforeEach(async () => {
157157
let projectPath = temp.mkdirSync("atom");
158158
fs.writeFileSync(path.join(projectPath, "tabs.txt"), "\t\n\\\t\n\\\\t");
159-
await atom.workspace.open(path.join(projectPath, "tabs.txt"));
160159
atom.project.setPaths([projectPath]);
161160
atom.commands.dispatch(workspaceElement, 'open-files-find:show');
162161
});
@@ -172,7 +171,7 @@ describe('OpenFilesFindView', () => {
172171
const resultsView = getResultsView();
173172
await resultsView.heightInvalidationPromise
174173
expect(resultsView.element).toBeVisible();
175-
expect(resultsView.refs.listView.element.querySelectorAll(".search-result")).toHaveLength(2);
174+
expect(resultsView.refs.listView.element.querySelectorAll(".match-row")).toHaveLength(2);
176175
})
177176
});
178177

@@ -186,7 +185,7 @@ describe('OpenFilesFindView', () => {
186185
const resultsView = getResultsView();
187186
await resultsView.heightInvalidationPromise
188187
expect(resultsView.element).toBeVisible();
189-
expect(resultsView.refs.listView.element.querySelectorAll(".search-result")).toHaveLength(1);
188+
expect(resultsView.refs.listView.element.querySelectorAll(".match-row")).toHaveLength(1);
190189
});
191190

192191
it("finds a backslash", async () => {
@@ -198,7 +197,8 @@ describe('OpenFilesFindView', () => {
198197
const resultsView = getResultsView();
199198
await resultsView.heightInvalidationPromise
200199
expect(resultsView.element).toBeVisible();
201-
expect(resultsView.refs.listView.element.querySelectorAll(".search-result")).toHaveLength(3);
200+
expect(resultsView.refs.listView.element.querySelectorAll(".match-row")).toHaveLength(2);
201+
expect(resultsView.refs.listView.element.querySelectorAll(".match.highlight-info")).toHaveLength(3);
202202
});
203203

204204
it("doesn't insert a escaped char if there are multiple backslashs in front of the char", async () => {
@@ -210,7 +210,7 @@ describe('OpenFilesFindView', () => {
210210
const resultsView = getResultsView();
211211
await resultsView.heightInvalidationPromise
212212
expect(resultsView.element).toBeVisible();
213-
expect(resultsView.refs.listView.element.querySelectorAll(".search-result")).toHaveLength(1);
213+
expect(resultsView.refs.listView.element.querySelectorAll(".match-row")).toHaveLength(1);
214214
});
215215
});
216216
});
@@ -297,7 +297,7 @@ describe('OpenFilesFindView', () => {
297297
});
298298

299299
it("does not split when option is false", async () => {
300-
const initialPane = atom.workspace.getActivePane();
300+
const initialPane = atom.workspace.getCenter().getActivePane();
301301
openFilesFindView.findEditor.setText('items');
302302

303303
atom.commands.dispatch(openFilesFindView.element, 'core:confirm');
@@ -314,20 +314,23 @@ describe('OpenFilesFindView', () => {
314314
await searchPromise;
315315

316316
const resultsPaneView1 = atom.views.getView(getExistingResultsPane());
317-
const pane1 = atom.workspace.getActivePane();
317+
const pane1 = atom.workspace.getCenter().getActivePane();
318318
const resultsView1 = pane1.getItems()[0].refs.resultsView
319319
pane1.splitRight({copyActiveItem: true});
320320

321-
const pane2 = atom.workspace.getActivePane();
321+
const pane2 = atom.workspace.getCenter().getActivePane();
322322
const resultsView2 = pane2.getItems()[0].refs.resultsView
323323
const resultsPaneView2 = atom.views.getView(pane2.itemForURI(ResultsPaneView.URI));
324324
expect(pane1).not.toBe(pane2);
325325
expect(resultsPaneView1).not.toBe(resultsPaneView2);
326326
simulateResizeEvent(resultsView2.element);
327327

328-
const {length: resultCount} = resultsPaneView1.querySelectorAll('.search-result');
328+
await etch.update(resultsView1);
329+
await etch.update(resultsView2);
330+
331+
const resultCount = resultsPaneView1.querySelectorAll('.match-row').length;
329332
expect(resultCount).toBeGreaterThan(0);
330-
expect(resultsPaneView2.querySelectorAll('.search-result')).toHaveLength(resultCount);
333+
expect(resultsPaneView2.querySelectorAll('.match-row')).toHaveLength(resultCount);
331334
expect(resultsPaneView2.querySelector('.preview-count').innerHTML).toEqual(resultsPaneView1.querySelector('.preview-count').innerHTML);
332335
});
333336

@@ -339,21 +342,25 @@ describe('OpenFilesFindView', () => {
339342
await searchPromise;
340343

341344
const resultsPaneView1 = atom.views.getView(getExistingResultsPane());
342-
const pane1 = atom.workspace.getActivePane();
345+
const pane1 = atom.workspace.getCenter().getActivePane();
343346
const resultsView1 = pane1.getItems()[0].refs.resultsView
344347

345348
pane1.splitDown({copyActiveItem: true});
346-
const pane2 = atom.workspace.getActivePane();
349+
const pane2 = atom.workspace.getCenter().getActivePane();
347350
const resultsView2 = pane2.getItems()[0].refs.resultsView
348351
const resultsPaneView2 = atom.views.getView(pane2.itemForURI(ResultsPaneView.URI));
349352
expect(pane1).not.toBe(pane2);
350353
expect(resultsPaneView1).not.toBe(resultsPaneView2);
354+
355+
await etch.update(resultsView1);
356+
await etch.update(resultsView2);
357+
351358
expect(resultsPaneView2.querySelector('.preview-count').innerHTML).toEqual(resultsPaneView1.querySelector('.preview-count').innerHTML);
352359
});
353360
});
354361

355362
describe("serialization", () => {
356-
it("serializes if the case, regex and whole word options", async () => {
363+
it("serializes the case, regex and whole word options", async () => {
357364
atom.commands.dispatch(editorElement, 'open-files-find:show');
358365
expect(openFilesFindView.refs.caseOptionButton).not.toHaveClass('selected');
359366
openFilesFindView.refs.caseOptionButton.click();
@@ -398,13 +405,14 @@ describe('OpenFilesFindView', () => {
398405

399406
await searchPromise;
400407

408+
// Would not expect these assertions to pass without first opening 2 files
401409
expect(openFilesFindView.refs.descriptionLabel.textContent).toContain('13 results found in 2 open files');
402410
atom.commands.dispatch(openFilesFindView.element, 'core:confirm');
403411
expect(openFilesFindView.refs.descriptionLabel.textContent).toContain('13 results found in 2 open files');
404412
});
405413

406414
it("shows an error when the pattern is invalid and clears when no error", async () => {
407-
spyOn(pathSearcher, 'searchPaths').andReturn(Promise.resolve()); // TODO: Remove?
415+
spyOn(pathSearcher, 'searchPaths').andReturn(Promise.resolve());
408416
atom.commands.dispatch(openFilesFindView.element, 'open-files-find:toggle-regex-option');
409417
openFilesFindView.findEditor.setText('[');
410418
atom.commands.dispatch(openFilesFindView.element, 'core:confirm');
@@ -501,7 +509,7 @@ describe('OpenFilesFindView', () => {
501509
await searchPromise;
502510
});
503511

504-
it("runs a case insensitive search by default", () => expect(String(PathSearcher.searchPaths.argsForCall[0][0])).toEqual(String(/ITEMS/gi)));
512+
it("runs a case insensitive search by default", () => expect(PathSearcher.searchPaths.argsForCall[0][0]).toEqual(/ITEMS/gi));
505513

506514
it("toggles case sensitive option via an event and finds files matching the pattern", async () => {
507515
expect(openFilesFindView.refs.caseOptionButton).not.toHaveClass('selected');
@@ -568,7 +576,8 @@ describe('OpenFilesFindView', () => {
568576
const resultsView = getResultsView();
569577
await resultsView.heightInvalidationPromise
570578
expect(resultsView.element).toBeVisible();
571-
expect(resultsView.refs.listView.element.querySelectorAll(".search-result")).toHaveLength(13);
579+
expect(resultsView.refs.listView.element.querySelectorAll(".match-row")).toHaveLength(11);
580+
expect(resultsView.refs.listView.element.querySelectorAll(".match.highlight-info")).toHaveLength(13);
572581
})
573582
});
574583

@@ -577,8 +586,8 @@ describe('OpenFilesFindView', () => {
577586
atom.commands.dispatch(workspaceElement, 'open-files-find:show')
578587
});
579588

580-
describe("when the there search field is empty", () => {
581-
it("does not run the seach but clears the model", () => {
589+
describe("when the search field is empty", () => {
590+
it("does not run the search but clears the model", () => {
582591
spyOn(pathSearcher, 'searchPaths');
583592
spyOn(openFilesFindView.model, 'clear');
584593
atom.commands.dispatch(openFilesFindView.element, 'core:confirm');
@@ -628,37 +637,50 @@ describe('OpenFilesFindView', () => {
628637

629638
await resultsView.heightInvalidationPromise
630639
expect(resultsView.element).toBeVisible();
631-
expect(resultsView.refs.listView.element.querySelectorAll(".search-result")).toHaveLength(13);
640+
expect(resultsView.refs.listView.element.querySelectorAll(".match-row")).toHaveLength(11);
641+
expect(resultsView.refs.listView.element.querySelectorAll(".match.highlight-info")).toHaveLength(13);
632642

633643
expect(resultsPaneView.refs.previewCount.textContent).toBe("13 results found in 2 files for items");
634-
expect(openFilesFindView.errorMessages).not.toBeVisible();
644+
expect(projectFindView.errorMessages).not.toBeVisible();
635645
});
636646

637647
it("updates the results list when a buffer changes", async () => {
638-
const buffer = atom.project.bufferForPathSync('sample.js');
648+
const editor = await atom.workspace.open('sample.js')
639649

640650
atom.commands.dispatch(openFilesFindView.element, 'core:confirm');
641651
await searchPromise;
642652

643653
const resultsView = getResultsView();
654+
const listView = resultsView.refs.listView;
644655
const resultsPaneView = getExistingResultsPane();
645656

646657
await resultsView.heightInvalidationPromise
647-
expect(resultsView.refs.listView.element.querySelectorAll(".search-result")).toHaveLength(13);
658+
expect(listView.element.querySelectorAll(".match-row")).toHaveLength(11);
659+
expect(listView.element.querySelectorAll(".match.highlight-info")).toHaveLength(13);
660+
// This assertion should fail until 2 files are open
648661
expect(resultsPaneView.refs.previewCount.textContent).toBe("13 results found in 2 files for items");
649662

650663
resultsView.selectFirstResult();
651-
for (let i = 0; i < 7; i++) await resultsView.moveDown()
652-
expect(resultsView.refs.listView.element.querySelectorAll(".path")[1]).toHaveClass('selected');
664+
for (let i = 0; i < 6; i++) resultsView.moveDown();
665+
await resultsView.moveDown();
666+
667+
expect(listView.element.querySelectorAll(".path-row")[1].parentElement).toHaveClass('selected');
653668

654-
buffer.setText('there is one "items" in this file');
655-
advanceClock(buffer.stoppedChangingDelay);
669+
editor.setText('there is one "items" in this file');
670+
advanceClock(editor.getBuffer().stoppedChangingDelay);
656671
await etch.getScheduler().getNextUpdatePromise()
672+
// This assertion should fail until 2 files are open
657673
expect(resultsPaneView.refs.previewCount.textContent).toBe("8 results found in 2 files for items");
658-
expect(resultsView.refs.listView.element.querySelectorAll(".path")[1]).toHaveClass('selected');
674+
expect(listView.element.querySelectorAll(".path-row")[1].parentElement).toHaveClass('selected');
675+
676+
// Ensure the newly added item can be opened.
677+
await resultsView.moveDown()
678+
atom.commands.dispatch(resultsView.element, 'core:confirm');
679+
await new Promise(resolve => editor.onDidChangeSelectionRange(resolve));
680+
expect(editor.getSelectedText()).toBe("items")
659681

660-
buffer.setText('no matches in this file');
661-
advanceClock(buffer.stoppedChangingDelay);
682+
editor.setText('no matches in this file');
683+
advanceClock(editor.getBuffer().stoppedChangingDelay);
662684
await etch.getScheduler().getNextUpdatePromise()
663685
expect(resultsPaneView.refs.previewCount.textContent).toBe("7 results found in 1 file for items");
664686
});
@@ -677,7 +699,7 @@ describe('OpenFilesFindView', () => {
677699
const resultsView = getResultsView();
678700
expect(openFilesFindView.refs.errorMessages).not.toBeVisible();
679701
expect(resultsView.element).toBeVisible();
680-
expect(resultsView.refs.listView.element.querySelectorAll(".search-result")).toHaveLength(0);
702+
expect(resultsView.refs.listView.element.querySelectorAll(".match-row")).toHaveLength(0);
681703
});
682704
});
683705
});
@@ -775,10 +797,12 @@ describe('OpenFilesFindView', () => {
775797
expect(errorList.querySelectorAll("li")).toHaveLength(0);
776798

777799
callback(null, {path: '/some/path.js', code: 'ENOENT', message: 'Nope'});
800+
await etch.update(resultsPaneView);
778801
expect(errorList).toBeVisible();
779802
expect(errorList.querySelectorAll("li")).toHaveLength(1);
780803

781804
callback(null, {path: '/some/path.js', code: 'ENOENT', message: 'Broken'});
805+
await etch.update(resultsPaneView);
782806
expect(errorList.querySelectorAll("li")).toHaveLength(2);
783807
});
784808

@@ -870,11 +894,14 @@ describe('OpenFilesFindView', () => {
870894

871895
const resultsView = getResultsView();
872896
resultsView.scrollToBottom(); // To load ALL the results
897+
await etch.update(resultsView);
873898
expect(resultsView.element).toBeVisible();
874-
expect(resultsView.refs.listView.element.querySelectorAll(".search-result")).toHaveLength(13);
899+
expect(resultsView.refs.listView.element.querySelectorAll(".match-row")).toHaveLength(11);
900+
expect(resultsView.refs.listView.element.querySelectorAll(".match.highlight-info")).toHaveLength(13);
875901

876902
resultsView.selectFirstResult();
877-
for (let i = 0; i < 10; i++) await resultsView.moveDown();
903+
for (let i = 0; i < 9; i++) resultsView.moveDown();
904+
await resultsView.moveDown();
878905

879906
atom.commands.dispatch(resultsView.element, 'core:confirm');
880907
await new Promise(resolve => editor.onDidChangeSelectionRange(resolve))
@@ -904,12 +931,12 @@ describe('OpenFilesFindView', () => {
904931
});
905932
});
906933

907-
describe("replacing", () => {
934+
xdescribe("replacing", () => {
908935
let testDir, sampleJs, sampleCoffee, replacePromise;
909936

910937
beforeEach(async () => {
911938
pathReplacer = new PathReplacer();
912-
testDir = path.join(os.tmpdir(), "atom-find-and-replace");
939+
testDir = temp.mkdirSync('atom-find-and-replace');
913940
sampleJs = path.join(testDir, 'sample.js');
914941
sampleCoffee = path.join(testDir, 'sample.coffee');
915942

@@ -1192,7 +1219,7 @@ describe('OpenFilesFindView', () => {
11921219

11931220
const resultsView = getResultsView();
11941221
expect(resultsView.element).toBeVisible();
1195-
expect(resultsView.refs.listView.element.querySelectorAll(".search-result")).toHaveLength(0);
1222+
expect(resultsView.refs.listView.element.querySelectorAll(".match-row")).toHaveLength(0);
11961223

11971224
expect(openFilesFindView.refs.descriptionLabel.textContent).toContain("Replaced items with sunshine 13 times in 2 open files");
11981225

spec/project-find-view-spec.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -483,7 +483,7 @@ describe('ProjectFindView', () => {
483483
});
484484

485485
describe("serialization", () => {
486-
it("serializes if the case, regex and whole word options", async () => {
486+
it("serializes the case, regex and whole word options", async () => {
487487
atom.commands.dispatch(editorElement, 'project-find:show');
488488
expect(projectFindView.refs.caseOptionButton).not.toHaveClass('selected');
489489
projectFindView.refs.caseOptionButton.click();
@@ -708,7 +708,7 @@ describe('ProjectFindView', () => {
708708
atom.commands.dispatch(workspaceElement, 'project-find:show')
709709
});
710710

711-
describe("when the there search field is empty", () => {
711+
describe("when the search field is empty", () => {
712712
it("does not run the search but clears the model", () => {
713713
spyOn(atom.workspace, 'scan');
714714
spyOn(projectFindView.model, 'clear');

0 commit comments

Comments
 (0)