Skip to content

Commit

Permalink
updated test
Browse files Browse the repository at this point in the history
  • Loading branch information
will-craig committed Dec 5, 2024
1 parent 5c146a0 commit dbfd09c
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -137,12 +137,21 @@ describe('JusticeUsersService', () => {
describe('clearUsers', () => {
it('should clear the search term', (done: DoneFn) => {
// arrange
clientApiSpy.getUserList.and.returnValue(of([]));

clientApiSpy.getUserList.and.returnValue(
of([{ username: 'test', first_name: 'test', lastname: 'test', contact_email: 'test' } as JusticeUserResponse])
);
// assert
service.filteredUsers$.subscribe(users => {
expect(users).toEqual([]);
done();
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');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,19 @@ export class JusticeUsersService {
}

clearUsers() {
this.searchTerm$.next(null);
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

0 comments on commit dbfd09c

Please sign in to comment.