add more specs to cycle through the context line functions
MODIFY
spec/results-view-spec.js
spec/results-view-spec.js
@@ -697,7 +697,7 @@ describe('ResultsView', () => {
describe('search result context lines', () => {
beforeEach(async () => {
atom.config.set('find-and-replace.searchContextLineCountBefore', 2);
- atom.config.set('find-and-replace.searchContextLineCountAfter', 1);
+ atom.config.set('find-and-replace.searchContextLineCountAfter', 3);
atom.config.set('find-and-replace.leadingContextLineCount', 0);
atom.config.set('find-and-replace.trailingContextLineCount', 0);
@@ -708,70 +708,123 @@ describe('ResultsView', () => {
resultsView = getResultsView();
});
+ function getLineNodesMatchFirstPath(resultsView, matchIndex) {
+ const pathNodes = resultsView.refs.listView.element.querySelectorAll('.path');
+ expect(pathNodes.length).not.toBeLessThan(1);
+ const pathNameNode = pathNodes[0].querySelector('.path-name');
+ expect(pathNameNode.textContent).toBe('sample.coffee');
+ // the second file is sample.js which we don't use
+ expect(pathNodes.length).not.toBeLessThan(matchIndex + 1);
+ const resultNode = pathNodes[matchIndex].querySelector('.search-result');
+ return resultNode.querySelectorAll('.list-item');
+ }
+
it('shows the context lines', async () => {
// the following condition is pretty hacky
// it doesn't work correctly for e.g. version 1.2
if (parseFloat(atom.getVersion()) >= 1.17) {
+ // show no context lines
expect(resultsView.model.getFindOptions().leadingContextLineCount).toBe(0);
expect(resultsView.model.getFindOptions().trailingContextLineCount).toBe(0);
+ {
+ const lineNodes = getLineNodesMatchFirstPath(resultsView, 0);
+ expect(lineNodes.length).toBe(1);
+ expect(lineNodes[0]).toHaveClass('match-line');
+ expect(lineNodes[0].querySelector('.preview').textContent).toBe('sort: (items) ->');
+ }
+
+ // show all leading context lines, show 1 trailing context line
await resultsView.toggleLeadingContextLines();
+ await resultsView.incrementTrailingContextLines();
expect(resultsView.model.getFindOptions().leadingContextLineCount).toBe(2);
- expect(resultsView.model.getFindOptions().trailingContextLineCount).toBe(0);
+ expect(resultsView.model.getFindOptions().trailingContextLineCount).toBe(1);
{
- const pathNodes = resultsView.refs.listView.element.querySelectorAll('.path');
- expect(pathNodes.length).toBe(2);
- const pathNameNode = pathNodes[0].querySelector('.path-name');
- expect(pathNameNode.textContent).toBe('sample.coffee');
- // the second file is sample.js which we don't use
- const resultNode = pathNodes[0].querySelector('.search-result');
- const lineNodes = resultNode.querySelectorAll('.list-item');
- expect(lineNodes.length).toBe(2);
+ const lineNodes = getLineNodesMatchFirstPath(resultsView, 0);
+ expect(lineNodes.length).toBe(3);
expect(lineNodes[0]).not.toHaveClass('match-line');
expect(lineNodes[0].querySelector('.preview').textContent).toBe('class quicksort');
expect(lineNodes[1]).toHaveClass('match-line');
expect(lineNodes[1].querySelector('.preview').textContent).toBe('sort: (items) ->');
+ expect(lineNodes[2]).not.toHaveClass('match-line');
+ expect(lineNodes[2].querySelector('.preview').textContent).toBe('return items if items.length <= 1');
}
- await resultsView.toggleTrailingContextLines();
- expect(resultsView.model.getFindOptions().leadingContextLineCount).toBe(2);
- expect(resultsView.model.getFindOptions().trailingContextLineCount).toBe(1);
+ // show 1 leading context line, show 2 trailing context lines
+ await resultsView.decrementLeadingContextLines();
+ await resultsView.incrementTrailingContextLines();
+ expect(resultsView.model.getFindOptions().leadingContextLineCount).toBe(1);
+ expect(resultsView.model.getFindOptions().trailingContextLineCount).toBe(2);
{
- const pathNodes = resultsView.refs.listView.element.querySelectorAll('.path');
- expect(pathNodes.length).toBe(2);
- const pathNameNode = pathNodes[0].querySelector('.path-name');
- expect(pathNameNode.textContent).toBe('sample.coffee');
- // the second file is sample.js which we don't use
- const resultNode = pathNodes[0].querySelector('.search-result');
- const lineNodes = resultNode.querySelectorAll('.list-item');
- expect(lineNodes.length).toBe(3);
+ const lineNodes = getLineNodesMatchFirstPath(resultsView, 0);
+ expect(lineNodes.length).toBe(4);
expect(lineNodes[0]).not.toHaveClass('match-line');
expect(lineNodes[0].querySelector('.preview').textContent).toBe('class quicksort');
expect(lineNodes[1]).toHaveClass('match-line');
expect(lineNodes[1].querySelector('.preview').textContent).toBe('sort: (items) ->');
expect(lineNodes[2]).not.toHaveClass('match-line');
expect(lineNodes[2].querySelector('.preview').textContent).toBe('return items if items.length <= 1');
+ expect(lineNodes[3]).not.toHaveClass('match-line');
+ expect(lineNodes[3].querySelector('.preview').textContent).toBe('');
+ // expect(lineNodes[4]).not.toHaveClass('match-line');
+ // expect(lineNodes[4].querySelector('.preview').textContent).toBe('pivot = items.shift()');
}
- }
- });
- it('hides the context lines', async () => {
- // the following condition is pretty hacky
- // it doesn't work correctly for e.g. version 1.2
- if (parseFloat(atom.getVersion()) >= 1.17) {
+ // show no leading context lines, show 3 trailing context lines
+ await resultsView.decrementLeadingContextLines();
+ await resultsView.incrementTrailingContextLines();
expect(resultsView.model.getFindOptions().leadingContextLineCount).toBe(0);
- expect(resultsView.model.getFindOptions().trailingContextLineCount).toBe(0);
- const pathNodes = resultsView.refs.listView.element.querySelectorAll('.path');
- expect(pathNodes.length).toBe(2);
- let pathNameNode = pathNodes[0].querySelector('.path-name');
- expect(pathNameNode.textContent).toBe('sample.coffee');
- // the second file is sample.js which we don't use
- const resultNode = pathNodes[0].querySelector('.search-result');
- const lineNodes = resultNode.querySelectorAll('.list-item');
- expect(lineNodes.length).toBe(1);
+ expect(resultsView.model.getFindOptions().trailingContextLineCount).toBe(3);
+
+ {
+ const lineNodes = getLineNodesMatchFirstPath(resultsView, 0);
+ expect(lineNodes.length).toBe(4);
expect(lineNodes[0]).toHaveClass('match-line');
expect(lineNodes[0].querySelector('.preview').textContent).toBe('sort: (items) ->');
+ expect(lineNodes[1]).not.toHaveClass('match-line');
+ expect(lineNodes[1].querySelector('.preview').textContent).toBe('return items if items.length <= 1');
+ expect(lineNodes[2]).not.toHaveClass('match-line');
+ expect(lineNodes[2].querySelector('.preview').textContent).toBe('');
+ expect(lineNodes[3]).not.toHaveClass('match-line');
+ expect(lineNodes[3].querySelector('.preview').textContent).toBe('pivot = items.shift()');
+ }
+
+ // show 1 leading context line, show 2 trailing context lines
+ await resultsView.incrementLeadingContextLines();
+ await resultsView.decrementTrailingContextLines();
+ expect(resultsView.model.getFindOptions().leadingContextLineCount).toBe(1);
+ expect(resultsView.model.getFindOptions().trailingContextLineCount).toBe(2);
+
+ {
+ const lineNodes = getLineNodesMatchFirstPath(resultsView, 0);
+ expect(lineNodes.length).toBe(4);
+ expect(lineNodes[0]).not.toHaveClass('match-line');
+ expect(lineNodes[0].querySelector('.preview').textContent).toBe('class quicksort');
+ expect(lineNodes[1]).toHaveClass('match-line');
+ expect(lineNodes[1].querySelector('.preview').textContent).toBe('sort: (items) ->');
+ expect(lineNodes[2]).not.toHaveClass('match-line');
+ expect(lineNodes[2].querySelector('.preview').textContent).toBe('return items if items.length <= 1');
+ expect(lineNodes[3]).not.toHaveClass('match-line');
+ expect(lineNodes[3].querySelector('.preview').textContent).toBe('');
+ }
+
+ // show 1 leading context line, show 2 trailing context lines
+ await resultsView.incrementTrailingContextLines();
+ expect(resultsView.model.getFindOptions().trailingContextLineCount).toBe(3);
+ await resultsView.incrementLeadingContextLines();
+ await resultsView.toggleTrailingContextLines();
+ expect(resultsView.model.getFindOptions().leadingContextLineCount).toBe(2);
+ expect(resultsView.model.getFindOptions().trailingContextLineCount).toBe(0);
+
+ {
+ const lineNodes = getLineNodesMatchFirstPath(resultsView, 0);
+ expect(lineNodes.length).toBe(2);
+ expect(lineNodes[0]).not.toHaveClass('match-line');
+ expect(lineNodes[0].querySelector('.preview').textContent).toBe('class quicksort');
+ expect(lineNodes[1]).toHaveClass('match-line');
+ expect(lineNodes[1].querySelector('.preview').textContent).toBe('sort: (items) ->');
+ }
}
});
})

add more specs to cycle through the context line functions