From c6460e5a75f5eee64f2479f33a4fdb2f30038548 Mon Sep 17 00:00:00 2001 From: aliraza556 Date: Thu, 5 Dec 2024 07:05:47 +0500 Subject: [PATCH 1/2] fix: preserve search parameter in bounties query --- src/store/main.ts | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/store/main.ts b/src/store/main.ts index f45ae9a2..467fbe77 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', From 8610f1c80a8a71618c99c9061b1239486729e7ed Mon Sep 17 00:00:00 2001 From: aliraza556 Date: Thu, 5 Dec 2024 07:38:55 +0500 Subject: [PATCH 2/2] fix unit test --- src/store/__test__/main.spec.ts | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) 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 () => {