From d143c150eaef7abc2afee2e721583e5fd11b715e Mon Sep 17 00:00:00 2001 From: marcogagliardi Date: Tue, 3 Dec 2024 11:44:29 +0000 Subject: [PATCH 1/8] added clearUsers function --- .../app/manage-team/manage-team/manage-team.component.ts | 6 +++++- .../ClientApp/src/app/services/justice-users.service.ts | 4 ++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/AdminWebsite/AdminWebsite/ClientApp/src/app/manage-team/manage-team/manage-team.component.ts b/AdminWebsite/AdminWebsite/ClientApp/src/app/manage-team/manage-team/manage-team.component.ts index 5752ea522..a35034d59 100644 --- a/AdminWebsite/AdminWebsite/ClientApp/src/app/manage-team/manage-team/manage-team.component.ts +++ b/AdminWebsite/AdminWebsite/ClientApp/src/app/manage-team/manage-team/manage-team.component.ts @@ -57,13 +57,17 @@ export class ManageTeamComponent implements OnInit, OnDestroy { } ngOnDestroy(): void { + this.clearUsers(); this.destroyed$.next(); } + clearUsers() { + this.justiceUserService.clearUsers(); + } + ngOnInit() { this.form.controls.inputSearch.valueChanges.subscribe(() => this.displayAddButton$.next(false)); this.isAnErrorMessage$.pipe(takeUntil(this.destroyed$)).subscribe(isAnErrorMessage => (this.isAnErrorMessage = isAnErrorMessage)); - this.users$ = this.justiceUserService.filteredUsers$.pipe( takeUntil(this.destroyed$), tap(users => { diff --git a/AdminWebsite/AdminWebsite/ClientApp/src/app/services/justice-users.service.ts b/AdminWebsite/AdminWebsite/ClientApp/src/app/services/justice-users.service.ts index 99fd6dee5..0a0024824 100644 --- a/AdminWebsite/AdminWebsite/ClientApp/src/app/services/justice-users.service.ts +++ b/AdminWebsite/AdminWebsite/ClientApp/src/app/services/justice-users.service.ts @@ -40,6 +40,10 @@ export class JusticeUsersService { this.refresh$.next(); } + clearUsers() { + this.searchTerm$.next(null); + } + search(searchTerm: string) { this.searchTerm$.next(searchTerm); } From 8d054259176d4352c248d8ca07fcd4485dbf5630 Mon Sep 17 00:00:00 2001 From: marcogagliardi Date: Tue, 3 Dec 2024 13:57:38 +0000 Subject: [PATCH 2/8] test fix --- .../app/manage-team/manage-team/manage-team.component.spec.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/AdminWebsite/AdminWebsite/ClientApp/src/app/manage-team/manage-team/manage-team.component.spec.ts b/AdminWebsite/AdminWebsite/ClientApp/src/app/manage-team/manage-team/manage-team.component.spec.ts index f7fb75e28..fc61e01e1 100644 --- a/AdminWebsite/AdminWebsite/ClientApp/src/app/manage-team/manage-team/manage-team.component.spec.ts +++ b/AdminWebsite/AdminWebsite/ClientApp/src/app/manage-team/manage-team/manage-team.component.spec.ts @@ -29,7 +29,8 @@ describe('ManageTeamComponent', () => { justiceUsersServiceSpy = jasmine.createSpyObj('JusticeUsersService', [ 'allUsers$', 'filteredUsers$', - 'search' + 'search', + 'clearUsers' ]); justiceUsersServiceSpy.filteredUsers$ = filteredUsers$; From f52da3e11348ebee43ba36ce4a5959fc06f06ed3 Mon Sep 17 00:00:00 2001 From: marcogagliardi Date: Tue, 3 Dec 2024 14:21:00 +0000 Subject: [PATCH 3/8] added test --- .../services/justice-users.service.spec.ts | 33 +++++++++++++++++++ 1 file changed, 33 insertions(+) diff --git a/AdminWebsite/AdminWebsite/ClientApp/src/app/services/justice-users.service.spec.ts b/AdminWebsite/AdminWebsite/ClientApp/src/app/services/justice-users.service.spec.ts index b0657b878..3e30665c7 100644 --- a/AdminWebsite/AdminWebsite/ClientApp/src/app/services/justice-users.service.spec.ts +++ b/AdminWebsite/AdminWebsite/ClientApp/src/app/services/justice-users.service.spec.ts @@ -134,6 +134,39 @@ describe('JusticeUsersService', () => { }); }); + describe('clearUsers', () => { + it('should clear the search term', (done: DoneFn) => { + // arrange + clientApiSpy.getUserList.and.returnValue(of([])); + + // act + service.clearUsers(); + + // assert + service.filteredUsers$.subscribe(users => { + expect(users).toEqual([]); + done(); + }); + + service.search('test'); + service.clearUsers(); + }); + + it('should trigger an emission from filteredUsers$', (done: DoneFn) => { + // arrange + clientApiSpy.getUserList.and.returnValue(of([])); + + // act + service.clearUsers(); + + // assert + service.filteredUsers$.pipe(take(1)).subscribe(users => { + expect(users).toEqual([]); + done(); + }); + }); + }); + describe('addNewJusticeUser', () => { it('should call the api to save a new user & again to get the users list', (done: DoneFn) => { const username = 'john@doe.com'; From 36974da0746b0dbe05b2635b85eaf8c28449411d Mon Sep 17 00:00:00 2001 From: marcogagliardi Date: Tue, 3 Dec 2024 14:50:34 +0000 Subject: [PATCH 4/8] Update justice-users.service.spec.ts --- .../app/services/justice-users.service.spec.ts | 16 +--------------- 1 file changed, 1 insertion(+), 15 deletions(-) diff --git a/AdminWebsite/AdminWebsite/ClientApp/src/app/services/justice-users.service.spec.ts b/AdminWebsite/AdminWebsite/ClientApp/src/app/services/justice-users.service.spec.ts index 3e30665c7..ca7b63bac 100644 --- a/AdminWebsite/AdminWebsite/ClientApp/src/app/services/justice-users.service.spec.ts +++ b/AdminWebsite/AdminWebsite/ClientApp/src/app/services/justice-users.service.spec.ts @@ -135,7 +135,7 @@ describe('JusticeUsersService', () => { }); describe('clearUsers', () => { - it('should clear the search term', (done: DoneFn) => { + fit('should clear the search term', (done: DoneFn) => { // arrange clientApiSpy.getUserList.and.returnValue(of([])); @@ -151,20 +151,6 @@ describe('JusticeUsersService', () => { service.search('test'); service.clearUsers(); }); - - it('should trigger an emission from filteredUsers$', (done: DoneFn) => { - // arrange - clientApiSpy.getUserList.and.returnValue(of([])); - - // act - service.clearUsers(); - - // assert - service.filteredUsers$.pipe(take(1)).subscribe(users => { - expect(users).toEqual([]); - done(); - }); - }); }); describe('addNewJusticeUser', () => { From 2d2df698003e29b1f4a8726ea6115d50dbc804a7 Mon Sep 17 00:00:00 2001 From: marcogagliardi Date: Tue, 3 Dec 2024 15:06:00 +0000 Subject: [PATCH 5/8] Update justice-users.service.spec.ts --- .../ClientApp/src/app/services/justice-users.service.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AdminWebsite/AdminWebsite/ClientApp/src/app/services/justice-users.service.spec.ts b/AdminWebsite/AdminWebsite/ClientApp/src/app/services/justice-users.service.spec.ts index ca7b63bac..a17094ca6 100644 --- a/AdminWebsite/AdminWebsite/ClientApp/src/app/services/justice-users.service.spec.ts +++ b/AdminWebsite/AdminWebsite/ClientApp/src/app/services/justice-users.service.spec.ts @@ -135,7 +135,7 @@ describe('JusticeUsersService', () => { }); describe('clearUsers', () => { - fit('should clear the search term', (done: DoneFn) => { + it('should clear the search term', (done: DoneFn) => { // arrange clientApiSpy.getUserList.and.returnValue(of([])); From bb9f2a9ec25bb5cf17ecb3e0d4b093e2cecf447e Mon Sep 17 00:00:00 2001 From: marcogagliardi Date: Wed, 4 Dec 2024 07:49:06 +0000 Subject: [PATCH 6/8] Update justice-users.service.spec.ts --- .../src/app/services/justice-users.service.spec.ts | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/AdminWebsite/AdminWebsite/ClientApp/src/app/services/justice-users.service.spec.ts b/AdminWebsite/AdminWebsite/ClientApp/src/app/services/justice-users.service.spec.ts index a17094ca6..258043c90 100644 --- a/AdminWebsite/AdminWebsite/ClientApp/src/app/services/justice-users.service.spec.ts +++ b/AdminWebsite/AdminWebsite/ClientApp/src/app/services/justice-users.service.spec.ts @@ -135,13 +135,10 @@ describe('JusticeUsersService', () => { }); describe('clearUsers', () => { - it('should clear the search term', (done: DoneFn) => { + fit('should clear the search term', (done: DoneFn) => { // arrange clientApiSpy.getUserList.and.returnValue(of([])); - - // act - service.clearUsers(); - + // assert service.filteredUsers$.subscribe(users => { expect(users).toEqual([]); From f4d7549e8805336925278e7f0dea88eadf2bbe74 Mon Sep 17 00:00:00 2001 From: marcogagliardi Date: Wed, 4 Dec 2024 07:52:58 +0000 Subject: [PATCH 7/8] Update justice-users.service.spec.ts --- .../ClientApp/src/app/services/justice-users.service.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AdminWebsite/AdminWebsite/ClientApp/src/app/services/justice-users.service.spec.ts b/AdminWebsite/AdminWebsite/ClientApp/src/app/services/justice-users.service.spec.ts index 258043c90..915aa0c2f 100644 --- a/AdminWebsite/AdminWebsite/ClientApp/src/app/services/justice-users.service.spec.ts +++ b/AdminWebsite/AdminWebsite/ClientApp/src/app/services/justice-users.service.spec.ts @@ -135,7 +135,7 @@ describe('JusticeUsersService', () => { }); describe('clearUsers', () => { - fit('should clear the search term', (done: DoneFn) => { + it('should clear the search term', (done: DoneFn) => { // arrange clientApiSpy.getUserList.and.returnValue(of([])); From 5c146a01562cbe223214ee4a0fda8cb3b6c10057 Mon Sep 17 00:00:00 2001 From: marcogagliardi Date: Wed, 4 Dec 2024 10:59:15 +0000 Subject: [PATCH 8/8] Update justice-users.service.spec.ts --- .../ClientApp/src/app/services/justice-users.service.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/AdminWebsite/AdminWebsite/ClientApp/src/app/services/justice-users.service.spec.ts b/AdminWebsite/AdminWebsite/ClientApp/src/app/services/justice-users.service.spec.ts index 915aa0c2f..fd40af924 100644 --- a/AdminWebsite/AdminWebsite/ClientApp/src/app/services/justice-users.service.spec.ts +++ b/AdminWebsite/AdminWebsite/ClientApp/src/app/services/justice-users.service.spec.ts @@ -138,7 +138,7 @@ describe('JusticeUsersService', () => { it('should clear the search term', (done: DoneFn) => { // arrange clientApiSpy.getUserList.and.returnValue(of([])); - + // assert service.filteredUsers$.subscribe(users => { expect(users).toEqual([]);