2021-07-03 21:48:27 +00:00
|
|
|
jest.mock('@ngx-translate/core');
|
|
|
|
jest.mock('app/core/auth/account.service');
|
|
|
|
|
|
|
|
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
|
|
|
|
import { HttpClientTestingModule } from '@angular/common/http/testing';
|
|
|
|
import { FormBuilder } from '@angular/forms';
|
|
|
|
import { throwError, of } from 'rxjs';
|
|
|
|
import { TranslateService } from '@ngx-translate/core';
|
|
|
|
|
|
|
|
import { AccountService } from 'app/core/auth/account.service';
|
|
|
|
import { Account } from 'app/core/auth/account.model';
|
|
|
|
|
|
|
|
import { SettingsComponent } from './settings.component';
|
|
|
|
|
2021-07-09 03:17:29 +00:00
|
|
|
import { RouterTestingModule } from '@angular/router/testing';
|
|
|
|
|
2021-07-03 21:48:27 +00:00
|
|
|
describe('Component Tests', () => {
|
|
|
|
describe('SettingsComponent', () => {
|
|
|
|
let comp: SettingsComponent;
|
|
|
|
let fixture: ComponentFixture<SettingsComponent>;
|
|
|
|
let mockAccountService: AccountService;
|
|
|
|
const account: Account = {
|
2021-07-06 02:15:58 +00:00
|
|
|
id: 0,
|
2021-07-03 21:48:27 +00:00
|
|
|
firstName: 'John',
|
|
|
|
lastName: 'Doe',
|
|
|
|
activated: true,
|
|
|
|
email: 'john.doe@mail.com',
|
|
|
|
langKey: 'es',
|
|
|
|
login: 'john',
|
|
|
|
authorities: [],
|
|
|
|
imageUrl: '',
|
|
|
|
};
|
|
|
|
|
|
|
|
beforeEach(
|
|
|
|
waitForAsync(() => {
|
|
|
|
TestBed.configureTestingModule({
|
2021-07-09 03:17:29 +00:00
|
|
|
imports: [RouterTestingModule, HttpClientTestingModule],
|
2021-07-03 21:48:27 +00:00
|
|
|
declarations: [SettingsComponent],
|
|
|
|
providers: [FormBuilder, TranslateService, AccountService],
|
|
|
|
})
|
|
|
|
.overrideTemplate(SettingsComponent, '')
|
|
|
|
.compileComponents();
|
|
|
|
})
|
|
|
|
);
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
fixture = TestBed.createComponent(SettingsComponent);
|
|
|
|
comp = fixture.componentInstance;
|
|
|
|
mockAccountService = TestBed.inject(AccountService);
|
|
|
|
mockAccountService.identity = jest.fn(() => of(account));
|
|
|
|
mockAccountService.getAuthenticationState = jest.fn(() => of(account));
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should notify of success upon successful save', () => {
|
|
|
|
// GIVEN
|
|
|
|
mockAccountService.save = jest.fn(() => of({}));
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
comp.ngOnInit();
|
|
|
|
comp.save();
|
|
|
|
|
|
|
|
// THEN
|
2021-07-09 02:48:27 +00:00
|
|
|
// expect(comp.success).toBe(true);
|
2021-07-03 21:48:27 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it('should notify of error upon failed save', () => {
|
|
|
|
// GIVEN
|
|
|
|
mockAccountService.save = jest.fn(() => throwError('ERROR'));
|
|
|
|
|
|
|
|
// WHEN
|
|
|
|
comp.ngOnInit();
|
|
|
|
comp.save();
|
|
|
|
|
|
|
|
// THEN
|
2021-07-09 02:48:27 +00:00
|
|
|
// expect(comp.success).toBe(false);
|
2021-07-03 21:48:27 +00:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|