Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[QUESTIONNAIRE] Sous-question avec le bilan financier #189

Draft
wants to merge 7 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 7 additions & 6 deletions .github/workflows/node.js.yml
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,23 @@ jobs:

runs-on: ubuntu-latest

strategy:
matrix:
node-version: [ 18.x ]

steps:
- uses: actions/checkout@v3
- name: Use Node.js ${{ matrix.node-version }}

- name: Utilisation de la version Node.js 18
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
node-version: 18
cache: 'npm'

- name: Installation des dépendances
run: npm ci

- name: Vérification des règles de code
run: npm run lint

- name: Lancement des tests unitaires
run: npm test

- name: Construction des applications
run: npm run build --if-present
10 changes: 8 additions & 2 deletions .github/workflows/storybook-build.yml
Original file line number Diff line number Diff line change
@@ -1,23 +1,29 @@
name: 'Storybook Tests'
name: "Storybook Tests"
on: push
jobs:
test:
timeout-minutes: 60

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- uses: actions/setup-node@v3
with:
node-version: "16.x"

- name: Installe les dépendances
run: npm ci

- name: Installe Playwright
run: npx playwright install --with-deps chromium

- name: Construction de Storybook
run: npm run storybook:build -w anssi-nis2-ui

- name: Tests UI
run: |
npx concurrently -k -s first -n "SB,TEST" -c "magenta,blue" \
"npx http-server ./anssi-nis2-ui/storybook-static --port 6006 --silent" \
"npx wait-on tcp:6006 && npm run storybook:test -w anssi-nis2-ui"

Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import RadioButtons from "@codegouvfr/react-dsfr/RadioButtons";
import BlocPrincipal from "../../BlocPrincipal.tsx";
import { FormSimulateur } from "../Etapes";
import {
TrancheBilanFinancier,
TrancheChiffreAffaire,
TrancheNombreEmployes,
} from "anssi-nis2-core/src/Domain/Simulateur/ChampsSimulateur.definitions.ts";
Expand All @@ -17,6 +18,7 @@ export function EtapeTailleEntitePrivee({
onValider: (
nombre: TrancheNombreEmployes[],
chiffreAffaire: TrancheChiffreAffaire[],
bilanFinancier: TrancheBilanFinancier[],
) => void;
onPrecedent: () => void;
}) {
Expand All @@ -26,6 +28,9 @@ export function EtapeTailleEntitePrivee({
const [reponseChiffreAffaire, setReponseChiffreAffaire] = useState<
TrancheChiffreAffaire[]
>([]);
const [reponseBilanFinancier, setReponseBilanFinancier] = useState<
TrancheBilanFinancier[]
>([]);

return (
<BlocPrincipal className="fond-gris" id="etape-formulaire">
Expand Down Expand Up @@ -79,33 +84,78 @@ export function EtapeTailleEntitePrivee({
},
},
{
label:
"10 à 50 millions €, ou bilan annuel de 10 à 43 millions €",
label: "10 à 50 millions €",
nativeInputProps: {
checked: reponseChiffreAffaire[0] === "moyen",
onChange: () => setReponseChiffreAffaire(["moyen"]),
},
},
{
label: "≥ 50 millions €, ou bilan annuel ≥ 43 millions €",
label: "≥ 50 millions €",
nativeInputProps: {
checked: reponseChiffreAffaire[0] === "grand",
onChange: () => setReponseChiffreAffaire(["grand"]),
},
},
]}
/>
{doitDemanderBilanFinancier(reponseNombre, reponseChiffreAffaire) && (
<RadioButtons
legend="Bilan financier annuel de l'année passée"
options={[
{
label: "< 10 millions €",
nativeInputProps: {
checked: reponseBilanFinancier[0] === "petit",
onChange: () => setReponseBilanFinancier(["petit"]),
},
},
{
label: "10 à 43 millions €",
nativeInputProps: {
checked: reponseBilanFinancier[0] === "moyen",
onChange: () => setReponseBilanFinancier(["moyen"]),
},
},
{
label: "≥ 43 millions €",
nativeInputProps: {
checked: reponseBilanFinancier[0] === "grand",
onChange: () => setReponseBilanFinancier(["grand"]),
},
},
]}
/>
)}
</div>
</FormSimulateur>

<PrecedentSuivant
message="Sélectionnez une réponse pour chaque critère"
onSuivant={() => onValider(reponseNombre, reponseChiffreAffaire)}
onSuivant={() =>
onValider(reponseNombre, reponseChiffreAffaire, reponseBilanFinancier)
}
suivantDisabled={
reponseNombre.length === 0 || reponseChiffreAffaire.length === 0
reponseNombre.length === 0 ||
reponseChiffreAffaire.length === 0 ||
(doitDemanderBilanFinancier(reponseNombre, reponseChiffreAffaire) &&
reponseBilanFinancier.length === 0)
}
onPrecedent={onPrecedent}
/>
</BlocPrincipal>
);
}

