mirror of https://github.com/keeweb/keeweb.git
search tests
This commit is contained in:
parent
9263caed59
commit
52741cf46a
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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;
|
||||
});
|
||||
});
|
Loading…
Reference in New Issue