Skip to content

Commit

Permalink
IS-2884: Move unntak-arsaker to ikke-aktuell
Browse files Browse the repository at this point in the history
  • Loading branch information
andersrognstad committed Jan 23, 2025
1 parent 6605767 commit b7da9ff
Show file tree
Hide file tree
Showing 7 changed files with 83 additions and 97 deletions.
42 changes: 6 additions & 36 deletions src/components/dialogmoteunntak/DialogmoteunntakSkjema.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import { Link, Navigate } from "react-router-dom";
import { moteoversiktRoutePath } from "@/routers/AppRouter";
import { useDialogmotekandidat } from "@/data/dialogmotekandidat/dialogmotekandidatQueryHooks";
import {
CreateUnntakArsak,
createUnntakArsakTexts,
CreateUnntakDTO,
UnntakArsak,
} from "@/data/dialogmotekandidat/types/dialogmoteunntakTypes";
import { useValgtPersonident } from "@/hooks/useValgtBruker";
import { useSettDialogmoteunntak } from "@/data/dialogmotekandidat/useSettDialogmoteunntak";
Expand All @@ -29,41 +30,10 @@ export const texts = {
avbryt: "Avbryt",
};

export interface UnntakArsakText {
arsak: UnntakArsak;
text: string;
}
export const unntakArsakTexts: UnntakArsakText[] = [
{
arsak: UnntakArsak.MEDISINSKE_GRUNNER,
text: "Medisinske grunner",
},
{
arsak: UnntakArsak.INNLEGGELSE_INSTITUSJON,
text: "Innleggelse i helseinstitusjon",
},
{
arsak: UnntakArsak.FRISKMELDT,
text: "Friskmeldt",
},
{
arsak: UnntakArsak.FORVENTET_FRISKMELDING_INNEN_28UKER,
text: "Forventet friskmelding innen 28 ukers sykmelding",
},
{
arsak: UnntakArsak.DOKUMENTERT_TILTAK_FRISKMELDING,
text: "Tiltak som sannsynligvis vil føre til en friskmelding",
},
{
arsak: UnntakArsak.ARBEIDSFORHOLD_OPPHORT,
text: "Arbeidsforholdet er opphørt",
},
];

export const dialogmoteunntakSkjemaBeskrivelseMaxLength = 2000;

export interface DialogmoteunntakSkjemaValues {
arsak: UnntakArsak;
arsak: CreateUnntakArsak;
beskrivelse?: string;
}

