diff --git a/src/store/__test__/main.spec.ts b/src/store/__test__/main.spec.ts index ff4d0492..77d30f3a 100644 --- a/src/store/__test__/main.spec.ts +++ b/src/store/__test__/main.spec.ts @@ -1,6 +1,7 @@ import { toJS } from 'mobx'; import sinon from 'sinon'; import moment from 'moment'; +import { waitFor } from '@testing-library/react'; import { people } from '../../__test__/__mockData__/persons'; import { user } from '../../__test__/__mockData__/user'; import { MeInfo, emptyMeInfo, uiStore } from '../ui'; @@ -1146,6 +1147,7 @@ describe('Main store', () => { ); expect(res).toBeTruthy(); }); + it('should accept search query and return results based on query ', async () => { const store = new MainStore(); @@ -1178,10 +1180,12 @@ describe('Main store', () => { await store.getPeopleBounties(searchCriteria); - sinon.assert.calledWithMatch(fetchStub, bountiesUrl); - expect(fetchStub.calledOnce).toBe(true); - expect(store.peopleBounties).toHaveLength(1); - expect(store.peopleBounties[0].body.title).toEqual(searchCriteria.search); + waitFor(() => { + sinon.assert.calledWithMatch(fetchStub, bountiesUrl); + expect(fetchStub.calledOnce).toBe(true); + expect(store.peopleBounties).toHaveLength(1); + expect(store.peopleBounties[0].body.title).toEqual(searchCriteria.search); + }); }); it('should return filter by languages, status response', async () => { diff --git a/src/store/main.ts b/src/store/main.ts index e764638e..b90857d5 100644 --- a/src/store/main.ts +++ b/src/store/main.ts @@ -650,16 +650,19 @@ export class MainStore { Pending: false, Failed: false, languageString: '', - direction: 'desc' + direction: 'desc', + search: uiStore.searchText ?? '' }; } } - queryParams = - (params.Pending === 'true' || params.Pending === true) && + queryParams = { + ...((params.Pending === 'true' || params.Pending === true) && (params.Paid === 'false' || params.Paid === false) ? newParams - : params; + : params), + search: uiStore.searchText ?? '' + }; const query2 = this.appendQueryParams( 'gobounties/all',