-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
La til sykefraværsstatistikkpanel for aktiviteter.
- Loading branch information
Showing
11 changed files
with
534 additions
and
210 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
.statistikk { | ||
display: flex; | ||
flex-direction: column; | ||
align-items: center; | ||
gap: 1rem; | ||
border-radius: var(--a-border-radius-medium); | ||
} | ||
|
||
.gråBakgrunn { | ||
--ac-panel-bg: var(--a-bg-subtle); | ||
} | ||
|
||
.tittel { | ||
font-weight: 600; | ||
} | ||
|
||
.tallContainer { | ||
display: flex; | ||
align-items: center; | ||
gap: 0.625rem; | ||
border: none; | ||
} | ||
|
||
.rotateOpp { | ||
transform: rotate(45deg); | ||
} | ||
|
||
.rotateNed { | ||
transform: rotate(135deg); | ||
} | ||
|
||
.rotateUendret { | ||
transform: rotate(90deg); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import { StatistikkPanel } from "./StatistikkPanel"; | ||
import { axe } from "jest-axe"; | ||
|
||
describe("StatistikkPanel", () => { | ||
it("Har ingen axe feil når bakgrunn er hvit", async () => { | ||
const { container } = render( | ||
<StatistikkPanel | ||
sykefravær="10" | ||
tittel="Sykefravær i virksomhet" | ||
tooltip="Din virksomhet" | ||
/> | ||
); | ||
const results = await axe(container); | ||
expect(results).toHaveNoViolations(); | ||
}); | ||
|
||
it("Har ingen axe feil når bakgrunn er grå", async () => { | ||
const { container } = render( | ||
<StatistikkPanel | ||
sykefravær="10" | ||
tittel="Sykefravær i virksomhet" | ||
tooltip="Din virksomhet" | ||
/> | ||
); | ||
const results = await axe(container); | ||
expect(results).toHaveNoViolations(); | ||
}); | ||
|
||
it("Viser 'uendret trend' når trend ikke er gitt til komponenten", async () => { | ||
render( | ||
<StatistikkPanel | ||
sykefravær="10" | ||
tittel="Sykefravær i virksomhet" | ||
tooltip="Din virksomhet" | ||
/> | ||
); | ||
expect( | ||
screen.getByRole("img", { | ||
name: /uendret trend/i, | ||
}) | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it("Viser stigende trend", async () => { | ||
render( | ||
<StatistikkPanel | ||
sykefravær="10" | ||
tittel="Sykefravær i virksomhet" | ||
tooltip="Din virksomhet" | ||
trend="2" | ||
/> | ||
); | ||
expect( | ||
screen.getByRole("img", { | ||
name: /stigende trend/i, | ||
}) | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it("Viser synkende trend", async () => { | ||
render( | ||
<StatistikkPanel | ||
sykefravær="10" | ||
tittel="Sykefravær i virksomhet" | ||
tooltip="Din virksomhet" | ||
trend="-2" | ||
/> | ||
); | ||
expect( | ||
screen.getByRole("img", { | ||
name: /synkende trend/i, | ||
}) | ||
).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import styles from "./StatistikkPanel.module.scss"; | ||
import { BodyShort, Panel, Tooltip } from "@navikt/ds-react"; | ||
import { ArrowUpIcon } from "@navikt/aksel-icons"; | ||
|
||
interface StatistikkPanelProps { | ||
trend?: string; | ||
sykefravær: string; | ||
tittel: string; | ||
tooltip: string; | ||
} | ||
|
||
export const StatistikkPanel = ({ | ||
sykefravær, | ||
tittel, | ||
trend, | ||
tooltip, | ||
}: StatistikkPanelProps) => { | ||
return ( | ||
<Panel className={`${styles.statistikk} ${styles.gråBakgrunn}`}> | ||
<Tooltip content={tooltip}> | ||
<BodyShort size={"small"} className={styles.tittel}> | ||
{tittel} | ||
</BodyShort> | ||
</Tooltip> | ||
<BodyShort className={styles.tallContainer}> | ||
<ArrowUpIcon | ||
className={roterEtterTrend(trend)} | ||
title={trendBeskrivelse(trend)} | ||
fontSize="1rem" | ||
/> | ||
{`${sykefravær} %`} | ||
</BodyShort> | ||
</Panel> | ||
); | ||
}; | ||
|
||
const roterEtterTrend = (trend: string | undefined): string => { | ||
const trendNummer = Number(trend); | ||
if (Number.isNaN(trendNummer) || trendNummer === 0) { | ||
return styles.rotateUendret; | ||
} else if (trendNummer < 0) { | ||
return styles.rotateNed; | ||
} else return styles.rotateOpp; | ||
}; | ||
|
||
const trendBeskrivelse = (trend: string | undefined): string => { | ||
const trendNummer = Number(trend); | ||
if (Number.isNaN(trendNummer) || trendNummer === 0) { | ||
return "uendret trend"; | ||
} else if (trendNummer < 0) { | ||
return "synkende trend"; | ||
} else return "stigende trend"; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
.statistikkContainer { | ||
display: flex; | ||
flex-wrap: wrap; | ||
gap: 1rem; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
import { render, screen } from "@testing-library/react"; | ||
import { axe } from "jest-axe"; | ||
import { Sykefraværsstatistikk } from "./Sykefraværsstatistikk"; | ||
import { AktivitetProvider } from "./context/aktivitetStatus"; | ||
import { mockAggregertStatistikkMedBransjetall } from "../Forside/Sykefraværsstatistikk/mockAggregertStatistikkMedBransjetall"; | ||
|
||
jest.mock("next/router", () => ({ | ||
useRouter() { | ||
return { | ||
route: "/", | ||
pathname: "", | ||
query: { | ||
bedrift: "123456789", | ||
}, | ||
asPath: "", | ||
}; | ||
}, | ||
})); | ||
|
||
describe("Sykefraværsstatistikk", () => { | ||
it("Har ingen uu-feil fra axe", async () => { | ||
const { container } = render( | ||
<AktivitetProvider | ||
aktivitetStatuser={[]} | ||
sykefraværsstatistikk={mockAggregertStatistikkMedBransjetall} | ||
> | ||
<Sykefraværsstatistikk /> | ||
</AktivitetProvider> | ||
); | ||
|
||
expect(await screen.findByText("Sykefravær i bransje")).toBeInTheDocument(); // Vent på kall til backend (msw) | ||
|
||
const results = await axe(container); | ||
expect(results).toHaveNoViolations(); | ||
}); | ||
|
||
it("Skal vise sykefravær med riktige verdier", async () => { | ||
render( | ||
<AktivitetProvider | ||
aktivitetStatuser={[]} | ||
sykefraværsstatistikk={mockAggregertStatistikkMedBransjetall} | ||
> | ||
<Sykefraværsstatistikk /> | ||
</AktivitetProvider> | ||
); | ||
|
||
expect(screen.getByText("Sykefravær i bransje")).toBeInTheDocument(); | ||
expect(screen.getByText("5.1 %")).toBeInTheDocument(); | ||
expect(await screen.findByText("Sykefravær hos deg")).toBeInTheDocument(); // Vent på kall til backend (msw) | ||
expect(screen.getByText("8.8 %")).toBeInTheDocument(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
import { Loader } from "@navikt/ds-react"; | ||
import styles from "./Sykefraværsstatistikk.module.scss"; | ||
import { useSykefraværsstatistikkForAktivitet } from "./context/aktivitetStatus"; | ||
import { StatistikkPanel } from "./StatistikkPanel"; | ||
import { | ||
StatistikkDto, | ||
Statistikkategori, | ||
} from "../integrasjoner/aggregert-statistikk-api"; | ||
|
||
export const Sykefraværsstatistikk = () => { | ||
const sykefraværsstatistikk = useSykefraværsstatistikkForAktivitet(); | ||
|
||
const sykefraværIVirksomhet = finnStatistikkVerdi( | ||
Statistikkategori.VIRKSOMHET, | ||
sykefraværsstatistikk?.prosentSiste4KvartalerTotalt | ||
); | ||
const sykefraværIBransje = finnStatistikkVerdi( | ||
Statistikkategori.BRANSJE, | ||
sykefraværsstatistikk?.prosentSiste4KvartalerTotalt | ||
); | ||
const trendIVirksomhet = finnStatistikkVerdi( | ||
Statistikkategori.VIRKSOMHET, | ||
sykefraværsstatistikk?.trendTotalt | ||
); | ||
const trendIBransje = finnStatistikkVerdi( | ||
Statistikkategori.BRANSJE, | ||
sykefraværsstatistikk?.trendTotalt | ||
); | ||
|
||
return sykefraværsstatistikk ? ( | ||
<div className={styles.statistikkContainer}> | ||
{sykefraværIVirksomhet && ( | ||
<StatistikkPanel | ||
tittel={"Sykefravær hos deg"} | ||
trend={trendIVirksomhet} | ||
sykefravær={sykefraværIVirksomhet} | ||
tooltip={"Din bedrift"} | ||
/> | ||
)} | ||
{sykefraværIBransje && ( | ||
<StatistikkPanel | ||
tittel={"Sykefravær i bransje"} | ||
trend={trendIBransje} | ||
sykefravær={sykefraværIBransje} | ||
tooltip={ | ||
sykefraværsstatistikk.prosentSiste4KvartalerTotalt?.find( | ||
(s) => s.statistikkategori === "BRANSJE" | ||
)?.label ?? "Din bransje" | ||
} | ||
/> | ||
)} | ||
</div> | ||
) : ( | ||
<Loader variant="interaction" /> | ||
); | ||
}; | ||
|
||
const finnStatistikkVerdi = ( | ||
kategori: Statistikkategori, | ||
liste?: StatistikkDto[] | ||
): string | undefined => { | ||
return liste?.find((e) => e.statistikkategori === kategori)?.verdi; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.