Skip to content

Commit c969427

Browse files
author
SilviaAmAm
committed
✅ [#166] test: Test that the OIDC button is present
1 parent 4e4a355 commit c969427

File tree

1 file changed

+43
-1
lines changed

1 file changed

+43
-1
lines changed

frontend/src/pages/login/Login.stories.tsx

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import type { Meta, StoryObj } from "@storybook/react";
2+
import { expect, within } from "@storybook/test";
23
import { DefaultBodyType, HttpResponse, PathParams, http } from "msw";
34
import {
45
reactRouterParameters,
56
withRouter,
67
} from "storybook-addon-remix-react-router";
7-
import { API_BASE_URL } from "~/api";
8+
import { API_BASE_URL, OidcInfoType } from "~/api";
89
import { FIXTURE_USER } from "~/fixtures";
910
import { routes } from "~/routes.tsx";
1011
import { User } from "~/types";
@@ -28,6 +29,10 @@ export const LoginPage: Story = {
2829
`${API_BASE_URL}/whoami/`,
2930
() => HttpResponse.json(FIXTURE_USER),
3031
),
32+
http.get<PathParams, DefaultBodyType, OidcInfoType>(
33+
`${API_BASE_URL}/oidc-info/`,
34+
() => HttpResponse.json({ enabled: false }),
35+
),
3136
],
3237
},
3338
reactRouter: reactRouterParameters({
@@ -38,3 +43,40 @@ export const LoginPage: Story = {
3843
}),
3944
},
4045
};
46+
47+
export const LoginPageWithOIDC: Story = {
48+
parameters: {
49+
msw: {
50+
handlers: [
51+
http.get<PathParams, DefaultBodyType, User>(
52+
`${API_BASE_URL}/whoami/`,
53+
() => HttpResponse.json(FIXTURE_USER),
54+
),
55+
http.get<PathParams, DefaultBodyType, OidcInfoType>(
56+
`${API_BASE_URL}/oidc-info/`,
57+
() =>
58+
HttpResponse.json({
59+
enabled: true,
60+
loginUrl: "http://backend.nl/oidc/authenticate",
61+
}),
62+
),
63+
],
64+
},
65+
reactRouter: reactRouterParameters({
66+
location: {
67+
path: "/login",
68+
},
69+
routing: routes[0],
70+
}),
71+
},
72+
play: async (context) => {
73+
const canvas = within(context.canvasElement);
74+
const oidcButton: HTMLBaseElement = await canvas.findByRole("link", {
75+
name: "Organisatie login",
76+
});
77+
const redirectUrl = new URL(oidcButton.href);
78+
const nextUrl = redirectUrl.searchParams.get("next");
79+
expect(nextUrl).not.toBeNull();
80+
expect(new URL(nextUrl as string).pathname).toEqual("/");
81+
},
82+
};

0 commit comments

Comments
 (0)