Expand Down Expand Up @@ -108,13 +78,13 @@ const DialogmoteunntakSkjema = () => {
size="small"
error={errors.arsak && texts.arsakErrorMessage}
>
{unntakArsakTexts.map((unntakArsakText, index) => (
{Object.entries(createUnntakArsakTexts).map(([key, tekst], index) => (
<Radio
key={index}
value={unntakArsakText.arsak}
value={key}
{...register("arsak", { required: true })}
>
{unntakArsakText.text}
{tekst}
</Radio>
))}
</RadioGroup>
Expand Down
10 changes: 10 additions & 0 deletions src/data/dialogmotekandidat/types/dialogmoteikkeaktuellTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,20 @@ export enum IkkeAktuellArsak {
ARBEIDSTAKER_AAP = "ARBEIDSTAKER_AAP",
ARBEIDSTAKER_DOD = "ARBEIDSTAKER_DOD",
DIALOGMOTE_AVHOLDT = "DIALOGMOTE_AVHOLDT",
FRISKMELDT = "FRISKMELDT",
ARBEIDSFORHOLD_OPPHORT = "ARBEIDSFORHOLD_OPPHORT",
}

export interface CreateIkkeAktuellDTO {
personIdent: string;
arsak: IkkeAktuellArsak;
beskrivelse?: string;
}

export const ikkeAktuellArsakTexts: Record<IkkeAktuellArsak, string> = {
[IkkeAktuellArsak.ARBEIDSTAKER_AAP]: "Innbygger mottar AAP",
[IkkeAktuellArsak.ARBEIDSTAKER_DOD]: "Innbygger er død",
[IkkeAktuellArsak.DIALOGMOTE_AVHOLDT]: "Dialogmøte avholdt",
[IkkeAktuellArsak.FRISKMELDT]: "Friskmeldt",
[IkkeAktuellArsak.ARBEIDSFORHOLD_OPPHORT]: "Arbeidsforholdet er opphørt",
};
24 changes: 23 additions & 1 deletion src/data/dialogmotekandidat/types/dialogmoteunntakTypes.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,28 @@ export enum UnntakArsak {
ARBEIDSFORHOLD_OPPHORT = "ARBEIDSFORHOLD_OPPHORT",
}

export enum CreateUnntakArsak {
MEDISINSKE_GRUNNER = "MEDISINSKE_GRUNNER",
INNLEGGELSE_INSTITUSJON = "INNLEGGELSE_INSTITUSJON",
FORVENTET_FRISKMELDING_INNEN_28UKER = "FORVENTET_FRISKMELDING_INNEN_28UKER",
DOKUMENTERT_TILTAK_FRISKMELDING = "DOKUMENTERT_TILTAK_FRISKMELDING",
}

export const createUnntakArsakTexts: Record<CreateUnntakArsak, string> = {
[UnntakArsak.MEDISINSKE_GRUNNER]: "Medisinske grunner",
[UnntakArsak.INNLEGGELSE_INSTITUSJON]: "Innleggelse i helseinstitusjon",
[UnntakArsak.FORVENTET_FRISKMELDING_INNEN_28UKER]:
"Forventet friskmelding innen 28 ukers sykmelding",
[UnntakArsak.DOKUMENTERT_TILTAK_FRISKMELDING]:
"Tiltak som sannsynligvis vil føre til en friskmelding",
};

export const unntakArsakTexts: Record<UnntakArsak, string> = {
...createUnntakArsakTexts,
[UnntakArsak.FRISKMELDT]: "Friskmeldt",
[UnntakArsak.ARBEIDSFORHOLD_OPPHORT]: "Arbeidsforholdet er opphørt",
};

export interface UnntakDTO {
uuid: string;
createdAt: Date;
Expand All @@ -18,6 +40,6 @@ export interface UnntakDTO {

export interface CreateUnntakDTO {
personIdent: string;
arsak: UnntakArsak;
arsak: CreateUnntakArsak;
beskrivelse?: string;
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import { useDialogmotekandidat } from "@/data/dialogmotekandidat/dialogmotekandi
import {
CreateIkkeAktuellDTO,
IkkeAktuellArsak,
ikkeAktuellArsakTexts,
} from "@/data/dialogmotekandidat/types/dialogmoteikkeaktuellTypes";
import { useValgtPersonident } from "@/hooks/useValgtBruker";
import { useSettDialogmoteIkkeAktuell } from "@/data/dialogmotekandidat/useSettDialogmoteIkkeAktuell";
Expand All @@ -29,25 +30,6 @@ export const texts = {
avbryt: "Avbryt",
};

export interface IkkeAktuellArsakText {
arsak: IkkeAktuellArsak;
text: string;
}
export const ikkeaktuellArsakTexts: IkkeAktuellArsakText[] = [
{
arsak: IkkeAktuellArsak.ARBEIDSTAKER_AAP,
text: "Innbygger mottar AAP",
},
{
arsak: IkkeAktuellArsak.ARBEIDSTAKER_DOD,
text: "Innbygger er død",
},
{
arsak: IkkeAktuellArsak.DIALOGMOTE_AVHOLDT,
text: "Dialogmøte avholdt",
},
];

export const skjemaBeskrivelseMaxLength = 2000;

interface SkjemaValues {
Expand Down Expand Up @@ -96,13 +78,13 @@ const DialogmoteIkkeAktuellSkjema = () => {
size="small"
error={errors.arsak && texts.arsakErrorMessage}
>
{ikkeaktuellArsakTexts.map((ikkeaktuellArsakText, index) => (
{Object.entries(ikkeAktuellArsakTexts).map(([key, tekst], index) => (
<Radio
key={index}
value={ikkeaktuellArsakText.arsak}
value={key}
{...register("arsak", { required: true })}
>
{ikkeaktuellArsakText.text}
{tekst}
</Radio>
))}
</RadioGroup>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,14 @@
import React, { ReactElement } from "react";
import { UnntakDTO } from "@/data/dialogmotekandidat/types/dialogmoteunntakTypes";
import {
unntakArsakTexts,
UnntakDTO,
} from "@/data/dialogmotekandidat/types/dialogmoteunntakTypes";
import { tilDatoMedManedNavn } from "@/utils/datoUtils";

import {
DocumentComponentDto,
DocumentComponentType,
} from "@/data/documentcomponent/documentComponentTypes";
import { unntakArsakTexts } from "@/components/dialogmoteunntak/DialogmoteunntakSkjema";
import { useVeilederInfoQuery } from "@/data/veilederinfo/veilederinfoQueryHooks";
import { ForhandsvisDocumentAccordionItem } from "@/sider/dialogmoter/components/motehistorikk/ForhandsvisDocumentAccordionItem";

Expand All @@ -26,10 +28,7 @@ function createUnntakDocument(
unntak: UnntakDTO,
veilederNavn: string | undefined
): DocumentComponentDto[] {
const arsakText: string =
unntakArsakTexts.find(
(unntakArsakText) => unntakArsakText.arsak == unntak.arsak
)?.text || unntak.arsak;
const arsakText: string = unntakArsakTexts[unntak.arsak] || unntak.arsak;
const componentList: DocumentComponentDto[] = [
{
type: DocumentComponentType.PARAGRAPH,
Expand Down
32 changes: 18 additions & 14 deletions test/dialogmoteikkeaktuell/DialogmoteikkeaktuellSkjemaTest.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,18 +16,22 @@ import { ValgtEnhetContext } from "@/context/ValgtEnhetContext";
import DialogmoteIkkeAktuellSkjema, {
skjemaBeskrivelseMaxLength,
texts as ikkeaktuellSkjemaTexts,
IkkeAktuellArsakText,
ikkeaktuellArsakTexts,
} from "@/sider/dialogmoter/components/ikkeaktuell/DialogmoteIkkeAktuellSkjema";
import { dialogmotekandidatQueryKeys } from "@/data/dialogmotekandidat/dialogmotekandidatQueryHooks";
import { ARBEIDSTAKER_DEFAULT } from "@/mocks/common/mockConstants";
import { dialogmotekandidatMock } from "@/mocks/isdialogmotekandidat/dialogmotekandidatMock";
import { CreateIkkeAktuellDTO } from "@/data/dialogmotekandidat/types/dialogmoteikkeaktuellTypes";
import {
CreateIkkeAktuellDTO,
IkkeAktuellArsak,
ikkeAktuellArsakTexts,
} from "@/data/dialogmotekandidat/types/dialogmoteikkeaktuellTypes";
import { renderWithRouter } from "../testRouterUtils";
import { dialogmoterQueryKeys } from "@/data/dialogmote/dialogmoteQueryHooks";

let queryClient: QueryClient;

const ikkeAktuellArsak = IkkeAktuellArsak.DIALOGMOTE_AVHOLDT;

describe("DialogmoteikkeaktuellSkjema", () => {
beforeEach(() => {
queryClient = queryClientWithMockData();
Expand Down Expand Up @@ -67,7 +71,7 @@ describe("DialogmoteikkeaktuellSkjema", () => {
const maxLengthErrorMsg = "1 tegn for mye";
expect(screen.getAllByText(maxLengthErrorMsg)).to.not.be.empty;

passSkjemaInput(ikkeaktuellArsakTexts[0], "beskrivelse");
passSkjemaInput(ikkeAktuellArsak, "beskrivelse");

// Feilmeldinger forsvinner
await waitFor(() => {
Expand All @@ -84,17 +88,16 @@ describe("DialogmoteikkeaktuellSkjema", () => {
it("sett ikke aktuell med kun med obligatorisk verdier fra skjema", async () => {
renderDialogmoteikkeaktuellSkjema();

expect(screen.getAllByRole("radio")).to.have.length(3);
expect(screen.getAllByRole("radio")).to.have.length(5);

const ikkeaktuellArsakText = ikkeaktuellArsakTexts[0];
passSkjemaInput(ikkeaktuellArsakText);
passSkjemaInput(ikkeAktuellArsak);

await clickButton(submitButtonText);
await waitFor(() => {
const ikkeaktuellMutation = queryClient.getMutationCache().getAll()[0];
const expectedCreateIkkeAktuellDTO: CreateIkkeAktuellDTO = {
personIdent: arbeidstaker.personident,
arsak: ikkeaktuellArsakText.arsak,
arsak: ikkeAktuellArsak,
beskrivelse: "",
};

Expand All @@ -107,20 +110,19 @@ describe("DialogmoteikkeaktuellSkjema", () => {
it("sett ikke aktuell med alle verdier fra skjema", async () => {
renderDialogmoteikkeaktuellSkjema();

expect(screen.getAllByRole("radio")).to.have.length(3);
expect(screen.getAllByRole("radio")).to.have.length(5);

const beskrivelse = "Dette er en begrunnelse";
const ikkeaktuellArsakText = ikkeaktuellArsakTexts[0];

passSkjemaInput(ikkeaktuellArsakText, beskrivelse);
passSkjemaInput(ikkeAktuellArsak, beskrivelse);

await clickButton(submitButtonText);

await waitFor(() => {
const ikkeaktuellMutation = queryClient.getMutationCache().getAll()[0];
const expectedCreateIkkeAktuellDTO: CreateIkkeAktuellDTO = {
personIdent: arbeidstaker.personident,
arsak: ikkeaktuellArsakText.arsak,
arsak: ikkeAktuellArsak,
beskrivelse,
};

Expand All @@ -146,10 +148,12 @@ const renderDialogmoteikkeaktuellSkjema = () => {
};

const passSkjemaInput = (
ikkeaktuellArsakText: IkkeAktuellArsakText,
ikkeaktuellArsak: IkkeAktuellArsak,
beskrivelse?: string
) => {
const arsakRadioButton = screen.getByText(ikkeaktuellArsakText.text);
const arsakRadioButton = screen.getByText(
ikkeAktuellArsakTexts[ikkeaktuellArsak]
);
fireEvent.click(arsakRadioButton);

if (beskrivelse) {
Expand Down
Loading

0 comments on commit b7da9ff

Please sign in to comment.