Skip to content

Commit

Permalink
fix(admin): fix admin test & build
Browse files Browse the repository at this point in the history
  • Loading branch information
pYassine committed Dec 17, 2024
1 parent 8fdc818 commit 0c1fc37
Show file tree
Hide file tree
Showing 16 changed files with 263 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,13 @@ import { NationalStatsComponent } from "./components/national-stats/national-sta
import { StatsService } from "./services/stats.service";
import { AdminStructuresTableComponent } from "./components/admin-structures-table/admin-structures-table.component";
import { TableHeadSortComponent } from "../shared/components/table-head-sort/table-head-sort.component";
import { StructureComponent } from "./components/structure/structure.component";
import { SortArrayPipe } from "../shared/pipes/sort-array.pipe";

@NgModule({
declarations: [
AdminStructuresListComponent,
AdminStructuresTableComponent,
NationalStatsComponent,
StructureComponent,
],
imports: [
CommonModule,
Expand All @@ -30,6 +29,7 @@ import { StructureComponent } from "./components/structure/structure.component";
FormsModule,
ReactiveFormsModule,
TableHeadSortComponent,
SortArrayPipe,
],
providers: [StatsService],
schemas: [CUSTOM_ELEMENTS_SCHEMA],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import { Pipe, PipeTransform } from "@angular/core";
import { compareAttributes } from "@domifa/common";

@Pipe({
name: "sortArray",
standalone: true,
})
export class SortArrayPipe implements PipeTransform {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
transform(array: any[], sortKey: string, sortValue: "asc" | "desc"): any[] {
if (!array || array.length <= 1) {
return array;
}

// eslint-disable-next-line @typescript-eslint/no-explicit-any
return array.sort((a: any, b: any) => {
const valA = a[sortKey];
const valB = b[sortKey];

return compareAttributes(valA, valB, sortValue === "asc");
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
<p>structure-page works!</p>
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
import { ComponentFixture, TestBed } from "@angular/core/testing";

import { StructureComponent } from "./structure.component";
import { StructurePageComponent } from "./structure-page.component";

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

beforeEach(async () => {
await TestBed.configureTestingModule({
imports: [StructureComponent],
imports: [StructurePageComponent],
}).compileComponents();

fixture = TestBed.createComponent(StructureComponent);
fixture = TestBed.createComponent(StructurePageComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { Component } from "@angular/core";

@Component({
selector: "app-structure-page",
standalone: true,
imports: [],
templateUrl: "./structure-page.component.html",
styleUrl: "./structure-page.component.css",
})
export class StructurePageComponent {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<div class="head-page pt-4">
<div class="head-page pt-4" *ngIf="structure">
<div class="container">
<div class="row">
<div class="col-md-9 col-12">
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { ComponentFixture, TestBed } from "@angular/core/testing";

import { StructureComponent } from "./structure.component";
import { CommonModule } from "@angular/common";
import { TableHeadSortComponent } from "../../../shared/components/table-head-sort/table-head-sort.component";
import { SortArrayPipe } from "../../../shared/pipes/sort-array.pipe";
import { AdminStructuresApiClient } from "../../../shared/services";
import { HttpClientTestingModule } from "@angular/common/http/testing";
import { RouterModule } from "@angular/router";

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

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [StructureComponent],
imports: [
CommonModule,
TableHeadSortComponent,
SortArrayPipe,
HttpClientTestingModule,
RouterModule.forRoot([]),
],
providers: [AdminStructuresApiClient],
}).compileComponents();

fixture = TestBed.createComponent(StructureComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it("should create", () => {
expect(component).toBeTruthy();
});
});
Empty file.
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<div class="content py-3">
<div class="container py-3">
<div class="page-content p-3">
<h2>Utilisateurs enregistrés: {{ users.length }} utilisateurs</h2>
<div class="table-responsive">
<table class="table" [attr.aria-rowcount]="users.length">
<caption class="visually-hidden">
Liste des utilisateurs enregistrés
</caption>
<thead>
<tr>
<th scope="col">
<app-table-head-sort
sortKey="nom"
[(sortValue)]="sortValue"
[(currentKey)]="currentKey"
columnName="Nom prénom"
>
</app-table-head-sort>
</th>
<th scope="col">
<app-table-head-sort
sortKey="email"
[(sortValue)]="sortValue"
[(currentKey)]="currentKey"
columnName="Email"
>
</app-table-head-sort>
</th>
<th scope="col">
<app-table-head-sort
sortKey="createdAt"
[(sortValue)]="sortValue"
[(currentKey)]="currentKey"
columnName="Date d'inscription"
>
</app-table-head-sort>
</th>
<th scope="col">
<app-table-head-sort
sortKey="lastLogin"
[(sortValue)]="sortValue"
[(currentKey)]="currentKey"
columnName="Statut"
>
</app-table-head-sort>
</th>
<th scope="col">
<app-table-head-sort
sortKey="role"
[(sortValue)]="sortValue"
[(currentKey)]="currentKey"
columnName="Rôle"
>
</app-table-head-sort>
</th>
</tr>
</thead>
<tbody>
<tr
*ngFor="
let user of users | sortArray : currentKey : sortValue;
let i = index
"
[attr.aria-rowindex]="i + 1"
>
<td class="fw-bold">{{ user.nom }} {{ user.prenom }}</td>
<td>{{ user.email }}</td>
<td>{{ user.createdAt | date : "d MMMM y" }}</td>
<td>
<p *ngIf="user.verified">✅ Compte actif</p>
<p *ngIf="!user.verified && user.lastLogin">
❌ Inactif depuis plus de 2 mois<br />Dernière connexion le
{{ user.lastLogin | date : "d MMMM y" }}
</p>
<p class="fw-bold" *ngIf="!user.verified && !user.lastLogin">
❌ Compte jamais utilisé
</p>
</td>
<td>
{{ USER_ROLES_LABELS[user.role] }}
</td>
</tr>
</tbody>
</table>
</div>
</div>
</div>
</div>
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
import { ComponentFixture, TestBed } from "@angular/core/testing";

import { UsersComponent } from "./users.component";
import { CommonModule } from "@angular/common";
import { HttpClientTestingModule } from "@angular/common/http/testing";
import { RouterModule } from "@angular/router";
import { TableHeadSortComponent } from "../../../shared/components/table-head-sort/table-head-sort.component";
import { SortArrayPipe } from "../../../shared/pipes/sort-array.pipe";
import { AdminStructuresApiClient } from "../../../shared/services";

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

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [UsersComponent],
imports: [
CommonModule,
TableHeadSortComponent,
SortArrayPipe,
HttpClientTestingModule,
RouterModule.forRoot([]),
],
providers: [AdminStructuresApiClient],
}).compileComponents();

fixture = TestBed.createComponent(UsersComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it("should create", () => {
expect(component).toBeTruthy();
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import { Component } from "@angular/core";
import { SortValues, UserStructure, UserStructureRole } from "@domifa/common";

@Component({
selector: "app-users",
templateUrl: "./users.component.html",
styleUrl: "./users.component.css",
})
export class UsersComponent {
public users: UserStructure[] = [];
public sortValue: SortValues = "asc";
public currentKey = "id";

public readonly USER_ROLES_LABELS: { [key in UserStructureRole]: string } = {
admin: "Administrateur",
responsable: "Gestionnaire",
simple: "Instructeur",
facteur: "Facteur",
};
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { NgModule } from "@angular/core";
import { RouterModule, Routes } from "@angular/router";
import { StructureComponent } from "./components/structure/structure.component";
import { UsersComponent } from "./components/users/users.component";

const routes: Routes = [
{ path: ":structureId", component: StructureComponent },
{ path: ":structureId/users0", component: UsersComponent },
];

@NgModule({
imports: [RouterModule.forChild(routes)],
exports: [RouterModule],
})
export class StructureRoutingModule {}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
import { NgModule } from "@angular/core";
import { CommonModule } from "@angular/common";
import { StructureComponent } from "./components/structure/structure.component";
import { FontAwesomeModule } from "@fortawesome/angular-fontawesome";
import { NgbModule } from "@ng-bootstrap/ng-bootstrap";
import { TableHeadSortComponent } from "../shared/components/table-head-sort/table-head-sort.component";
import { SharedModule } from "../shared/shared.module";
import { StructureRoutingModule } from "./structure-routing.module";
import { UsersComponent } from "./components/users/users.component";
import { SortArrayPipe } from "../shared/pipes/sort-array.pipe";

@NgModule({
declarations: [StructureComponent, UsersComponent],
imports: [
CommonModule,
NgbModule,
SharedModule,
FontAwesomeModule,
TableHeadSortComponent,
StructureRoutingModule,
SortArrayPipe,
],
})
export class StructureModule {}

0 comments on commit 0c1fc37

Please sign in to comment.