Skip to content
This repository has been archived by the owner on Jan 9, 2023. It is now read-only.

Fix search 1438 #1451

Merged
merged 4 commits into from
Jul 17, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions app/adapters/application.js
Original file line number Diff line number Diff line change
Expand Up @@ -94,15 +94,21 @@ export default Adapter.extend(CheckForErrors, {
let recordTypeName = this.getRecordTypeName(type);
let queryParams = {
selector: {
$or: []
$and: [{}, { $or: [] }]
}
};
// filter to only retrieve the specified type of record. relational-pouch may eventually provide
// a better way to do this and allow this workaround to be removed
queryParams.selector.$and[0]._id = {
'$gt': db.rel.makeDocID({ type: recordTypeName }),
'$lt': db.rel.makeDocID({ type: recordTypeName, id: {} })
};
if (query.containsValue && query.containsValue.value) {
let regexp = new RegExp(query.containsValue.value, 'i');
query.containsValue.keys.forEach((key) => {
let subQuery = {};
subQuery[`data.${key.name}`] = { $regex: regexp };
queryParams.selector.$or.push(subQuery);
queryParams.selector.$and[1].$or.push(subQuery);
});
}

Expand Down
13 changes: 9 additions & 4 deletions tests/acceptance/pricing-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ test('Searching pricing', function(assert) {
await fillIn('[role="search"] div input', 'Xray Hand');
await click('.glyphicon-search');
assert.equal(currentURL(), '/pricing/search/Xray%20Hand', 'Searched for Name: Xray Hand');
assert.equal(find('button:contains(Delete)').length, 3, 'There are 3 search items');
assert.equal(find('button:contains(Delete)').length, 1, 'There is one search item');

await fillIn('[role="search"] div input', 'Blood');
await click('.glyphicon-search');
Expand All @@ -184,17 +184,22 @@ test('Searching pricing', function(assert) {
await fillIn('[role="search"] div input', 'Leg');
await click('.glyphicon-search');
assert.equal(currentURL(), '/pricing/search/Leg', 'Searched for Name: Leg');
assert.equal(find('button:contains(Delete)').length, 2, 'There are 2 search items');
assert.equal(find('button:contains(Delete)').length, 1, 'There is one search item');

await fillIn('[role="search"] div input', 'Gauze');
await click('.glyphicon-search');
assert.equal(currentURL(), '/pricing/search/Gauze', 'Searched for Name: Gauze');
assert.equal(find('button:contains(Delete)').length, 2, 'There are 2 search items');
assert.equal(find('button:contains(Delete)').length, 1, 'There is one search item');

await fillIn('[role="search"] div input', 'xray');
await click('.glyphicon-search');
assert.equal(currentURL(), '/pricing/search/xray', 'Searched for all lower case xray');
assert.equal(find('button:contains(Delete)').length, 3, 'There is one search item');
assert.equal(find('button:contains(Delete)').length, 1, 'There is one search item');

await fillIn('[role="search"] div input', 'd');
await click('.glyphicon-search');
assert.equal(currentURL(), '/pricing/search/d', 'Searched for the letter d');
assert.equal(find('button:contains(Delete)').length, 3, 'There are three search items');

await fillIn('[role="search"] div input', 'ItemNotFound');
await click('.glyphicon-search');
Expand Down