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

Commit 3c6a601

Browse files
author
Nathan Sobo
authored
Merge pull request #1091 from atom/ns/fix-flakes
Construct ResultsView directly to fix some flaky tests
2 parents 2b85972 + 485e1cb commit 3c6a601

File tree

2 files changed

+52
-54
lines changed

2 files changed

+52
-54
lines changed

lib/project/results-model.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -387,3 +387,6 @@ module.exports = class ResultsModel {
387387
return pathsPattern.trim().split(',').map((inputPath) => inputPath.trim())
388388
}
389389
}
390+
391+
// Exported for tests
392+
module.exports.Result = Result

spec/results-view-spec.js

Lines changed: 49 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,40 @@ describe('ResultsView', () => {
3535
return getResultsPane().refs.resultsView;
3636
}
3737

38+
function buildResultsView() {
39+
const FindOptions = require("../lib/find-options")
40+
const ResultsModel = require("../lib/project/results-model")
41+
const { Result } = ResultsModel
42+
const ResultsView = require("../lib/project/results-view")
43+
const model = new ResultsModel(new FindOptions({}), null)
44+
const resultsView = new ResultsView({ model })
45+
model.addResult("/a/b.txt", Result.create({
46+
filePath: "/a/b.txt",
47+
matches: [
48+
{
49+
lineText: "hello world",
50+
matchText: "world",
51+
range: {start: {row: 0, column: 6}, end: {row: 0, column: 11}},
52+
leadingContextLines: [],
53+
trailingContextLines: []
54+
}
55+
]
56+
}))
57+
model.addResult("/c/d.txt", Result.create({
58+
filePath: "/c/d.txt",
59+
matches: [
60+
{
61+
lineText: "goodnight moon",
62+
matchText: "night",
63+
range: {start: {row: 0, column: 4}, end: {row: 0, column: 8}},
64+
leadingContextLines: [],
65+
trailingContextLines: []
66+
}
67+
]
68+
}))
69+
return resultsView
70+
}
71+
3872
beforeEach(async () => {
3973
workspaceElement = atom.views.getView(atom.workspace);
4074
workspaceElement.style.height = '1000px';
@@ -649,80 +683,41 @@ describe('ResultsView', () => {
649683
});
650684

651685
describe("copying items with core:copy", () => {
652-
it("copies the selected line onto the clipboard", async () => {
653-
await atom.workspace.open('sample.js');
686+
it("copies the selected line onto the clipboard", () => {
687+
const resultsView = buildResultsView();
654688

655-
projectFindView.findEditor.setText('items');
656-
atom.commands.dispatch(projectFindView.element, 'core:confirm');
657-
await searchPromise;
658-
659-
resultsView = getResultsView();
660-
await resultsView.heightInvalidationPromise;
661689
resultsView.selectFirstResult();
662-
663-
_.times(2, () => atom.commands.dispatch(resultsView.element, 'core:move-down'));
690+
_.times(3, () => atom.commands.dispatch(resultsView.element, 'core:move-down'));
664691
atom.commands.dispatch(resultsView.element, 'core:copy');
665-
expect(atom.clipboard.read()).toBe(' return items if items.length <= 1');
692+
expect(atom.clipboard.read()).toBe('goodnight moon');
666693
});
667694
});
668695

669696
describe("copying path with find-and-replace:copy-path", () => {
670-
it("copies the selected file path to clipboard", async () => {
671-
jasmine.useRealClock()
672-
673-
projectFindView.findEditor.setText('items');
674-
atom.commands.dispatch(projectFindView.element, 'core:confirm');
675-
await searchPromise;
676-
677-
resultsView = getResultsView();
678-
await resultsView.heightInvalidationPromise;
679-
await resultsView.selectFirstResult();
680-
await resultsView.collapseResult();
697+
it("copies the selected file path to clipboard", () => {
698+
const resultsView = buildResultsView();
681699

700+
resultsView.selectFirstResult();
701+
// await resultsView.collapseResult();
682702
atom.commands.dispatch(resultsView.element, 'find-and-replace:copy-path');
683-
expect(atom.clipboard.read()).toBe('sample.coffee');
703+
expect(atom.clipboard.read()).toBe('/a/b.txt');
704+
705+
atom.commands.dispatch(resultsView.element, 'core:move-down');
684706
atom.commands.dispatch(resultsView.element, 'core:move-down');
685707
atom.commands.dispatch(resultsView.element, 'find-and-replace:copy-path');
686-
expect(atom.clipboard.read()).toBe('sample.js');
687-
});
688-
689-
it("copies the selected file path to the clipboard when there are multiple project folders", async () => {
690-
jasmine.useRealClock()
691-
692-
const folder1 = temp.mkdirSync('folder-1')
693-
const file1 = path.join(folder1, 'sample.txt')
694-
fs.writeFileSync(file1, 'items')
695-
696-
const folder2 = temp.mkdirSync('folder-2')
697-
const file2 = path.join(folder2, 'sample.txt')
698-
fs.writeFileSync(file2, 'items')
708+
expect(atom.clipboard.read()).toBe('/c/d.txt');
699709

700-
atom.project.setPaths([folder1, folder2]);
701-
projectFindView.findEditor.setText('items');
702-
atom.commands.dispatch(projectFindView.element, 'core:confirm');
703-
await searchPromise;
704-
705-
resultsView = getResultsView();
706-
await resultsView.heightInvalidationPromise;
707-
resultsView.selectFirstResult();
708-
resultsView.collapseResult();
709-
atom.commands.dispatch(resultsView.element, 'find-and-replace:copy-path');
710-
expect(atom.clipboard.read()).toBe(path.join(path.basename(folder1), path.basename(file1)));
711-
atom.commands.dispatch(resultsView.element, 'core:move-down');
710+
atom.commands.dispatch(resultsView.element, 'core:move-up');
712711
atom.commands.dispatch(resultsView.element, 'find-and-replace:copy-path');
713-
expect(atom.clipboard.read()).toBe(path.join(path.basename(folder2), path.basename(file2)));
712+
expect(atom.clipboard.read()).toBe('/a/b.txt');
714713
});
715714
});
716715

717716
describe("fonts", () => {
718717
it('respect the editor.fontFamily setting', async () => {
719718
atom.config.set('editor.fontFamily', 'Courier');
719+
const resultsView = buildResultsView();
720720

721-
projectFindView.findEditor.setText('items');
722-
atom.commands.dispatch(projectFindView.element, 'core:confirm');
723-
await searchPromise;
724-
725-
resultsView = getResultsView();
726721
await etch.update(resultsView);
727722
expect(resultsView.element.style.fontFamily).toBe('Courier');
728723

0 commit comments

Comments
 (0)