Commit 7e55e22a authored by Eduardo Sanz García's avatar Eduardo Sanz García Committed by Eduardo

Improved test to cover default parameters

Both `SearchClient` and `load-annotations::load` had the same default
parameters. We have decided to leave the default parameters only in one
place instead of two.

This more specific test proves that removing the default parameters in
`load-annoationas::load` still uses the default parameters in the
`SearchClient`.
parent 3675cea5
...@@ -89,8 +89,8 @@ export default function loadAnnotationsService( ...@@ -89,8 +89,8 @@ export default function loadAnnotationsService(
const searchOptions = { const searchOptions = {
incremental: true, incremental: true,
maxResults,
separateReplies: false, separateReplies: false,
maxResults,
// Annotations are fetched in order of creation by default. This is expected // Annotations are fetched in order of creation by default. This is expected
// to roughly correspond to the order in which threads end up being sorted // to roughly correspond to the order in which threads end up being sorted
......
...@@ -7,7 +7,13 @@ let longRunningSearchClient = false; ...@@ -7,7 +7,13 @@ let longRunningSearchClient = false;
class FakeSearchClient extends EventEmitter { class FakeSearchClient extends EventEmitter {
constructor( constructor(
searchFn, searchFn,
{ incremental, separateReplies, sortBy = 'created', sortOrder = 'asc' } {
incremental,
separateReplies,
sortBy = 'created',
sortOrder = 'asc',
maxResults = null,
}
) { ) {
super(); super();
...@@ -18,6 +24,7 @@ class FakeSearchClient extends EventEmitter { ...@@ -18,6 +24,7 @@ class FakeSearchClient extends EventEmitter {
this.separateReplies = !!separateReplies; this.separateReplies = !!separateReplies;
this.sortBy = sortBy; this.sortBy = sortBy;
this.sortOrder = sortOrder; this.sortOrder = sortOrder;
this.maxResults = maxResults;
this.get = sinon.spy(query => { this.get = sinon.spy(query => {
if (!query.uri) { if (!query.uri) {
...@@ -257,16 +264,29 @@ describe('loadAnnotationsService', () => { ...@@ -257,16 +264,29 @@ describe('loadAnnotationsService', () => {
assert.isFalse(searchClients[0].separateReplies); assert.isFalse(searchClients[0].separateReplies);
}); });
it('loads annotations with default sort order', () => { it('search annotations with default SearchClient parameters', () => {
const svc = createService(); const svc = createService();
svc.load({ groupId: fakeGroupId, uris: fakeUris }); svc.load({ groupId: fakeGroupId, uris: fakeUris });
assert.equal(searchClients[0].sortBy, 'created'); assert.equal(searchClients[0].sortBy, 'created');
assert.equal(searchClients[0].sortOrder, 'asc'); assert.equal(searchClients[0].sortOrder, 'asc');
assert.equal(searchClients[0].maxResults, null);
svc.load({
groupId: fakeGroupId,
uris: fakeUris,
sortBy: undefined,
sortOrder: undefined,
maxResults: undefined,
});
assert.equal(searchClients[1].sortBy, 'created');
assert.equal(searchClients[1].sortOrder, 'asc');
assert.equal(searchClients[1].maxResults, null);
}); });
it('loads annotations with custom sort order', () => { it('search annotations with custom SearchClient parameters', () => {
const svc = createService(); const svc = createService();
svc.load({ svc.load({
...@@ -274,10 +294,12 @@ describe('loadAnnotationsService', () => { ...@@ -274,10 +294,12 @@ describe('loadAnnotationsService', () => {
uris: fakeUris, uris: fakeUris,
sortBy: 'updated', sortBy: 'updated',
sortOrder: 'desc', sortOrder: 'desc',
maxResults: 50,
}); });
assert.equal(searchClients[0].sortBy, 'updated'); assert.equal(searchClients[0].sortBy, 'updated');
assert.equal(searchClients[0].sortOrder, 'desc'); assert.equal(searchClients[0].sortOrder, 'desc');
assert.equal(searchClients[0].maxResults, 50);
}); });
it("cancels previously search client if it's still running", () => { it("cancels previously search client if it's still running", () => {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment