refacto : refactoring des mocks de test
This commit is contained in:
@@ -4,38 +4,25 @@ import { HomeComponent } from './home.component';
|
||||
import { provideRouter } from '@angular/router';
|
||||
import { ProfileRepository } from '@app/domain/profiles/profile.repository';
|
||||
import { SectorRepository } from '@app/domain/sectors/sector.repository';
|
||||
import { of } from 'rxjs';
|
||||
import { Profile } from '@app/domain/profiles/profile.model';
|
||||
import { PROFILE_REPOSITORY_TOKEN } from '@app/infrastructure/profiles/profile-repository.token';
|
||||
import { SECTOR_REPOSITORY_TOKEN } from '@app/infrastructure/sectors/sector-repository.token';
|
||||
import { Sector } from '@app/domain/sectors/sector.model';
|
||||
import { mockSectorRepo } from '@app/testing/sector.mock';
|
||||
import { mockProfileRepo } from '@app/testing/profile.mock';
|
||||
|
||||
describe('HomeComponent', () => {
|
||||
let component: HomeComponent;
|
||||
let fixture: ComponentFixture<HomeComponent>;
|
||||
|
||||
let mockProfileRepo: jest.Mocked<Partial<ProfileRepository>>;
|
||||
let mockSectorRepo: jest.Mocked<Partial<SectorRepository>>;
|
||||
let mockProfileRepository: jest.Mocked<Partial<ProfileRepository>> = mockProfileRepo;
|
||||
let mockSectorRepository: jest.Mocked<Partial<SectorRepository>> = mockSectorRepo;
|
||||
|
||||
beforeEach(async () => {
|
||||
mockProfileRepo = {
|
||||
create: jest.fn().mockReturnValue(of({} as Profile)),
|
||||
list: jest.fn().mockReturnValue(of([])),
|
||||
getById: jest.fn().mockReturnValue(of({} as Profile)),
|
||||
update: jest.fn().mockReturnValue(of({} as Profile)),
|
||||
};
|
||||
|
||||
mockSectorRepo = {
|
||||
list: jest.fn().mockReturnValue(of([])),
|
||||
getOne: jest.fn().mockReturnValue(of({} as Sector)),
|
||||
};
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [HomeComponent],
|
||||
providers: [
|
||||
provideRouter([]),
|
||||
{ provide: PROFILE_REPOSITORY_TOKEN, useValue: mockProfileRepo },
|
||||
{ provide: SECTOR_REPOSITORY_TOKEN, useValue: mockSectorRepo },
|
||||
{ provide: PROFILE_REPOSITORY_TOKEN, useValue: mockProfileRepository },
|
||||
{ provide: SECTOR_REPOSITORY_TOKEN, useValue: mockSectorRepository },
|
||||
],
|
||||
}).compileComponents();
|
||||
|
||||
|
||||
@@ -4,62 +4,33 @@ import { MyProfileComponent } from './my-profile.component';
|
||||
import { provideRouter } from '@angular/router';
|
||||
import { ProfileRepository } from '@app/domain/profiles/profile.repository';
|
||||
import { PROFILE_REPOSITORY_TOKEN } from '@app/infrastructure/profiles/profile-repository.token';
|
||||
import { of } from 'rxjs';
|
||||
import { Profile } from '@app/domain/profiles/profile.model';
|
||||
import { ToastrService } from 'ngx-toastr';
|
||||
import { USER_REPOSITORY_TOKEN } from '@app/infrastructure/users/user-repository.token';
|
||||
import { UserRepository } from '@app/domain/users/user.repository';
|
||||
import { AuthRepository } from '@app/domain/authentification/auth.repository';
|
||||
import { AUTH_REPOSITORY_TOKEN } from '@app/infrastructure/authentification/auth-repository.token';
|
||||
import { mockProfileRepo } from '@app/testing/profile.mock';
|
||||
import { mockToastR } from '@app/testing/toastr.mock';
|
||||
import { mockUserRepo } from '@app/testing/user.mock';
|
||||
import { mockAuthRepo } from '@app/testing/auth.mock';
|
||||
|
||||
describe('MyProfileComponent', () => {
|
||||
let component: MyProfileComponent;
|
||||
let fixture: ComponentFixture<MyProfileComponent>;
|
||||
|
||||
let mockProfileRepo: ProfileRepository;
|
||||
let mockToastrService: Partial<ToastrService>;
|
||||
let mockUserRepo: Partial<UserRepository>;
|
||||
let mockAuthRepository: jest.Mocked<Partial<AuthRepository>>;
|
||||
let mockProfileRepository: jest.Mocked<Partial<ProfileRepository>> = mockProfileRepo;
|
||||
let mockToastrService: jest.Mocked<Partial<ToastrService>> = mockToastR;
|
||||
let mockUserRepository: jest.Mocked<Partial<UserRepository>> = mockUserRepo;
|
||||
let mockAuthRepository: jest.Mocked<Partial<AuthRepository>> = mockAuthRepo;
|
||||
|
||||
beforeEach(async () => {
|
||||
mockProfileRepo = {
|
||||
create: jest.fn(),
|
||||
list: jest.fn(),
|
||||
update: jest.fn(),
|
||||
getById: jest.fn().mockReturnValue(of({} as Profile)),
|
||||
};
|
||||
|
||||
mockUserRepo = {
|
||||
update: jest.fn(),
|
||||
getUserById: jest.fn(),
|
||||
};
|
||||
|
||||
mockToastrService = {
|
||||
warning: jest.fn(),
|
||||
success: jest.fn(),
|
||||
info: jest.fn(),
|
||||
error: jest.fn(),
|
||||
};
|
||||
|
||||
mockAuthRepository = {
|
||||
get: jest.fn(),
|
||||
login: jest.fn(),
|
||||
sendVerificationEmail: jest.fn(),
|
||||
logout: jest.fn(),
|
||||
isAuthenticated: jest.fn(),
|
||||
isEmailVerified: jest.fn(),
|
||||
register: jest.fn(),
|
||||
sendRequestPasswordReset: jest.fn(),
|
||||
confirmPasswordReset: jest.fn(),
|
||||
};
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [MyProfileComponent],
|
||||
providers: [
|
||||
provideRouter([]),
|
||||
{ provide: PROFILE_REPOSITORY_TOKEN, useValue: mockProfileRepo },
|
||||
{ provide: PROFILE_REPOSITORY_TOKEN, useValue: mockProfileRepository },
|
||||
{ provide: AUTH_REPOSITORY_TOKEN, useValue: mockAuthRepository },
|
||||
{ provide: USER_REPOSITORY_TOKEN, useValue: mockUserRepo },
|
||||
{ provide: USER_REPOSITORY_TOKEN, useValue: mockUserRepository },
|
||||
{ provide: ToastrService, useValue: mockToastrService },
|
||||
],
|
||||
}).compileComponents();
|
||||
|
||||
@@ -4,68 +4,38 @@ import { ProfileDetailComponent } from './profile-detail.component';
|
||||
import { provideRouter } from '@angular/router';
|
||||
import { PROJECT_REPOSITORY_TOKEN } from '@app/infrastructure/projects/project-repository.token';
|
||||
import { ProjectRepository } from '@app/domain/projects/project.repository';
|
||||
import { of } from 'rxjs';
|
||||
import { Project } from '@app/domain/projects/project.model';
|
||||
import { Sector } from '@app/domain/sectors/sector.model';
|
||||
import { SectorRepository } from '@app/domain/sectors/sector.repository';
|
||||
import { SECTOR_REPOSITORY_TOKEN } from '@app/infrastructure/sectors/sector-repository.token';
|
||||
import { ToastrService } from 'ngx-toastr';
|
||||
import { PROFILE_REPOSITORY_TOKEN } from '@app/infrastructure/profiles/profile-repository.token';
|
||||
import { Profile } from '@app/domain/profiles/profile.model';
|
||||
import { ProfileRepository } from '@app/domain/profiles/profile.repository';
|
||||
import { USER_REPOSITORY_TOKEN } from '@app/infrastructure/users/user-repository.token';
|
||||
import { UserRepository } from '@app/domain/users/user.repository';
|
||||
import { User } from '@app/domain/users/user.model';
|
||||
import { mockProfileRepo } from '@app/testing/profile.mock';
|
||||
import { mockSectorRepo } from '@app/testing/sector.mock';
|
||||
import { mockToastR } from '@app/testing/toastr.mock';
|
||||
import { mockUserRepo } from '@app/testing/user.mock';
|
||||
import { mockProjectRepo } from '@app/testing/project.mock';
|
||||
|
||||
describe('ProfileDetailComponent', () => {
|
||||
let component: ProfileDetailComponent;
|
||||
let fixture: ComponentFixture<ProfileDetailComponent>;
|
||||
let mockProjectRepository: jest.Mocked<ProjectRepository>;
|
||||
let mockProfileRepository: jest.Mocked<Partial<ProfileRepository>>;
|
||||
let mockSectorRepo: SectorRepository;
|
||||
let mockToastr: Partial<ToastrService>;
|
||||
let mockUserRepo: jest.Mocked<Partial<UserRepository>>;
|
||||
|
||||
let mockProjectRepository: jest.Mocked<Partial<ProjectRepository>> = mockProjectRepo;
|
||||
let mockProfileRepository: jest.Mocked<Partial<ProfileRepository>> = mockProfileRepo;
|
||||
let mockSectorRepository: jest.Mocked<Partial<SectorRepository>> = mockSectorRepo;
|
||||
let mockToastr: jest.Mocked<Partial<ToastrService>> = mockToastR;
|
||||
let mockUserRepository: jest.Mocked<Partial<UserRepository>> = mockUserRepo;
|
||||
|
||||
beforeEach(async () => {
|
||||
mockProjectRepository = {
|
||||
create: jest.fn().mockReturnValue(of({} as Project)),
|
||||
list: jest.fn().mockReturnValue(of([])),
|
||||
get: jest.fn().mockReturnValue(of({} as Project)),
|
||||
update: jest.fn().mockReturnValue(of({} as Project)),
|
||||
};
|
||||
|
||||
mockSectorRepo = {
|
||||
list: jest.fn(),
|
||||
getOne: jest.fn().mockReturnValue(of({} as Sector)),
|
||||
};
|
||||
|
||||
mockToastr = {
|
||||
warning: jest.fn(),
|
||||
success: jest.fn(),
|
||||
info: jest.fn(),
|
||||
error: jest.fn(),
|
||||
};
|
||||
|
||||
mockProfileRepository = {
|
||||
create: jest.fn().mockReturnValue(of({} as Profile)),
|
||||
list: jest.fn().mockReturnValue(of([])),
|
||||
getById: jest.fn().mockReturnValue(of({} as Profile)),
|
||||
update: jest.fn().mockReturnValue(of({} as Profile)),
|
||||
};
|
||||
|
||||
mockUserRepo = {
|
||||
getUserById: jest.fn().mockReturnValue(of({} as User)),
|
||||
update: jest.fn(),
|
||||
};
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [ProfileDetailComponent],
|
||||
providers: [
|
||||
provideRouter([]),
|
||||
{ provide: PROJECT_REPOSITORY_TOKEN, useValue: mockProjectRepository },
|
||||
{ provide: PROFILE_REPOSITORY_TOKEN, useValue: mockProfileRepository },
|
||||
{ provide: SECTOR_REPOSITORY_TOKEN, useValue: mockSectorRepo },
|
||||
{ provide: USER_REPOSITORY_TOKEN, useValue: mockUserRepo },
|
||||
{ provide: SECTOR_REPOSITORY_TOKEN, useValue: mockSectorRepository },
|
||||
{ provide: USER_REPOSITORY_TOKEN, useValue: mockUserRepository },
|
||||
{ provide: ToastrService, useValue: mockToastr },
|
||||
],
|
||||
}).compileComponents();
|
||||
|
||||
@@ -2,33 +2,20 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ProfileListComponent } from './profile-list.component';
|
||||
import { provideRouter } from '@angular/router';
|
||||
import { of } from 'rxjs';
|
||||
import { ProfileRepository } from '@app/domain/profiles/profile.repository';
|
||||
import { PROFILE_REPOSITORY_TOKEN } from '@app/infrastructure/profiles/profile-repository.token';
|
||||
import { Profile } from '@app/domain/profiles/profile.model';
|
||||
import { SECTOR_REPOSITORY_TOKEN } from '@app/infrastructure/sectors/sector-repository.token';
|
||||
import { SectorRepository } from '@app/domain/sectors/sector.repository';
|
||||
import { Sector } from '@app/domain/sectors/sector.model';
|
||||
import { mockProfileRepo } from '@app/testing/profile.mock';
|
||||
import { mockSectorRepo } from '@app/testing/sector.mock';
|
||||
|
||||
describe('ProfileListComponent', () => {
|
||||
let component: ProfileListComponent;
|
||||
let fixture: ComponentFixture<ProfileListComponent>;
|
||||
let mockProfileRepository: jest.Mocked<Partial<ProfileRepository>>;
|
||||
let mockSectorRepository: jest.Mocked<Partial<SectorRepository>>;
|
||||
let mockProfileRepository: jest.Mocked<Partial<ProfileRepository>> = mockProfileRepo;
|
||||
let mockSectorRepository: jest.Mocked<Partial<SectorRepository>> = mockSectorRepo;
|
||||
|
||||
beforeEach(async () => {
|
||||
mockProfileRepository = {
|
||||
create: jest.fn().mockReturnValue(of({} as Profile)),
|
||||
list: jest.fn().mockReturnValue(of([])),
|
||||
getById: jest.fn().mockReturnValue(of({} as Profile)),
|
||||
update: jest.fn().mockReturnValue(of({} as Profile)),
|
||||
};
|
||||
|
||||
mockSectorRepository = {
|
||||
list: jest.fn().mockReturnValue(of([])),
|
||||
getOne: jest.fn().mockReturnValue(of({} as Sector)),
|
||||
};
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [ProfileListComponent],
|
||||
providers: [
|
||||
|
||||
@@ -3,27 +3,21 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { ChipsComponent } from './chips.component';
|
||||
import { provideRouter } from '@angular/router';
|
||||
import { SECTOR_REPOSITORY_TOKEN } from '@app/infrastructure/sectors/sector-repository.token';
|
||||
import { of } from 'rxjs';
|
||||
import { Sector } from '@app/domain/sectors/sector.model';
|
||||
import { SectorRepository } from '@app/domain/sectors/sector.repository';
|
||||
import { mockSectorRepo } from '@app/testing/sector.mock';
|
||||
|
||||
describe('ChipsComponent', () => {
|
||||
let component: ChipsComponent;
|
||||
let fixture: ComponentFixture<ChipsComponent>;
|
||||
|
||||
let mockSectorRepo: SectorRepository;
|
||||
let mockSectorRepository: jest.Mocked<Partial<SectorRepository>> = mockSectorRepo;
|
||||
|
||||
beforeEach(async () => {
|
||||
mockSectorRepo = {
|
||||
list: jest.fn(),
|
||||
getOne: jest.fn().mockReturnValue(of({} as Sector)),
|
||||
};
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [ChipsComponent],
|
||||
providers: [
|
||||
provideRouter([]),
|
||||
{ provide: SECTOR_REPOSITORY_TOKEN, useValue: mockSectorRepo },
|
||||
{ provide: SECTOR_REPOSITORY_TOKEN, useValue: mockSectorRepository },
|
||||
],
|
||||
}).compileComponents();
|
||||
|
||||
|
||||
@@ -6,21 +6,15 @@ import { Project } from '@app/domain/projects/project.model';
|
||||
import { ProjectRepository } from '@app/domain/projects/project.repository';
|
||||
import { provideRouter } from '@angular/router';
|
||||
import { PROJECT_REPOSITORY_TOKEN } from '@app/infrastructure/projects/project-repository.token';
|
||||
import { mockProjectRepo } from '@app/testing/project.mock';
|
||||
|
||||
describe('MyProfileProjectItemComponent', () => {
|
||||
let component: MyProfileProjectItemComponent;
|
||||
let fixture: ComponentFixture<MyProfileProjectItemComponent>;
|
||||
|
||||
let mockProjectRepository: jest.Mocked<ProjectRepository>;
|
||||
let mockProjectRepository: jest.Mocked<Partial<ProjectRepository>> = mockProjectRepo;
|
||||
|
||||
beforeEach(async () => {
|
||||
mockProjectRepository = {
|
||||
create: jest.fn().mockReturnValue(of({} as Project)),
|
||||
list: jest.fn().mockReturnValue(of([])),
|
||||
get: jest.fn().mockReturnValue(of({} as Project)),
|
||||
update: jest.fn().mockReturnValue(of({} as Project)),
|
||||
};
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [MyProfileProjectItemComponent],
|
||||
providers: [
|
||||
|
||||
@@ -2,24 +2,16 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { MyProfileProjectListComponent } from './my-profile-project-list.component';
|
||||
import { ProjectRepository } from '@app/domain/projects/project.repository';
|
||||
import { of } from 'rxjs';
|
||||
import { provideRouter } from '@angular/router';
|
||||
import { PROJECT_REPOSITORY_TOKEN } from '@app/infrastructure/projects/project-repository.token';
|
||||
import { Project } from '@app/domain/projects/project.model';
|
||||
import { mockProfileRepo } from '@app/testing/profile.mock';
|
||||
|
||||
describe('MyProfileProjectListComponent', () => {
|
||||
let component: MyProfileProjectListComponent;
|
||||
let fixture: ComponentFixture<MyProfileProjectListComponent>;
|
||||
let mockProjectRepository: jest.Mocked<ProjectRepository>;
|
||||
let mockProjectRepository: jest.Mocked<Partial<ProjectRepository>> = mockProfileRepo;
|
||||
|
||||
beforeEach(async () => {
|
||||
mockProjectRepository = {
|
||||
create: jest.fn().mockReturnValue(of({} as Project)),
|
||||
list: jest.fn().mockReturnValue(of([])),
|
||||
get: jest.fn().mockReturnValue(of({} as Project)),
|
||||
update: jest.fn().mockReturnValue(of({} as Project)),
|
||||
};
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [MyProfileProjectListComponent],
|
||||
providers: [
|
||||
|
||||
@@ -3,37 +3,24 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { MyProfileUpdateCvFormComponent } from './my-profile-update-cv-form.component';
|
||||
import { ToastrService } from 'ngx-toastr';
|
||||
import { provideRouter } from '@angular/router';
|
||||
import { ProfileRepository } from '@app/domain/profiles/profile.repository';
|
||||
import { of } from 'rxjs';
|
||||
import { Profile } from '@app/domain/profiles/profile.model';
|
||||
import { PROFILE_REPOSITORY_TOKEN } from '@app/infrastructure/profiles/profile-repository.token';
|
||||
import { ProjectRepository } from '@app/domain/projects/project.repository';
|
||||
import { mockProfileRepo } from '@app/testing/profile.mock';
|
||||
import { mockToastR } from '@app/testing/toastr.mock';
|
||||
|
||||
describe('MyProfileUpdateCvFormComponent', () => {
|
||||
let component: MyProfileUpdateCvFormComponent;
|
||||
let fixture: ComponentFixture<MyProfileUpdateCvFormComponent>;
|
||||
|
||||
let mockToastrService: Partial<ToastrService>;
|
||||
let mockProfileRepo: ProfileRepository;
|
||||
let mockToastrService: jest.Mocked<Partial<ToastrService>> = mockToastR;
|
||||
let mockProjectRepository: jest.Mocked<Partial<ProjectRepository>> = mockProfileRepo;
|
||||
|
||||
beforeEach(async () => {
|
||||
mockToastrService = {
|
||||
success: jest.fn(),
|
||||
error: jest.fn(),
|
||||
warning: jest.fn(),
|
||||
};
|
||||
|
||||
mockProfileRepo = {
|
||||
create: jest.fn(),
|
||||
list: jest.fn(),
|
||||
update: jest.fn().mockReturnValue(of({} as Profile)),
|
||||
getById: jest.fn().mockReturnValue(of({} as Profile)),
|
||||
};
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [MyProfileUpdateCvFormComponent],
|
||||
providers: [
|
||||
provideRouter([]),
|
||||
{ provide: PROFILE_REPOSITORY_TOKEN, useValue: mockProfileRepo },
|
||||
{ provide: PROFILE_REPOSITORY_TOKEN, useValue: mockProjectRepository },
|
||||
{ provide: ToastrService, useValue: mockToastrService },
|
||||
],
|
||||
}).compileComponents();
|
||||
|
||||
@@ -11,14 +11,18 @@ import { Profile } from '@app/domain/profiles/profile.model';
|
||||
import { SectorRepository } from '@app/domain/sectors/sector.repository';
|
||||
import { Sector } from '@app/domain/sectors/sector.model';
|
||||
import { SECTOR_REPOSITORY_TOKEN } from '@app/infrastructure/sectors/sector-repository.token';
|
||||
import { mockToastR } from '@app/testing/toastr.mock';
|
||||
import { ProjectRepository } from '@app/domain/projects/project.repository';
|
||||
import { mockProfileRepo } from '@app/testing/profile.mock';
|
||||
import { mockSectorRepo } from '@app/testing/sector.mock';
|
||||
|
||||
describe('MyProfileUpdateFormComponent', () => {
|
||||
let component: MyProfileUpdateFormComponent;
|
||||
let fixture: ComponentFixture<MyProfileUpdateFormComponent>;
|
||||
|
||||
let mockToastrService: Partial<ToastrService>;
|
||||
let mockProfileRepo: ProfileRepository;
|
||||
let mockSectorRepo: SectorRepository;
|
||||
let mockToastrService: jest.Mocked<Partial<ToastrService>> = mockToastR;
|
||||
let mockProfileRepository: jest.Mocked<Partial<ProfileRepository>> = mockProfileRepo;
|
||||
let mockSectorRepository: jest.Mocked<Partial<SectorRepository>> = mockSectorRepo;
|
||||
|
||||
const mockProfileData = {
|
||||
profession: '',
|
||||
@@ -29,32 +33,14 @@ describe('MyProfileUpdateFormComponent', () => {
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
mockToastrService = {
|
||||
warning: jest.fn(),
|
||||
success: jest.fn(),
|
||||
error: jest.fn(),
|
||||
};
|
||||
|
||||
mockProfileRepo = {
|
||||
create: jest.fn(),
|
||||
list: jest.fn(),
|
||||
update: jest.fn().mockReturnValue(of({} as Profile)),
|
||||
getById: jest.fn().mockReturnValue(of({} as Profile)),
|
||||
};
|
||||
|
||||
mockSectorRepo = {
|
||||
list: jest.fn().mockReturnValue(of([])),
|
||||
getOne: jest.fn().mockReturnValue(of({} as Sector)),
|
||||
};
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [MyProfileUpdateFormComponent],
|
||||
providers: [
|
||||
FormBuilder,
|
||||
provideRouter([]),
|
||||
{ provide: ToastrService, useValue: mockToastrService },
|
||||
{ provide: PROFILE_REPOSITORY_TOKEN, useValue: mockProfileRepo },
|
||||
{ provide: SECTOR_REPOSITORY_TOKEN, useValue: mockSectorRepo },
|
||||
{ provide: PROFILE_REPOSITORY_TOKEN, useValue: mockProfileRepository },
|
||||
{ provide: SECTOR_REPOSITORY_TOKEN, useValue: mockSectorRepository },
|
||||
],
|
||||
}).compileComponents();
|
||||
|
||||
|
||||
@@ -11,49 +11,22 @@ import { AUTH_REPOSITORY_TOKEN } from '@app/infrastructure/authentification/auth
|
||||
import { PROFILE_REPOSITORY_TOKEN } from '@app/infrastructure/profiles/profile-repository.token';
|
||||
import { AuthRepository } from '@app/domain/authentification/auth.repository';
|
||||
import { ProfileRepository } from '@app/domain/profiles/profile.repository';
|
||||
import { mockAuthRepo } from '@app/testing/auth.mock';
|
||||
import { mockProfileRepo } from '@app/testing/profile.mock';
|
||||
import { mockProjectRepo } from '@app/testing/project.mock';
|
||||
import { mockToastR } from '@app/testing/toastr.mock';
|
||||
|
||||
describe('MyProfileUpdateProjectFormComponent', () => {
|
||||
let component: MyProfileUpdateProjectFormComponent;
|
||||
let fixture: ComponentFixture<MyProfileUpdateProjectFormComponent>;
|
||||
|
||||
let mockToastrService: jest.Mocked<Partial<ToastrService>>;
|
||||
let mockProjectRepository: jest.Mocked<Partial<ProjectRepository>>;
|
||||
let mockToastrService: jest.Mocked<Partial<ToastrService>> = mockToastR;
|
||||
let mockProjectRepository: jest.Mocked<Partial<ProjectRepository>> = mockProjectRepo;
|
||||
|
||||
let mockAuthRepository: jest.Mocked<Partial<AuthRepository>>;
|
||||
let mockProfileRepo: jest.Mocked<Partial<ProfileRepository>>;
|
||||
let mockAuthRepository: jest.Mocked<Partial<AuthRepository>> = mockAuthRepo;
|
||||
let mockProfileRepository: jest.Mocked<Partial<ProfileRepository>> = mockProfileRepo;
|
||||
|
||||
beforeEach(async () => {
|
||||
mockToastrService = {
|
||||
success: jest.fn(),
|
||||
error: jest.fn(),
|
||||
warning: jest.fn(),
|
||||
};
|
||||
|
||||
mockProjectRepository = {
|
||||
create: jest.fn().mockReturnValue(of({} as Project)),
|
||||
list: jest.fn().mockReturnValue(of([])),
|
||||
get: jest.fn().mockReturnValue(of({} as Project)),
|
||||
update: jest.fn().mockReturnValue(of({} as Project)),
|
||||
};
|
||||
mockAuthRepository = {
|
||||
get: jest.fn(),
|
||||
login: jest.fn(),
|
||||
sendVerificationEmail: jest.fn(),
|
||||
logout: jest.fn(),
|
||||
isAuthenticated: jest.fn(),
|
||||
isEmailVerified: jest.fn(),
|
||||
register: jest.fn(),
|
||||
sendRequestPasswordReset: jest.fn(),
|
||||
confirmPasswordReset: jest.fn(),
|
||||
};
|
||||
|
||||
mockProfileRepo = {
|
||||
create: jest.fn(),
|
||||
list: jest.fn(),
|
||||
update: jest.fn(),
|
||||
getById: jest.fn(),
|
||||
};
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [MyProfileUpdateProjectFormComponent],
|
||||
providers: [
|
||||
@@ -61,7 +34,7 @@ describe('MyProfileUpdateProjectFormComponent', () => {
|
||||
{ provide: ToastrService, useValue: mockToastrService },
|
||||
{ provide: PROJECT_REPOSITORY_TOKEN, useValue: mockProjectRepository },
|
||||
{ provide: AUTH_REPOSITORY_TOKEN, useValue: mockAuthRepository },
|
||||
{ provide: PROFILE_REPOSITORY_TOKEN, useValue: mockProfileRepo },
|
||||
{ provide: PROFILE_REPOSITORY_TOKEN, useValue: mockProfileRepository },
|
||||
],
|
||||
}).compileComponents();
|
||||
|
||||
|
||||
@@ -3,20 +3,22 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
import { NavBarComponent } from './nav-bar.component';
|
||||
import { ThemeService } from '@app/core/services/theme/theme.service';
|
||||
import { provideRouter } from '@angular/router';
|
||||
import { signal } from '@angular/core';
|
||||
import { User } from '@app/domain/users/user.model';
|
||||
import { AUTH_REPOSITORY_TOKEN } from '@app/infrastructure/authentification/auth-repository.token';
|
||||
import { AuthRepository } from '@app/domain/authentification/auth.repository';
|
||||
import { PROFILE_REPOSITORY_TOKEN } from '@app/infrastructure/profiles/profile-repository.token';
|
||||
import { ProfileRepository } from '@app/domain/profiles/profile.repository';
|
||||
import { mockProfileRepo } from '@app/testing/profile.mock';
|
||||
import { mockAuthRepo } from '@app/testing/auth.mock';
|
||||
import { mockThemeService } from '@app/testing/theme.mock';
|
||||
|
||||
describe('NavBarComponent', () => {
|
||||
let component: NavBarComponent;
|
||||
let fixture: ComponentFixture<NavBarComponent>;
|
||||
let mockThemeService: jest.Mocked<Partial<ThemeService>>;
|
||||
let mockTheme: jest.Mocked<Partial<ThemeService>> = mockThemeService;
|
||||
|
||||
let mockAuthRepository: jest.Mocked<Partial<AuthRepository>>;
|
||||
let mockProfileRepo: jest.Mocked<Partial<ProfileRepository>>;
|
||||
let mockAuthRepository: jest.Mocked<Partial<AuthRepository>> = mockAuthRepo;
|
||||
let mockProfileRepository: jest.Mocked<Partial<ProfileRepository>> = mockProfileRepo;
|
||||
|
||||
const user: User = {
|
||||
id: 'adbc123',
|
||||
@@ -31,37 +33,13 @@ describe('NavBarComponent', () => {
|
||||
};
|
||||
|
||||
beforeEach(async () => {
|
||||
mockThemeService = {
|
||||
darkModeSignal: signal<string>('null'),
|
||||
updateDarkMode: jest.fn(),
|
||||
};
|
||||
|
||||
mockAuthRepository = {
|
||||
get: jest.fn(),
|
||||
login: jest.fn(),
|
||||
sendVerificationEmail: jest.fn(),
|
||||
logout: jest.fn(),
|
||||
isAuthenticated: jest.fn(),
|
||||
isEmailVerified: jest.fn(),
|
||||
register: jest.fn(),
|
||||
sendRequestPasswordReset: jest.fn(),
|
||||
confirmPasswordReset: jest.fn(),
|
||||
};
|
||||
|
||||
mockProfileRepo = {
|
||||
create: jest.fn(),
|
||||
list: jest.fn(),
|
||||
update: jest.fn(),
|
||||
getById: jest.fn(),
|
||||
};
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [NavBarComponent],
|
||||
providers: [
|
||||
provideRouter([]),
|
||||
{ provide: ThemeService, useValue: mockThemeService },
|
||||
{ provide: ThemeService, useValue: mockTheme },
|
||||
{ provide: AUTH_REPOSITORY_TOKEN, useValue: mockAuthRepository },
|
||||
{ provide: PROFILE_REPOSITORY_TOKEN, useValue: mockProfileRepo },
|
||||
{ provide: PROFILE_REPOSITORY_TOKEN, useValue: mockProfileRepository },
|
||||
],
|
||||
}).compileComponents();
|
||||
|
||||
|
||||
@@ -2,25 +2,17 @@ import { ComponentFixture, TestBed } from '@angular/core/testing';
|
||||
|
||||
import { ProjectListComponent } from './project-list.component';
|
||||
import { ProjectRepository } from '@app/domain/projects/project.repository';
|
||||
import { of } from 'rxjs';
|
||||
import { Project } from '@app/domain/projects/project.model';
|
||||
import { provideRouter } from '@angular/router';
|
||||
import { PROJECT_REPOSITORY_TOKEN } from '@app/infrastructure/projects/project-repository.token';
|
||||
import { mockProjectRepo } from '@app/testing/project.mock';
|
||||
|
||||
describe('ProjectListComponent', () => {
|
||||
let component: ProjectListComponent;
|
||||
let fixture: ComponentFixture<ProjectListComponent>;
|
||||
|
||||
let mockProjectRepository: jest.Mocked<ProjectRepository>;
|
||||
let mockProjectRepository: jest.Mocked<ProjectRepository> = mockProjectRepo;
|
||||
|
||||
beforeEach(async () => {
|
||||
mockProjectRepository = {
|
||||
create: jest.fn().mockReturnValue(of({} as Project)),
|
||||
list: jest.fn().mockReturnValue(of([])),
|
||||
get: jest.fn().mockReturnValue(of({} as Project)),
|
||||
update: jest.fn().mockReturnValue(of({} as Project)),
|
||||
};
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [ProjectListComponent],
|
||||
providers: [
|
||||
|
||||
@@ -4,31 +4,18 @@ import { ProjectPictureFormComponent } from './project-picture-form.component';
|
||||
import { provideRouter } from '@angular/router';
|
||||
import { ToastrService } from 'ngx-toastr';
|
||||
import { PROJECT_REPOSITORY_TOKEN } from '@app/infrastructure/projects/project-repository.token';
|
||||
import { of } from 'rxjs';
|
||||
import { Project } from '@app/domain/projects/project.model';
|
||||
import { ProjectRepository } from '@app/domain/projects/project.repository';
|
||||
import { mockToastR } from '@app/testing/toastr.mock';
|
||||
import { mockProjectRepo } from '@app/testing/project.mock';
|
||||
|
||||
describe('ProjectPictureFormComponent', () => {
|
||||
let component: ProjectPictureFormComponent;
|
||||
let fixture: ComponentFixture<ProjectPictureFormComponent>;
|
||||
|
||||
let mockToastrService: Partial<ToastrService>;
|
||||
let mockProjectRepository: jest.Mocked<ProjectRepository>;
|
||||
let mockToastrService: jest.Mocked<Partial<ToastrService>> = mockToastR;
|
||||
let mockProjectRepository: jest.Mocked<Partial<ProjectRepository>> = mockProjectRepo;
|
||||
|
||||
beforeEach(async () => {
|
||||
mockToastrService = {
|
||||
success: jest.fn(),
|
||||
error: jest.fn(),
|
||||
warning: jest.fn(),
|
||||
};
|
||||
|
||||
mockProjectRepository = {
|
||||
create: jest.fn().mockReturnValue(of({} as Project)),
|
||||
list: jest.fn().mockReturnValue(of([])),
|
||||
get: jest.fn().mockReturnValue(of({} as Project)),
|
||||
update: jest.fn().mockReturnValue(of({} as Project)),
|
||||
};
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [ProjectPictureFormComponent],
|
||||
providers: [
|
||||
|
||||
@@ -5,31 +5,22 @@ import { provideRouter } from '@angular/router';
|
||||
import { ToastrService } from 'ngx-toastr';
|
||||
import { UserRepository } from '@app/domain/users/user.repository';
|
||||
import { USER_REPOSITORY_TOKEN } from '@app/infrastructure/users/user-repository.token';
|
||||
import { mockToastR } from '@app/testing/toastr.mock';
|
||||
import { mockUserRepo } from '@app/testing/user.mock';
|
||||
|
||||
describe('UserAvatarFormComponent', () => {
|
||||
let component: UserAvatarFormComponent;
|
||||
let fixture: ComponentFixture<UserAvatarFormComponent>;
|
||||
|
||||
let mockToastrService: Partial<ToastrService>;
|
||||
let mockUserRepo: UserRepository;
|
||||
let mockToastrService: jest.Mocked<Partial<ToastrService>> = mockToastR;
|
||||
let mockUserRepository: jest.Mocked<Partial<UserRepository>> = mockUserRepo;
|
||||
|
||||
beforeEach(async () => {
|
||||
mockToastrService = {
|
||||
warning: jest.fn(),
|
||||
success: jest.fn(),
|
||||
error: jest.fn(),
|
||||
};
|
||||
|
||||
mockUserRepo = {
|
||||
update: jest.fn(),
|
||||
getUserById: jest.fn(),
|
||||
};
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [UserAvatarFormComponent],
|
||||
providers: [
|
||||
provideRouter([]),
|
||||
{ provide: USER_REPOSITORY_TOKEN, useValue: mockUserRepo },
|
||||
{ provide: USER_REPOSITORY_TOKEN, useValue: mockUserRepository },
|
||||
{ provide: ToastrService, useValue: mockToastrService },
|
||||
],
|
||||
}).compileComponents();
|
||||
|
||||
@@ -6,32 +6,23 @@ import { provideRouter } from '@angular/router';
|
||||
import { FormBuilder } from '@angular/forms';
|
||||
import { USER_REPOSITORY_TOKEN } from '@app/infrastructure/users/user-repository.token';
|
||||
import { UserRepository } from '@app/domain/users/user.repository';
|
||||
import { mockToastR } from '@app/testing/toastr.mock';
|
||||
import { mockUserRepo } from '@app/testing/user.mock';
|
||||
|
||||
describe('UserFormComponent', () => {
|
||||
let component: UserFormComponent;
|
||||
let fixture: ComponentFixture<UserFormComponent>;
|
||||
|
||||
let mockToastrService: Partial<ToastrService>;
|
||||
let mockUserRepo: UserRepository;
|
||||
let mockToastrService: jest.Mocked<Partial<ToastrService>> = mockToastR;
|
||||
let mockUserRepository: jest.Mocked<Partial<UserRepository>> = mockUserRepo;
|
||||
|
||||
beforeEach(async () => {
|
||||
mockToastrService = {
|
||||
warning: jest.fn(),
|
||||
success: jest.fn(),
|
||||
error: jest.fn(),
|
||||
};
|
||||
|
||||
mockUserRepo = {
|
||||
update: jest.fn(),
|
||||
getUserById: jest.fn(),
|
||||
};
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [UserFormComponent],
|
||||
providers: [
|
||||
provideRouter([]),
|
||||
FormBuilder,
|
||||
{ provide: USER_REPOSITORY_TOKEN, useValue: mockUserRepo },
|
||||
{ provide: USER_REPOSITORY_TOKEN, useValue: mockUserRepository },
|
||||
{ provide: ToastrService, useValue: mockToastrService },
|
||||
],
|
||||
}).compileComponents();
|
||||
|
||||
@@ -6,34 +6,23 @@ import { AuthFacade } from '@app/ui/authentification/auth.facade';
|
||||
import { By } from '@angular/platform-browser';
|
||||
import { ActionType } from '@app/domain/action-type.util';
|
||||
import { signal, WritableSignal } from '@angular/core';
|
||||
import { mockToastR } from '@app/testing/toastr.mock';
|
||||
import { mockAuthenticationFacade } from '@app/testing/ui/authentification/auth.facade.mock';
|
||||
|
||||
describe('UserPasswordFormComponent', () => {
|
||||
let component: UserPasswordFormComponent;
|
||||
let fixture: ComponentFixture<UserPasswordFormComponent>;
|
||||
|
||||
let mockToastrService: Partial<ToastrService>;
|
||||
let mockToastrService: jest.Mocked<Partial<ToastrService>> = mockToastR;
|
||||
|
||||
// On mocke la Facade car c'est ce que le composant utilise directement
|
||||
let mockAuthFacade: {
|
||||
sendRequestPasswordReset: jest.Mock;
|
||||
loading: WritableSignal<{ isLoading: boolean; action: ActionType }>;
|
||||
error: WritableSignal<{ hasError: boolean }>;
|
||||
};
|
||||
} = mockAuthenticationFacade;
|
||||
|
||||
beforeEach(async () => {
|
||||
mockToastrService = {
|
||||
warning: jest.fn(),
|
||||
success: jest.fn(),
|
||||
info: jest.fn(),
|
||||
error: jest.fn(),
|
||||
};
|
||||
|
||||
mockAuthFacade = {
|
||||
sendRequestPasswordReset: jest.fn(),
|
||||
loading: signal({ isLoading: false, action: ActionType.NONE }),
|
||||
error: signal({ hasError: false }),
|
||||
};
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [UserPasswordFormComponent],
|
||||
providers: [
|
||||
|
||||
@@ -9,31 +9,23 @@ import { of } from 'rxjs';
|
||||
import { SECTOR_REPOSITORY_TOKEN } from '@app/infrastructure/sectors/sector-repository.token';
|
||||
import { SectorRepository } from '@app/domain/sectors/sector.repository';
|
||||
import { Sector } from '@app/domain/sectors/sector.model';
|
||||
import { mockUserRepo } from '@app/testing/user.mock';
|
||||
import { mockSectorRepo } from '@app/testing/sector.mock';
|
||||
|
||||
describe('VerticalProfileItemComponent', () => {
|
||||
let component: VerticalProfileItemComponent;
|
||||
let fixture: ComponentFixture<VerticalProfileItemComponent>;
|
||||
|
||||
let mockUserRepo: UserRepository;
|
||||
let mockSectorRepo: SectorRepository;
|
||||
let mockUserRepository: jest.Mocked<Partial<UserRepository>> = mockUserRepo;
|
||||
let mockSectorRepository: jest.Mocked<Partial<SectorRepository>> = mockSectorRepo;
|
||||
|
||||
beforeEach(async () => {
|
||||
mockUserRepo = {
|
||||
update: jest.fn().mockReturnValue(of({} as User)),
|
||||
getUserById: jest.fn().mockReturnValue(of({} as User)),
|
||||
};
|
||||
|
||||
mockSectorRepo = {
|
||||
list: jest.fn().mockReturnValue(of({} as Sector)),
|
||||
getOne: jest.fn().mockReturnValue(of({} as Sector)),
|
||||
};
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [VerticalProfileItemComponent],
|
||||
providers: [
|
||||
provideRouter([]),
|
||||
{ provide: USER_REPOSITORY_TOKEN, useValue: mockUserRepo },
|
||||
{ provide: SECTOR_REPOSITORY_TOKEN, useValue: mockSectorRepo },
|
||||
{ provide: USER_REPOSITORY_TOKEN, useValue: mockUserRepository },
|
||||
{ provide: SECTOR_REPOSITORY_TOKEN, useValue: mockSectorRepository },
|
||||
],
|
||||
}).compileComponents();
|
||||
|
||||
|
||||
@@ -9,26 +9,16 @@ import { of } from 'rxjs';
|
||||
import { Profile } from '@app/domain/profiles/profile.model';
|
||||
import { ProfileRepository } from '@app/domain/profiles/profile.repository';
|
||||
import { Sector } from '@app/domain/sectors/sector.model';
|
||||
import { mockProfileRepo } from '@app/testing/profile.mock';
|
||||
import { mockSectorRepo } from '@app/testing/sector.mock';
|
||||
|
||||
describe('FilterComponent', () => {
|
||||
let component: FilterComponent;
|
||||
let fixture: ComponentFixture<FilterComponent>;
|
||||
let mockProfileRepository: jest.Mocked<Partial<ProfileRepository>>;
|
||||
let mockSectorRepository: jest.Mocked<Partial<SectorRepository>>;
|
||||
let mockProfileRepository: jest.Mocked<Partial<ProfileRepository>> = mockProfileRepo;
|
||||
let mockSectorRepository: jest.Mocked<Partial<SectorRepository>> = mockSectorRepo;
|
||||
|
||||
beforeEach(async () => {
|
||||
mockProfileRepository = {
|
||||
create: jest.fn().mockReturnValue(of({} as Profile)),
|
||||
list: jest.fn().mockReturnValue(of([])),
|
||||
getById: jest.fn().mockReturnValue(of({} as Profile)),
|
||||
update: jest.fn().mockReturnValue(of({} as Profile)),
|
||||
};
|
||||
|
||||
mockSectorRepository = {
|
||||
list: jest.fn().mockReturnValue(of([])),
|
||||
getOne: jest.fn().mockReturnValue(of({} as Sector)),
|
||||
};
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [FilterComponent],
|
||||
providers: [
|
||||
|
||||
@@ -8,43 +8,20 @@ import { AuthRepository } from '@app/domain/authentification/auth.repository';
|
||||
import { AUTH_REPOSITORY_TOKEN } from '@app/infrastructure/authentification/auth-repository.token';
|
||||
import { ProfileRepository } from '@app/domain/profiles/profile.repository';
|
||||
import { PROFILE_REPOSITORY_TOKEN } from '@app/infrastructure/profiles/profile-repository.token';
|
||||
import { mockAuthRepo } from '@app/testing/auth.mock';
|
||||
import { mockProfileRepo } from '@app/testing/profile.mock';
|
||||
import { mockToastR } from '@app/testing/toastr.mock';
|
||||
|
||||
describe('LoginComponent', () => {
|
||||
let component: LoginComponent;
|
||||
let fixture: ComponentFixture<LoginComponent>;
|
||||
|
||||
// Mocks des services
|
||||
let mockToastrService: Partial<ToastrService>;
|
||||
let mockAuthRepository: jest.Mocked<Partial<AuthRepository>>;
|
||||
let mockProfileRepo: jest.Mocked<Partial<ProfileRepository>>;
|
||||
let mockToastrService: Partial<ToastrService> = mockToastR;
|
||||
let mockAuthRepository: jest.Mocked<Partial<AuthRepository>> = mockAuthRepo;
|
||||
let mockProfileRepository: jest.Mocked<Partial<ProfileRepository>> = mockProfileRepo;
|
||||
|
||||
beforeEach(async () => {
|
||||
mockToastrService = {
|
||||
warning: jest.fn(),
|
||||
success: jest.fn(),
|
||||
info: jest.fn(),
|
||||
error: jest.fn(),
|
||||
};
|
||||
|
||||
mockAuthRepository = {
|
||||
get: jest.fn(),
|
||||
login: jest.fn(),
|
||||
sendVerificationEmail: jest.fn(),
|
||||
logout: jest.fn(),
|
||||
isAuthenticated: jest.fn(),
|
||||
isEmailVerified: jest.fn(),
|
||||
register: jest.fn(),
|
||||
sendRequestPasswordReset: jest.fn(),
|
||||
confirmPasswordReset: jest.fn(),
|
||||
};
|
||||
|
||||
mockProfileRepo = {
|
||||
create: jest.fn(),
|
||||
list: jest.fn(),
|
||||
update: jest.fn(),
|
||||
getById: jest.fn(),
|
||||
};
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [LoginComponent],
|
||||
providers: [
|
||||
@@ -52,7 +29,7 @@ describe('LoginComponent', () => {
|
||||
provideRouter([]),
|
||||
{ provide: ToastrService, useValue: mockToastrService },
|
||||
{ provide: AUTH_REPOSITORY_TOKEN, useValue: mockAuthRepository },
|
||||
{ provide: PROFILE_REPOSITORY_TOKEN, useValue: mockProfileRepo },
|
||||
{ provide: PROFILE_REPOSITORY_TOKEN, useValue: mockProfileRepository },
|
||||
],
|
||||
}).compileComponents();
|
||||
|
||||
|
||||
@@ -7,47 +7,25 @@ import { ProfileRepository } from '@app/domain/profiles/profile.repository';
|
||||
import { PROFILE_REPOSITORY_TOKEN } from '@app/infrastructure/profiles/profile-repository.token';
|
||||
import { AUTH_REPOSITORY_TOKEN } from '@app/infrastructure/authentification/auth-repository.token';
|
||||
import { AuthRepository } from '@app/domain/authentification/auth.repository';
|
||||
import { mockToastR } from '@app/testing/toastr.mock';
|
||||
import { mockProfileRepo } from '@app/testing/profile.mock';
|
||||
import { mockAuthRepo } from '@app/testing/auth.mock';
|
||||
|
||||
describe('RegisterComponent', () => {
|
||||
let component: RegisterComponent;
|
||||
let fixture: ComponentFixture<RegisterComponent>;
|
||||
|
||||
let mockToastrService: jest.Mocked<Partial<ToastrService>>;
|
||||
let mockProfileRepo: jest.Mocked<Partial<ProfileRepository>>;
|
||||
let mockAuthRepository: jest.Mocked<Partial<AuthRepository>>;
|
||||
let mockToastrService: jest.Mocked<Partial<ToastrService>> = mockToastR;
|
||||
let mockProfileRepository: jest.Mocked<Partial<ProfileRepository>> = mockProfileRepo;
|
||||
let mockAuthRepository: jest.Mocked<Partial<AuthRepository>> = mockAuthRepo;
|
||||
|
||||
beforeEach(async () => {
|
||||
mockProfileRepo = {
|
||||
create: jest.fn(),
|
||||
list: jest.fn(),
|
||||
update: jest.fn(),
|
||||
getById: jest.fn(),
|
||||
};
|
||||
|
||||
mockToastrService = {
|
||||
success: jest.fn(),
|
||||
error: jest.fn(),
|
||||
warning: jest.fn(),
|
||||
};
|
||||
|
||||
mockAuthRepository = {
|
||||
get: jest.fn(),
|
||||
login: jest.fn(),
|
||||
sendVerificationEmail: jest.fn(),
|
||||
logout: jest.fn(),
|
||||
isAuthenticated: jest.fn(),
|
||||
isEmailVerified: jest.fn(),
|
||||
register: jest.fn(),
|
||||
sendRequestPasswordReset: jest.fn(),
|
||||
confirmPasswordReset: jest.fn(),
|
||||
};
|
||||
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [RegisterComponent],
|
||||
providers: [
|
||||
provideRouter([]),
|
||||
{ provide: ToastrService, useValue: mockToastrService },
|
||||
{ provide: PROFILE_REPOSITORY_TOKEN, useValue: mockProfileRepo },
|
||||
{ provide: PROFILE_REPOSITORY_TOKEN, useValue: mockProfileRepository },
|
||||
{ provide: AUTH_REPOSITORY_TOKEN, useValue: mockAuthRepository },
|
||||
],
|
||||
}).compileComponents();
|
||||
|
||||
@@ -4,37 +4,25 @@ import { SearchComponent } from './search.component';
|
||||
import { provideRouter } from '@angular/router';
|
||||
import { PROFILE_REPOSITORY_TOKEN } from '@app/infrastructure/profiles/profile-repository.token';
|
||||
import { SECTOR_REPOSITORY_TOKEN } from '@app/infrastructure/sectors/sector-repository.token';
|
||||
import { of } from 'rxjs';
|
||||
import { Profile } from '@app/domain/profiles/profile.model';
|
||||
import { ProfileRepository } from '@app/domain/profiles/profile.repository';
|
||||
import { SectorRepository } from '@app/domain/sectors/sector.repository';
|
||||
import { Sector } from '@app/domain/sectors/sector.model';
|
||||
import { mockProfileRepo } from '@app/testing/profile.mock';
|
||||
import { mockSectorRepo } from '@app/testing/sector.mock';
|
||||
|
||||
describe('SearchComponent', () => {
|
||||
let component: SearchComponent;
|
||||
let fixture: ComponentFixture<SearchComponent>;
|
||||
|
||||
let mockProfileRepo: jest.Mocked<Partial<ProfileRepository>>;
|
||||
let mockSectorRepo: jest.Mocked<Partial<SectorRepository>>;
|
||||
let mockProfileRepository: jest.Mocked<Partial<ProfileRepository>> = mockProfileRepo;
|
||||
let mockSectorRepository: jest.Mocked<Partial<SectorRepository>> = mockSectorRepo;
|
||||
|
||||
beforeEach(async () => {
|
||||
mockProfileRepo = {
|
||||
create: jest.fn().mockReturnValue(of({} as Profile)),
|
||||
list: jest.fn().mockReturnValue(of([])),
|
||||
getById: jest.fn().mockReturnValue(of({} as Profile)),
|
||||
update: jest.fn().mockReturnValue(of({} as Profile)),
|
||||
};
|
||||
|
||||
mockSectorRepo = {
|
||||
list: jest.fn().mockReturnValue(of([])),
|
||||
getOne: jest.fn().mockReturnValue(of({} as Sector)),
|
||||
};
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [SearchComponent],
|
||||
providers: [
|
||||
provideRouter([]),
|
||||
{ provide: PROFILE_REPOSITORY_TOKEN, useValue: mockProfileRepo },
|
||||
{ provide: SECTOR_REPOSITORY_TOKEN, useValue: mockSectorRepo },
|
||||
{ provide: PROFILE_REPOSITORY_TOKEN, useValue: mockProfileRepository },
|
||||
{ provide: SECTOR_REPOSITORY_TOKEN, useValue: mockSectorRepository },
|
||||
],
|
||||
}).compileComponents();
|
||||
|
||||
|
||||
@@ -5,28 +5,22 @@ import { provideRouter } from '@angular/router';
|
||||
import { UserRepository } from '@app/domain/users/user.repository';
|
||||
import { USER_REPOSITORY_TOKEN } from '@app/infrastructure/users/user-repository.token';
|
||||
import { ToastrService } from 'ngx-toastr';
|
||||
import { mockUserRepo } from '@app/testing/user.mock';
|
||||
import { mockToastR } from '@app/testing/toastr.mock';
|
||||
|
||||
describe('UpdateUserComponent', () => {
|
||||
let component: UpdateUserComponent;
|
||||
let fixture: ComponentFixture<UpdateUserComponent>;
|
||||
|
||||
let mockUserRepo: jest.Mocked<Partial<UserRepository>>;
|
||||
let mockToastrService: jest.Mocked<Partial<ToastrService>>;
|
||||
let mockUserRepository: jest.Mocked<Partial<UserRepository>> = mockUserRepo;
|
||||
let mockToastrService: jest.Mocked<Partial<ToastrService>> = mockToastR;
|
||||
|
||||
beforeEach(async () => {
|
||||
mockUserRepo = {
|
||||
getUserById: jest.fn(),
|
||||
};
|
||||
mockToastrService = {
|
||||
warning: jest.fn(),
|
||||
success: jest.fn(),
|
||||
error: jest.fn(),
|
||||
};
|
||||
await TestBed.configureTestingModule({
|
||||
imports: [UpdateUserComponent],
|
||||
providers: [
|
||||
provideRouter([]),
|
||||
{ provide: USER_REPOSITORY_TOKEN, useValue: mockUserRepo },
|
||||
{ provide: USER_REPOSITORY_TOKEN, useValue: mockUserRepository },
|
||||
{ provide: ToastrService, useValue: mockToastrService },
|
||||
],
|
||||
}).compileComponents();
|
||||
|
||||
11
src/app/testing/auth.mock.ts
Normal file
11
src/app/testing/auth.mock.ts
Normal file
@@ -0,0 +1,11 @@
|
||||
export const mockAuthRepo = {
|
||||
get: jest.fn(),
|
||||
login: jest.fn(),
|
||||
sendVerificationEmail: jest.fn(),
|
||||
logout: jest.fn(),
|
||||
isAuthenticated: jest.fn(),
|
||||
isEmailVerified: jest.fn(),
|
||||
register: jest.fn(),
|
||||
sendRequestPasswordReset: jest.fn(),
|
||||
confirmPasswordReset: jest.fn(),
|
||||
};
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Profile, ProfilePaginated } from '@app/domain/profiles/profile.model';
|
||||
import { of } from 'rxjs';
|
||||
|
||||
export const mockProfiles: Profile[] = [
|
||||
{
|
||||
@@ -38,3 +39,10 @@ export const mockProfilePaginated: ProfilePaginated = {
|
||||
totalItems: 1,
|
||||
items: mockProfiles,
|
||||
};
|
||||
|
||||
export const mockProfileRepo = {
|
||||
create: jest.fn().mockReturnValue(of({} as Profile)),
|
||||
list: jest.fn().mockReturnValue(of([])),
|
||||
getById: jest.fn().mockReturnValue(of({} as Profile)),
|
||||
update: jest.fn().mockReturnValue(of({} as Profile)),
|
||||
};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Project } from '@app/domain/projects/project.model';
|
||||
import { of } from 'rxjs';
|
||||
|
||||
export const fakeProjects: Project[] = [
|
||||
{
|
||||
@@ -57,3 +58,10 @@ export const fakeProjects: Project[] = [
|
||||
utilisateur: 'user_001',
|
||||
},
|
||||
];
|
||||
|
||||
export const mockProjectRepo = {
|
||||
create: jest.fn().mockReturnValue(of({} as Project)),
|
||||
list: jest.fn().mockReturnValue(of([])),
|
||||
get: jest.fn().mockReturnValue(of({} as Project)),
|
||||
update: jest.fn().mockReturnValue(of({} as Project)),
|
||||
};
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { Sector } from '@app/domain/sectors/sector.model';
|
||||
import { of } from 'rxjs';
|
||||
|
||||
export const fakeSectors: Sector[] = [
|
||||
{
|
||||
@@ -32,3 +33,8 @@ export const fakeSectors: Sector[] = [
|
||||
nom: 'Ressources humaines',
|
||||
},
|
||||
];
|
||||
|
||||
export const mockSectorRepo = {
|
||||
list: jest.fn().mockReturnValue(of([])),
|
||||
getOne: jest.fn().mockReturnValue(of({} as Sector)),
|
||||
};
|
||||
|
||||
6
src/app/testing/theme.mock.ts
Normal file
6
src/app/testing/theme.mock.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
import { signal } from '@angular/core';
|
||||
|
||||
export const mockThemeService = {
|
||||
darkModeSignal: signal<string>('null'),
|
||||
updateDarkMode: jest.fn(),
|
||||
};
|
||||
6
src/app/testing/toastr.mock.ts
Normal file
6
src/app/testing/toastr.mock.ts
Normal file
@@ -0,0 +1,6 @@
|
||||
export const mockToastR = {
|
||||
warning: jest.fn(),
|
||||
success: jest.fn(),
|
||||
info: jest.fn(),
|
||||
error: jest.fn(),
|
||||
};
|
||||
8
src/app/testing/ui/authentification/auth.facade.mock.ts
Normal file
8
src/app/testing/ui/authentification/auth.facade.mock.ts
Normal file
@@ -0,0 +1,8 @@
|
||||
import { signal } from '@angular/core';
|
||||
import { ActionType } from '@app/domain/action-type.util';
|
||||
|
||||
export const mockAuthenticationFacade = {
|
||||
sendRequestPasswordReset: jest.fn(),
|
||||
loading: signal({ isLoading: false, action: ActionType.NONE }),
|
||||
error: signal({ hasError: false }),
|
||||
};
|
||||
@@ -1,4 +1,5 @@
|
||||
import { User } from '@app/domain/users/user.model';
|
||||
import { of } from 'rxjs';
|
||||
|
||||
export const fakeUsers: User[] = [
|
||||
{
|
||||
@@ -13,3 +14,8 @@ export const fakeUsers: User[] = [
|
||||
verified: false,
|
||||
},
|
||||
];
|
||||
|
||||
export const mockUserRepo = {
|
||||
getUserById: jest.fn().mockReturnValue(of({} as User)),
|
||||
update: jest.fn(),
|
||||
};
|
||||
|
||||
@@ -2,6 +2,7 @@
|
||||
{
|
||||
"compileOnSave": false,
|
||||
"compilerOptions": {
|
||||
"skipLibCheck": true,
|
||||
"baseUrl": ".",
|
||||
"resolveJsonModule": true,
|
||||
"paths": {
|
||||
|
||||
Reference in New Issue
Block a user