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

Open
wants to merge 9 commits into
base: master
Choose a base branch
from
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,22 @@ describe('JusticeUsersService', () => {
});
});

describe('clearUsers', () => {
it('should clear the search term', (done: DoneFn) => {
// arrange
clientApiSpy.getUserList.and.returnValue(of([]));

// assert
service.filteredUsers$.subscribe(users => {
expect(users).toEqual([]);
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,6 +40,10 @@ export class JusticeUsersService {
this.refresh$.next();
}

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

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