search tests

This commit is contained in:
antelle 2020-05-05 16:23:17 +02:00
parent 9263caed59
commit 52741cf46a
No known key found for this signature in database
GPG Key ID: 094A2F2D6136A4EE
2 changed files with 42 additions and 2 deletions

View File

@ -22,12 +22,12 @@ class EntrySearch {
} else if (filter.textLowerParts) {
const parts = filter.textLowerParts;
for (let i = 0; i < parts.length; i++) {
if (this.model.searchText && this.model.searchText.indexOf(parts[i]) < 0) {
if (this.model.searchText.indexOf(parts[i]) < 0) {
return false;
}
}
} else {
if (this.model.searchText && this.model.searchText.indexOf(filter.textLower) < 0) {
if (this.model.searchText.indexOf(filter.textLower) < 0) {
return false;
}
}

View File

@ -0,0 +1,40 @@
import { expect } from 'chai';
import { EntrySearch } from 'util/entry-search';
describe('EntrySearch', () => {
it('should match an empty filter', () => {
const search = new EntrySearch({ searchText: '' });
expect(search.matches()).to.be.true;
});
it('should not match an empty entry', () => {
const search = new EntrySearch({ searchText: '' });
expect(search.matches({ textLower: 'test' })).to.be.false;
});
it('should match a simple string', () => {
const search = new EntrySearch({ searchText: 'some test' });
expect(search.matches({ textLower: 'test' })).to.be.true;
});
it('should not match a non-existing string', () => {
const search = new EntrySearch({ searchText: 'some test' });
expect(search.matches({ textLower: 'something' })).to.be.false;
});
it('should match text parts', () => {
const search = new EntrySearch({ searchText: 'some test' });
expect(
search.matches({
textLower: 'some test',
textLowerParts: ['some', 'test']
})
).to.be.true;
expect(
search.matches({
textLower: 'test some',
textLowerParts: ['test', 'some']
})
).to.be.true;
});
});