Skip to content

Commit

Permalink
Tests: update file-search tests
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
OmarSdt-EC committed Jul 26, 2021
1 parent 33dea9b commit c58e16c
Showing 1 changed file with 55 additions and 0 deletions.
55 changes: 55 additions & 0 deletions examples/api-tests/src/file-search.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
});

});

});

});

0 comments on commit c58e16c

Please sign in to comment.