Skip to content

Commit

Permalink
feat(frontend): update list
Browse files Browse the repository at this point in the history
  • Loading branch information
pYassine committed Nov 19, 2024
1 parent b19cf05 commit e7470b1
Show file tree
Hide file tree
Showing 4 changed files with 95 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ import { ManageFiltersComponent } from "./manage-filters.component";
import { NgbModule } from "@ng-bootstrap/ng-bootstrap";
import { CUSTOM_ELEMENTS_SCHEMA } from "@angular/core";

import { ManageUsagersModule } from "../../manage-usagers.module";

describe("ManageFiltersComponent", () => {
let component: ManageFiltersComponent;
let fixture: ComponentFixture<ManageFiltersComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ManageFiltersComponent],
imports: [NgbModule],
imports: [NgbModule, ManageUsagersModule],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
}).compileComponents();

Expand All @@ -38,4 +40,69 @@ describe("ManageFiltersComponent", () => {
it("should create", () => {
expect(component).toBeTruthy();
});

describe("getSortKeys", () => {
it("devrait toujours retourner les éléments de tri de base", () => {
const result = component.getSortKeys();
expect(result).toContainEqual({ id: "ID", label: "ID" });
expect(result).toContainEqual({ id: "NAME", label: "nom" });
expect(result).toContainEqual({
id: "ECHEANCE",
label: expect.any(String),
});
});

it("devrait inclure PASSAGE quand statut est TOUS", () => {
component.filters = { ...component.filters, statut: "TOUS" };
const result = component.getSortKeys();
expect(result).toContainEqual({
id: "PASSAGE",
label: "dernier passage",
});
expect(result.length).toBe(4);
});

it("devrait inclure PASSAGE quand statut est VALIDE", () => {
component.filters = { ...component.filters, statut: "VALIDE" };
const result = component.getSortKeys();
expect(result).toContainEqual({
id: "PASSAGE",
label: "dernier passage",
});
expect(result.length).toBe(4);
});

it("ne devrait pas inclure PASSAGE pour les autres statuts", () => {
component.filters = { ...component.filters, statut: "RADIE" };
const result = component.getSortKeys();
expect(result).not.toContainEqual({
id: "PASSAGE",
label: "dernier passage",
});
expect(result.length).toBe(3);
});
});

describe("getEcheanceLabel", () => {
it('devrait retourner "radiation" quand statut est RADIE', () => {
component.filters = { ...component.filters, statut: "RADIE" };
expect(component.getEcheanceLabel()).toBe("radiation");
});

it('devrait retourner "refus" quand statut est REFUS', () => {
component.filters = { ...component.filters, statut: "REFUS" };
expect(component.getEcheanceLabel()).toBe("refus");
});

it('devrait retourner "échéance" pour tout autre statut', () => {
component.filters = { ...component.filters, statut: "VALIDE" };
expect(component.getEcheanceLabel()).toBe("échéance");

component.filters = { ...component.filters, statut: "TOUS" };
expect(component.getEcheanceLabel()).toBe("échéance");

component.filters = { ...component.filters, statut: undefined };
expect(component.getEcheanceLabel()).toBe("échéance");
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -252,7 +252,7 @@ export class ManageUsagersPageComponent
map(([filters, usagers]) => ({
filters,
usagers,
totalCount: usagersRadiesTotalCount,
usagersRadiesTotalCount,
}))
)
)
Expand All @@ -267,17 +267,21 @@ export class ManageUsagersPageComponent
return {
filters,
usagers,
totalCount: usagersRadiesTotalCount,
usagersRadiesTotalCount,
};
})
);
}),

takeUntil(this.destroy$)
)
.subscribe(({ filters, usagers, totalCount }) => {
.subscribe(({ filters, usagers, usagersRadiesTotalCount }) => {
if (filters && usagers) {
this.usagersRadiesTotalCount = totalCount;
this.usagersRadiesTotalCount = usagersRadiesTotalCount;
this.usagersCountByStatus = calculateUsagersCountByStatus(
usagers,
this.usagersRadiesTotalCount
);
this.applyFilters({ filters, allUsagers: usagers });
}
this.searching = false;
Expand Down Expand Up @@ -489,10 +493,6 @@ export class ManageUsagersPageComponent
}

this.usagersRadiesLoadedCount = radiesCount;
this.usagersCountByStatus = calculateUsagersCountByStatus(
allUsagers,
this.usagersRadiesTotalCount
);

localStorage.setItem("MANAGE_USAGERS", JSON.stringify(filters));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { UsagerLight } from "../../../../../../_common/model";
import { UsagerFormModel } from "../../../../usager-shared/interfaces";
import { usagersSorter } from "./usagersSorter.service";

const usagers = [
Expand All @@ -18,6 +19,10 @@ const usagers = [
nom: "Smith",
},
],
decision: {
statut: "RADIE",
dateFin: new Date(Date.UTC(2022, 8, 15)),
},
},
{
ref: 2,
Expand All @@ -33,6 +38,7 @@ const usagers = [
},
],
decision: {
statut: "RADIE",
dateFin: new Date(Date.UTC(2022, 8, 15)),
},
},
Expand All @@ -45,7 +51,7 @@ const usagers = [
email: "claire.meunier@vprovider2.org",
ayantsDroits: [],
decision: {
dateFin: new Date(Date.UTC(2022, 6, 15)),
dateFin: new Date(Date.UTC(2022, 6, 25)),
},
},
{
Expand All @@ -57,7 +63,8 @@ const usagers = [
email: undefined,
ayantsDroits: [],
decision: {
dateFin: new Date(Date.UTC(2021, 6, 15)),
statut: "RADIE",
dateFin: new Date(Date.UTC(2023, 6, 15)),
},
},
{
Expand All @@ -69,10 +76,11 @@ const usagers = [
email: undefined,
ayantsDroits: [],
decision: {
dateFin: new Date(Date.UTC(2021, 6, 16)),
statut: "RADIE",
dateFin: new Date(Date.UTC(2023, 6, 16)),
},
},
] as UsagerLight[];
].map((usager) => new UsagerFormModel(usager as UsagerLight));

it("usagersSorter NAME (nom, prenom)", () => {
const results = usagersSorter.sortBy(usagers, {
Expand All @@ -89,7 +97,12 @@ it("usagersSorter RADIE (usager.decision.dateFin)", () => {
sortValue: "desc",
});
expect(results.length).toEqual(usagers.length);
expect(results.map((x) => x.ref)).toEqual([2, 3, 5, 4, 1]); // null last
expect(
results.map((x) => {
console.log({ dateToDisplay: x.echeanceInfos.dateToDisplay, ref: x.ref });
return x.ref;
})
).toEqual([5, 4, 1, 2, 3]); // null last
});

it("usagersSorter customRef asc", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ function sortBy(
if (sortKey === "ID") {
return sortUsagersByCustomRef(usagers, asc);
}

return dataSorter.sortMultiple(usagers, {
getSortAttributes: (usager) => {
const sortAttributes: SortableAttribute[] = [];
Expand Down

0 comments on commit e7470b1

Please sign in to comment.