Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

VIH-10346 - Manage team page is not cleared #1454

Merged
merged 10 commits into from
Dec 5, 2024
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ describe('ManageTeamComponent', () => {
justiceUsersServiceSpy = jasmine.createSpyObj<JusticeUsersService>('JusticeUsersService', [
'allUsers$',
'filteredUsers$',
'search'
'search',
'clearUsers'
]);
justiceUsersServiceSpy.filteredUsers$ = filteredUsers$;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,31 @@ describe('JusticeUsersService', () => {
});
});

describe('clearUsers', () => {
it('should clear the search term', (done: DoneFn) => {
// arrange
clientApiSpy.getUserList.and.returnValue(
of([{ username: 'test', first_name: 'test', lastname: 'test', contact_email: 'test' } as JusticeUserResponse])
);
// assert
const emittedValues: JusticeUserResponse[][] = [];
service.filteredUsers$.pipe(take(2)).subscribe({
next: users => emittedValues.push(users),
complete: () => {
// Assert
// First emission should have 1 user from searching for 'test'
expect(emittedValues[0].length).toBe(1);
// Second emission should have 0 users after clearing the search term
expect(emittedValues[1].length).toBe(0);
done();
}
});

service.search('test');
service.clearUsers();
});
});

describe('addNewJusticeUser', () => {
it('should call the api to save a new user & again to get the users list', (done: DoneFn) => {
const username = '[email protected]';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,20 @@ export class JusticeUsersService {
this.refresh$.next();
}

clearUsers() {
this.searchTerm$.next('');
}

search(searchTerm: string) {
this.searchTerm$.next(searchTerm);
}

applyFilter(searchTerm: string, users: JusticeUserResponse[]): JusticeUserResponse[] {
// Clear all users
if (searchTerm === '') {
return [];
}

if (!searchTerm) {
return users;
}
Expand Down
Loading