From c58e16cdf8230caa609bfd1dfe416e421a7b7aa7 Mon Sep 17 00:00:00 2001 From: Omar Sadat Date: Mon, 28 Jun 2021 13:04:31 -0400 Subject: [PATCH] Tests: update file-search tests The commit updates the `file-search` api-tests (integration) by testing the following: - verify `fileAndRange` property by default, and once a search is performed. - verify that `splitFilterAndRange` successfully handles different input value combinations. --- examples/api-tests/src/file-search.spec.js | 55 ++++++++++++++++++++++ 1 file changed, 55 insertions(+) diff --git a/examples/api-tests/src/file-search.spec.js b/examples/api-tests/src/file-search.spec.js index 196abe1e59b92..00b01ecb0f8ad 100644 --- a/examples/api-tests/src/file-search.spec.js +++ b/examples/api-tests/src/file-search.spec.js @@ -21,6 +21,7 @@ describe('file-search', function () { const Uri = require('@theia/core/lib/common/uri'); const { QuickFileOpenService } = require('@theia/file-search/lib/browser/quick-file-open'); + const { CancellationTokenSource } = require('@theia/core/lib/common/cancellation'); /** @type {import('inversify').Container} */ const container = window['theia'].container; @@ -60,6 +61,60 @@ describe('file-search', function () { }); + describe('#filterAndRange', () => { + + it('should return the default when not searching', () => { + const filterAndRange = quickFileOpenService['filterAndRange']; + assert.equal(filterAndRange, quickFileOpenService['filterAndRangeDefault']); + }); + + it('should update when searching', () => { + quickFileOpenService['getPicks']('a:2:1', new CancellationTokenSource().token); // perform a mock search. + const filterAndRange = quickFileOpenService['filterAndRange']; + assert.equal(filterAndRange.filter, 'a'); + assert.deepEqual(filterAndRange.range, { start: { line: 1, character: 0 }, end: { line: 1, character: 0 } }); + }); + + }); + + describe('#splitFilterAndRange', () => { + + const expression1 = 'a:2:1'; + const expression2 = 'a:2,1'; + const expression3 = 'a:2#2'; + const expression4 = 'a#2:2'; + const expression5 = 'a#2,1'; + const expression6 = 'a#2#2'; + const expression7 = 'a:2'; + const expression8 = 'a#2'; + + it('should split the filter correctly for different combinations', () => { + assert.equal((quickFileOpenService['splitFilterAndRange'](expression1).filter), 'a'); + assert.equal((quickFileOpenService['splitFilterAndRange'](expression2).filter), 'a'); + assert.equal((quickFileOpenService['splitFilterAndRange'](expression3).filter), 'a'); + assert.equal((quickFileOpenService['splitFilterAndRange'](expression4).filter), 'a'); + assert.equal((quickFileOpenService['splitFilterAndRange'](expression5).filter), 'a'); + assert.equal((quickFileOpenService['splitFilterAndRange'](expression6).filter), 'a'); + assert.equal((quickFileOpenService['splitFilterAndRange'](expression7).filter), 'a'); + assert.equal((quickFileOpenService['splitFilterAndRange'](expression8).filter), 'a'); + }); + + it('should split the range correctly for different combinations', () => { + const rangeTest1 = { start: { line: 1, character: 0 }, end: { line: 1, character: 0 } }; + const rangeTest2 = { start: { line: 1, character: 1 }, end: { line: 1, character: 1 } }; + + assert.deepEqual(quickFileOpenService['splitFilterAndRange'](expression1).range, rangeTest1); + assert.deepEqual(quickFileOpenService['splitFilterAndRange'](expression2).range, rangeTest1); + assert.deepEqual(quickFileOpenService['splitFilterAndRange'](expression3).range, rangeTest2); + assert.deepEqual(quickFileOpenService['splitFilterAndRange'](expression4).range, rangeTest2); + assert.deepEqual(quickFileOpenService['splitFilterAndRange'](expression5).range, rangeTest1); + assert.deepEqual(quickFileOpenService['splitFilterAndRange'](expression6).range, rangeTest2); + assert.deepEqual(quickFileOpenService['splitFilterAndRange'](expression7).range, rangeTest1); + assert.deepEqual(quickFileOpenService['splitFilterAndRange'](expression8).range, rangeTest1); + }); + + }); + }); });