function doitDemanderBilanFinancier(
trancheNombre: TrancheNombreEmployes[],
trancheCa: TrancheChiffreAffaire[],
): boolean {
const [nombre] = trancheNombre;
const [ca] = trancheCa;

if (nombre === "petit" && (ca === "moyen" || ca === "grand")) return true;
if (nombre === "moyen" && ca === "grand") return true;

return false;
}
10 changes: 8 additions & 2 deletions anssi-nis2-ui/src/Components/Simulateur/Questionnaire.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -89,8 +89,14 @@ export const Questionnaire = ({
return (
<AvecDemandeDeFeedback>
<EtapeTailleEntitePrivee
onValider={(nombre, chiffreAffaire) =>
dispatch(valideTailleEntitePrivee(nombre, chiffreAffaire))
onValider={(nombre, chiffreAffaire, bilanFinancier) =>
dispatch(
valideTailleEntitePrivee(
nombre,
chiffreAffaire,
bilanFinancier,
),
)
}
onPrecedent={() => dispatch(undo())}
/>
Expand Down
4 changes: 2 additions & 2 deletions anssi-nis2-ui/src/References/Libelles.ts
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ export const libellesTranchesNombreEmployes: Record<

export const libellesTranchesCA: Record<TrancheChiffreAffaire, string> = {
petit: "< 10 millions €",
moyen: "10 à 50 millions €, ou bilan annuel de 10 à 43 millions €",
grand: "≥ 50 millions €, ou bilan annuel ≥ 43 millions €",
moyen: "10 à 50 millions €",
grand: "≥ 50 millions €",
};

export const libellesSimulateur: DictionnaireLibellesSimulateur = {
Expand Down
4 changes: 4 additions & 0 deletions anssi-nis2-ui/src/questionnaire/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Activite } from "anssi-nis2-core/src/Domain/Simulateur/Activite.definit
import {
AppartenancePaysUnionEuropeenne,
DesignationOperateurServicesEssentiels,
TrancheBilanFinancier,
TrancheChiffreAffaire,
TrancheNombreEmployes,
TypeStructure,
Expand Down Expand Up @@ -49,6 +50,7 @@ interface ActionValideTailleEntitePrivee {
type: "VALIDE_ETAPE_TAILLE_ENTITE_PRIVEE";
nombreEmployes: TrancheNombreEmployes[];
chiffreAffaire: TrancheChiffreAffaire[];
bilanFinancier: TrancheBilanFinancier[];
}

interface ActionValideSecteursActivite {
Expand Down Expand Up @@ -106,10 +108,12 @@ export const valideTypeStructure = (
export const valideTailleEntitePrivee = (
nombreEmployes: TrancheNombreEmployes[],
chiffreAffaire: TrancheChiffreAffaire[],
bilanFinancier: TrancheBilanFinancier[],
): ActionValideTailleEntitePrivee => ({
type: "VALIDE_ETAPE_TAILLE_ENTITE_PRIVEE",
nombreEmployes,
chiffreAffaire,
bilanFinancier,
});

export const valideSecteursActivite = (
Expand Down
4 changes: 4 additions & 0 deletions anssi-nis2-ui/src/questionnaire/reducerQuestionnaire.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { Activite } from "anssi-nis2-core/src/Domain/Simulateur/Activite.definit
import {
AppartenancePaysUnionEuropeenne,
DesignationOperateurServicesEssentiels,
TrancheBilanFinancier,
TrancheChiffreAffaire,
TrancheNombreEmployes,
TypeEntitePublique,
Expand Down Expand Up @@ -33,6 +34,7 @@ export type EtatQuestionnaire = {
typeStructure: TypeStructure[];
trancheNombreEmployes: TrancheNombreEmployes[];
trancheChiffreAffaire: TrancheChiffreAffaire[];
trancheBilanFinancier: TrancheBilanFinancier[];
secteurActivite: SecteurActivite[];
sousSecteurActivite: SousSecteurActivite[];
activites: Activite[];
Expand All @@ -50,6 +52,7 @@ export const etatParDefaut: EtatQuestionnaire = {
typeStructure: [],
trancheNombreEmployes: [],
trancheChiffreAffaire: [],
trancheBilanFinancier: [],
secteurActivite: [],
sousSecteurActivite: [],
activites: [],
Expand Down Expand Up @@ -107,6 +110,7 @@ const valideEtape = (
return vaVers("secteursActivite", {
trancheNombreEmployes: action.nombreEmployes,
trancheChiffreAffaire: action.chiffreAffaire,
trancheBilanFinancier: action.bilanFinancier,
});
case "VALIDE_ETAPE_SECTEURS_ACTIVITE":
return vaVers(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,21 +11,36 @@ export class RegleTaille implements Regle {
evalue(etat: EtatQuestionnaire): boolean {
const employes = etat.trancheNombreEmployes;
const ca = etat.trancheChiffreAffaire;
const bilan = etat.trancheBilanFinancier;

let tailleReelle: UnionPetitMoyenGrand | undefined;

const employesPetit = contientUnParmi("petit")(employes);
if (employesPetit) {
if (contientUnParmi("petit")(ca)) tailleReelle = "petit";
if (contientUnParmi("moyen")(ca)) tailleReelle = "moyen";
if (contientUnParmi("grand")(ca)) tailleReelle = "grand";

if (contientUnParmi("moyen")(ca)) {
if (contientUnParmi("petit")(bilan)) tailleReelle = "petit";
if (contientUnParmi("moyen")(bilan)) tailleReelle = "moyen";
if (contientUnParmi("grand")(bilan)) tailleReelle = "moyen";
}

if (contientUnParmi("grand")(ca)) {
if (contientUnParmi("petit")(bilan)) tailleReelle = "petit";
if (contientUnParmi("moyen")(bilan)) tailleReelle = "moyen";
if (contientUnParmi("grand")(bilan)) tailleReelle = "grand";
}
}

const employesMoyen = contientUnParmi("moyen")(employes);
if (employesMoyen) {
if (contientUnParmi("petit")(ca)) tailleReelle = "moyen";
if (contientUnParmi("moyen")(ca)) tailleReelle = "moyen";
if (contientUnParmi("grand")(ca)) tailleReelle = "grand";
if (contientUnParmi("grand")(ca)) {
if (contientUnParmi("petit")(bilan)) tailleReelle = "moyen";
if (contientUnParmi("moyen")(bilan)) tailleReelle = "moyen";
if (contientUnParmi("grand")(bilan)) tailleReelle = "grand";
}
}

if (contientUnParmi("grand")(employes)) tailleReelle = "grand";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,12 +81,15 @@ describe("Le reducer du Questionnaire", () => {
describe("à la validation de l'étape « Taille d'entité privée »", () => {
let etat: EtatQuestionnaire;
beforeEach(() => {
etat = executer([valideTailleEntitePrivee(["petit"], ["moyen"])]);
etat = executer([
valideTailleEntitePrivee(["petit"], ["moyen"], ["grand"]),
]);
});

it("sauvegarde les informations de l'étape", () => {
expect(etat.trancheNombreEmployes).toEqual(["petit"]);
expect(etat.trancheChiffreAffaire).toEqual(["moyen"]);
expect(etat.trancheBilanFinancier).toEqual(["grand"]);
});

it("passe à l'étape « Secteurs d'activité »", () => {
Expand Down
Loading
Loading