Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
it('should allow the user to be updated when password field is untouched', fakeAsync(() => {
const env = new TestUserEntryComponent();
env.useExistingUser();
expect(env.component.showPasswordPanel).toBe(false);
// The user's password is not stored on the form
expect(env.component.password.value).toBe('');
expect(env.component.password.hasError('required')).toBe(true);
// The validations on the password get bypassed when showPasswordPanel is false
env.clickElement(env.updateButton);
verify(env.mockedUserService.onlineUpdateAttributes(anything(), anything())).once();
}));
it("should call the delete on the repository", async () => {
when(directorRepository.deleteDirectorWithId(testId)).thenReturn(Promise.resolve());
await serviceUnderTest.delete(testId);
verify(directorRepository.deleteDirectorWithId(testId)).called();
});
it('should report conflicts', fakeAsync(() => {
const env = new TestUserEntryComponent();
when(env.mockedUserService.onlineCreate(anything())).thenThrow(new MockClientError(409, 'Duplicate Email!'));
env.simulateAddUser();
env.setInputValue(env.nameInput, 'New Name');
env.setInputValue(env.emailInput, env.testUser.email);
env.setInputValue(env.passwordInput, env.testUser.password);
expect(env.component.accountUserForm.valid).toBe(true);
env.clickElement(env.addButton);
verify(env.mockedUserService.onlineCreate(anything())).once();
verify(env.mockedNoticeService.show('User account could not be created due to a conflict.')).once();
}));
it('should not submit if form is invalid ', fakeAsync(() => {
const env = new TestUserEntryComponent();
env.simulateAddUser();
env.setInputValue(env.nameInput, '');
expect(env.component.fullName.hasError('required')).toBe(true);
env.setInputValue(env.emailInput, 'invalidemail');
expect(env.component.email.hasError('email')).toBe(true);
env.setInputValue(env.emailInput, 'invalidemail@example');
expect(env.component.email.hasError('pattern')).toBe(true);
env.setInputValue(env.passwordInput, '');
expect(env.component.password.hasError('required')).toBe(true);
env.clickElement(env.addButton);
verify(env.mockedUserService.onlineCreate(anything())).never();
verify(env.mockedNoticeService.show(anything())).never();
}));
it('should not submit if form is invalid', fakeAsync(() => {
const env = new TestUserEntryComponent();
env.useExistingUser();
env.setInputValue(env.nameInput, '');
expect(env.component.fullName.hasError('required')).toBe(true);
env.setInputValue(env.emailInput, '');
expect(env.component.email.hasError('required')).toBe(true);
env.setInputValue(env.emailInput, 'notvalidemail');
expect(env.component.email.hasError('email')).toBe(true);
env.clickElement(env.updateButton);
verify(env.mockedUserService.onlineUpdateAttributes(anything(), anything())).never();
}));
it('should report conflicts', fakeAsync(() => {
const env = new TestUserEntryComponent();
when(env.mockedUserService.onlineUpdateAttributes(anything(), anything())).thenThrow(
new MockClientError(409, 'Duplicate Email!')
);
env.useExistingUser();
env.setInputValue(env.nameInput, 'Something New');
env.clickElement(env.updateButton);
verify(env.mockedUserService.onlineUpdateAttributes(anything(), anything())).once();
verify(env.mockedNoticeService.show('User account could not be updated due to a conflict.')).once();
expect().nothing();
}));
it('should call api service on receiving search term', inject([SearchBoxApiService], (searchBoxApiService: SearchBoxApiService) => {
searchBoxApiService.searchEntries('url');
verify(apiServiceMock.get(anything())).once();
}));
});
it('should call CategoriesService.getCategory if subcategories data is not loaded', () => {
component.category.subCategories = null;
component.category.hasOnlineSubCategories = true;
fixture.detectChanges();
verify(categoriesServiceMock.getCategory(anything())).once();
});
});
it('should not perform link translation when not requested', () => {
apiService.get('categories').subscribe(data => {
expect(data).toEqual(categoriesResponse);
});
verify(httpClient.get(categoriesPath, new Object(anything()))).once();
verify(httpClient.get(webcamsPath, new Object(anything()))).never();
});
}
});
TestBed.configureTestingModule({
providers: [
{ provide: HttpClient, useFactory: () => instance(httpClient) },
{ provide: REST_ENDPOINT, useValue: `${BASE_URL}/site` },
{ provide: ICM_SERVER_URL, useValue: BASE_URL },
{ provide: Store, useFactory: () => instance(storeMock$) },
ApiServiceErrorHandler,
ApiService,
],
});
apiService = TestBed.get(ApiService);
verify(httpClient.get(categoriesPath, new Object(anything()))).never();
verify(httpClient.get(webcamsPath, new Object(anything()))).never();
});