Skip to content

Commit

Permalink
fix(frontend): update unit test mocks
Browse files Browse the repository at this point in the history
  • Loading branch information
pYassine committed Aug 23, 2024
1 parent 38b1853 commit e817092
Show file tree
Hide file tree
Showing 66 changed files with 250 additions and 168 deletions.
1 change: 0 additions & 1 deletion packages/common/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ export * from "./_core";
export * from "./import";
export * from "./interactions";
export * from "./message-sms";
export * from "./mocks";
export * from "./pagination";
export * from "./stats";
export * from "./structure";
Expand Down
2 changes: 1 addition & 1 deletion packages/common/src/mocks/USAGER_ACTIF.mock.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { ETAPE_DOSSIER_COMPLET } from "../usager";

export const USAGER_ACTIF_MOCK = {
export const USAGER_VALIDE_MOCK = {
numeroDistribution: null,
decision: {
statut: "VALIDE",
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { USAGER_ACTIF_MOCK } from "../../mocks";
import { USAGER_VALIDE_MOCK } from "../../mocks";
import {
ETAPE_RENDEZ_VOUS,
ETAPE_DOSSIER_COMPLET,
Expand Down Expand Up @@ -68,7 +68,7 @@ describe("Création des rendez-vous", () => {
});

it("Rendez-vous de base", () => {
const usager = USAGER_ACTIF_MOCK;
const usager = USAGER_VALIDE_MOCK;
usager.rdv = { dateRdv: null, userId: 0, userName: "" };
expect(getRdvInfos(usager)).toEqual({
class: "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { CountryISO } from "@khazii/ngx-intl-tel-input";
import { UsagerLight } from "../model";
import { ETAPE_DOSSIER_COMPLET } from "@domifa/common";

export const USAGER_ACTIF_MOCK: UsagerLight = {
export const USAGER_VALIDE_MOCK: UsagerLight = {
numeroDistribution: null,
statut: "VALIDE",
decision: {
Expand All @@ -20,7 +20,7 @@ export const USAGER_ACTIF_MOCK: UsagerLight = {
userName: "Testeur Robin",
},
lastInteraction: {
colisIn: 0,
colisIn: 10,
courrierIn: 0,
enAttente: false,
recommandeIn: 0,
Expand Down
2 changes: 1 addition & 1 deletion packages/frontend/src/_common/mocks/index.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// @index('./*', f => `export * from '${f.path}'`)
export * from "./AuthServiceMock";
export * from "./STRUCTURE_MOCK.const";
export * from "./USAGER_ACTIF.mock";
export * from "./USAGER_VALIDE.mock";
export * from "./USAGER_NOTE.mock";
export * from "./USAGER_REFUS.mock";
export * from "./USER_STRUCTURE.mock";
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { UsagerFormModel } from "./../../../usager-shared/interfaces/UsagerFormM
import { ComponentFixture, TestBed } from "@angular/core/testing";

import { ColumnInformationsComponent } from "./column-informations.component";
import { USAGER_ACTIF_MOCK } from "../../../../../_common/mocks";
import { USAGER_VALIDE_MOCK } from "../../../../../_common/mocks";
import { APP_BASE_HREF } from "@angular/common";
import { CUSTOM_ELEMENTS_SCHEMA } from "@angular/core";
import { NgbModule } from "@ng-bootstrap/ng-bootstrap";
Expand All @@ -22,7 +22,7 @@ describe("ColumnInformationsComponent", () => {

fixture = TestBed.createComponent(ColumnInformationsComponent);
component = fixture.componentInstance;
component.usager = new UsagerFormModel(USAGER_ACTIF_MOCK);
component.usager = new UsagerFormModel(USAGER_VALIDE_MOCK);
fixture.detectChanges();
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { HttpClientTestingModule } from "@angular/common/http/testing";
import { ComponentFixture, TestBed } from "@angular/core/testing";
import {
USAGER_ACTIF_MOCK,
USAGER_VALIDE_MOCK,
USER_STRUCTURE_MOCK,
} from "../../../../../_common/mocks";
import { UsagerFormModel } from "../../../usager-shared/interfaces";
Expand Down Expand Up @@ -29,7 +29,7 @@ describe("ManageDownloadDocsComponent", () => {
component = fixture.componentInstance;
component.me = USER_STRUCTURE_MOCK;
component.me.structure = USER_STRUCTURE_MOCK.structure;
component.usager = new UsagerFormModel(USAGER_ACTIF_MOCK);
component.usager = new UsagerFormModel(USAGER_VALIDE_MOCK);
fixture.detectChanges();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -259,9 +259,11 @@ export class ManageUsagersPageComponent implements OnInit, OnDestroy {
usagers: UsagerLight[],
usagersRadiesTotalCount: number
) {
this.usagersCountByStatus = calculateUsagersCountByStatus(usagers);
this.usagersCountByStatus.RADIE = usagersRadiesTotalCount;
this.usagersCountByStatus.TOUS = usagers.length;
this.usagersCountByStatus = calculateUsagersCountByStatus(
usagers,
usagersRadiesTotalCount
);

this.usagersRadiesLoadedCount = usagers.filter(
(usager) => usager.statut === "RADIE"
).length;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -157,8 +157,8 @@
</label>
</td>
<td *ngIf="filters.statut === 'TOUS'" class="clickable text-start">
<span [class]="'label-info ' + usager?.statusInfos?.color">
{{ usager?.statusInfos?.text }}</span
<span [class]="'label-info ' + usager?.statusInfo?.color">
{{ usager?.statusInfo?.text }}</span
>
</td>
<td
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@ import { UsagersCountByStatus } from "..";
import { UsagerLight } from "../../../../../../_common/model";

export function calculateUsagersCountByStatus(
usagers: UsagerLight[]
usagers: UsagerLight[],
usagersRadiesTotalCount: number
): UsagersCountByStatus {
return usagers.reduce(
const counters = usagers.reduce(
(count, usager) => {
// We skip "RADIE" already count by backend
if (usager.statut !== "RADIE") {
count[usager.statut]++;
count.TOUS++;
}
return count;
},
Expand All @@ -21,4 +23,7 @@ export function calculateUsagersCountByStatus(
TOUS: 0,
}
);
counters.TOUS = counters.TOUS + usagersRadiesTotalCount;
counters.RADIE = usagersRadiesTotalCount;
return counters;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,11 @@ import { environment } from "src/environments/environment";
import { UsagerLight } from "../../../../_common/model/usager/UsagerLight.type";

import { Store } from "@ngrx/store";
import { setUsagerInformation, usagerActions } from "../../../shared";
import {
setUsagerInformation,
usagerActions,
UsagerState,
} from "../../../shared";

@Injectable({
providedIn: "root",
Expand All @@ -17,7 +21,7 @@ export class ManageUsagersService {

constructor(
private readonly http: HttpClient,
private readonly store: Store
private readonly store: Store<UsagerState>
) {}

public fetchSearchPageUsagerData({
Expand Down Expand Up @@ -82,11 +86,13 @@ export class ManageUsagersService {
return this.http
.get<UsagerLight[]>(`${environment.apiUrl}usagers/update-manage`)
.pipe(
tap((usagers: UsagerLight[]) =>
this.store.dispatch(
usagerActions.updateManyUsagersForManage({ usagers })
)
)
tap((usagers: UsagerLight[]) => {
if (usagers?.length) {
this.store.dispatch(
usagerActions.updateManyUsagersForManage({ usagers })
);
}
})
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import { AuthService } from "../../../shared/services/auth.service";
import { StructureService } from "../../services/structure.service";
import { UserStructure, StructureCommon } from "@domifa/common";
import { Store } from "@ngrx/store";
import { usagerActions } from "../../../../shared";
import { usagerActions, UsagerState } from "../../../../shared";

@Component({
selector: "app-structures-edit",
Expand All @@ -41,7 +41,7 @@ export class StructuresEditComponent implements OnInit, OnDestroy {
private readonly authService: AuthService,
private readonly modalService: NgbModal,
private readonly titleService: Title,
private readonly store: Store
private readonly store: Store<UsagerState>
) {
this.showHardReset = false;
this.exportLoading = false;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { Component, OnDestroy, OnInit } from "@angular/core";
import { Title } from "@angular/platform-browser";
import { ActivatedRoute, Router } from "@angular/router";
import { filter, Observable, Subscription } from "rxjs";
import { Observable, Subscription } from "rxjs";

import { Store } from "@ngrx/store";
import { UsagerLight } from "../../../../../_common/model";
Expand Down Expand Up @@ -45,17 +45,14 @@ export class BaseUsagerDossierPageComponent implements OnInit, OnDestroy {
public ngOnInit(): void {
const id = this.route.snapshot.params.id;
this.subscription.add(
this.store
.select(selectUsagerById(id))
.pipe(filter((usager): usager is UsagerLight => !!usager))
.subscribe({
next: (usager: UsagerLight) => {
this.usager = new UsagerFormModel(usager);
},
error: (error) => {
console.error("Erreur lors de la récupération du dossier:", error);
},
})
this.store.select(selectUsagerById(id)).subscribe({
next: (usager: UsagerLight) => {
this.usager = new UsagerFormModel(usager);
},
error: (error) => {
console.error("Erreur lors de la récupération du dossier:", error);
},
})
);

this.subscription.add(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { FormsModule, ReactiveFormsModule } from "@angular/forms";
import { RouterTestingModule } from "@angular/router/testing";
import { NgbModule } from "@ng-bootstrap/ng-bootstrap";

import { USAGER_ACTIF_MOCK } from "../../../../../_common/mocks/USAGER_ACTIF.mock";
import { USAGER_VALIDE_MOCK } from "../../../../../_common/mocks/USAGER_VALIDE.mock";
import { SharedModule } from "../../../shared/shared.module";
import { UsagerFormModel } from "../../../usager-shared/interfaces";

Expand Down Expand Up @@ -41,7 +41,7 @@ describe("DecisionRefusFormComponent", () => {
beforeEach(() => {
fixture = TestBed.createComponent(DecisionRefusFormComponent);
component = fixture.componentInstance;
component.usager = new UsagerFormModel(USAGER_ACTIF_MOCK);
component.usager = new UsagerFormModel(USAGER_VALIDE_MOCK);
fixture.detectChanges();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { HttpClientTestingModule } from "@angular/common/http/testing";
import { UsagerFormModel } from "../../../usager-shared/interfaces";
import {
USER_STRUCTURE_MOCK,
USAGER_ACTIF_MOCK,
USAGER_VALIDE_MOCK,
} from "../../../../../_common/mocks";
import { APP_BASE_HREF } from "@angular/common";
import { CUSTOM_ELEMENTS_SCHEMA } from "@angular/core";
Expand Down Expand Up @@ -33,7 +33,7 @@ describe("DecisionStandbyFormComponent", () => {
fixture = TestBed.createComponent(DecisionStandbyFormComponent);
component = fixture.componentInstance;
component.me = USER_STRUCTURE_MOCK;
component.usager = new UsagerFormModel(USAGER_ACTIF_MOCK);
component.usager = new UsagerFormModel(USAGER_VALIDE_MOCK);
fixture.detectChanges();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import {
NgbModule,
} from "@ng-bootstrap/ng-bootstrap";

import { USAGER_ACTIF_MOCK } from "../../../../../_common/mocks/USAGER_ACTIF.mock";
import { USAGER_VALIDE_MOCK } from "../../../../../_common/mocks/USAGER_VALIDE.mock";
import { NgbDateCustomParserFormatter } from "../../../shared/services/date-formatter.service";
import { CustomDatepickerI18n } from "../../../shared/services/date-french.service";
import { SharedModule } from "../../../shared/shared.module";
Expand Down Expand Up @@ -54,7 +54,7 @@ describe("DecisionValideFormComponent", () => {
beforeEach(() => {
fixture = TestBed.createComponent(DecisionValideFormComponent);
component = fixture.componentInstance;
component.usager = new UsagerFormModel(USAGER_ACTIF_MOCK);
component.usager = new UsagerFormModel(USAGER_VALIDE_MOCK);
fixture.detectChanges();
});

Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import { ComponentFixture, TestBed } from "@angular/core/testing";

import { DisplayContactDetailsDecisionComponent } from "./display-contact-details-decision.component";
import { USAGER_ACTIF_MOCK } from "../../../../../_common/mocks";
import { USAGER_VALIDE_MOCK } from "../../../../../_common/mocks";
import { UsagerFormModel } from "../../../usager-shared/interfaces";
import { FormatInternationalPhoneNumberPipe } from "../../../usager-shared/formatInternationalPhoneNumber.pipe";

Expand All @@ -17,7 +17,7 @@ describe("DisplayContactDetailsDecisionComponent", () => {

fixture = TestBed.createComponent(DisplayContactDetailsDecisionComponent);
component = fixture.componentInstance;
component.usager = new UsagerFormModel(USAGER_ACTIF_MOCK);
component.usager = new UsagerFormModel(USAGER_VALIDE_MOCK);
fixture.detectChanges();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import { NO_ERRORS_SCHEMA } from "@angular/core";

import { DisplayEtatCivilDecisionComponent } from "./display-etat-civil-decision.component";
import { FormatInternationalPhoneNumberPipe } from "../../../usager-shared/formatInternationalPhoneNumber.pipe";
import { USAGER_ACTIF_MOCK } from "../../../../../_common/mocks";
import { USAGER_VALIDE_MOCK } from "../../../../../_common/mocks";
import { UsagerFormModel } from "../../../usager-shared/interfaces";

describe("DisplayEtatCivilDecisionComponent", () => {
Expand All @@ -18,7 +18,7 @@ describe("DisplayEtatCivilDecisionComponent", () => {
});
fixture = TestBed.createComponent(DisplayEtatCivilDecisionComponent);
component = fixture.componentInstance;
component.usager = new UsagerFormModel(USAGER_ACTIF_MOCK);
component.usager = new UsagerFormModel(USAGER_VALIDE_MOCK);
});

it("can load instance", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { ReactiveFormsModule, FormsModule } from "@angular/forms";

import { NgbModule } from "@ng-bootstrap/ng-bootstrap";

import { USAGER_ACTIF_MOCK } from "../../../../../_common/mocks/USAGER_ACTIF.mock";
import { USAGER_VALIDE_MOCK } from "../../../../../_common/mocks/USAGER_VALIDE.mock";
import { SharedModule } from "../../../shared/shared.module";
import { UsagerFormModel } from "../../../usager-shared/interfaces";
import { StepRdvComponent } from "./step-rdv.component";
Expand Down Expand Up @@ -40,7 +40,7 @@ describe("StepRdvComponent", () => {
beforeEach(() => {
fixture = TestBed.createComponent(StepRdvComponent);
component = fixture.debugElement.componentInstance;
component.usager = new UsagerFormModel(USAGER_ACTIF_MOCK);
component.usager = new UsagerFormModel(USAGER_VALIDE_MOCK);
});

it("should create", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,18 @@ import {
import { userStructureBuilder } from "../../users/services";
import { Store } from "@ngrx/store";
import { UserStructure, Usager } from "@domifa/common";
import { usagerActions } from "../../../shared";
import { usagerActions, UsagerState } from "../../../shared";

@Injectable({
providedIn: "root",
})
export class UsagerDossierService {
public endPointUsagers = environment.apiUrl + "usagers";

constructor(private readonly http: HttpClient, private store: Store) {}
constructor(
private readonly http: HttpClient,
private store: Store<UsagerState>
) {}

public editStepEtatCivil(
usager: UsagerEtatCivilFormData,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { HttpClientTestingModule } from "@angular/common/http/testing";
import { CUSTOM_ELEMENTS_SCHEMA } from "@angular/core";
import { NgbModule } from "@ng-bootstrap/ng-bootstrap";
import {
USAGER_ACTIF_MOCK,
USAGER_VALIDE_MOCK,
USER_STRUCTURE_MOCK,
} from "../../../../../_common/mocks";
import { UsagerFormModel } from "../../../usager-shared/interfaces";
Expand All @@ -29,7 +29,7 @@ describe("BaseUsagerNotesComponent", () => {

fixture = TestBed.createComponent(BaseUsagerNotesComponent);
component = fixture.componentInstance;
component.usager = new UsagerFormModel(USAGER_ACTIF_MOCK);
component.usager = new UsagerFormModel(USAGER_VALIDE_MOCK);
component.me = USER_STRUCTURE_MOCK;

fixture.detectChanges();
Expand Down
Loading

0 comments on commit e817092

Please sign in to comment.