Skip to content

Commit

Permalink
Add jest test
Browse files Browse the repository at this point in the history
  • Loading branch information
dbernstein committed Dec 22, 2023
1 parent 06f4d42 commit 1cf7f20
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 2 deletions.
5 changes: 3 additions & 2 deletions src/components/QuicksightDashboard.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ export interface QuicksightDashboardState {
embedUrl: string;
}

export class QuicksightDashboard extends React.Component<
class QuicksightDashboard extends React.Component<
QuicksightDashboardProps,
QuicksightDashboardState
> {
Expand All @@ -43,7 +43,7 @@ export class QuicksightDashboard extends React.Component<

this.props.fetchLibraries().then((libs) => {
const library_uuids: string = libs.libraries
.slice(0, 5)
.slice(0, Math.min(1, 10))// TODO: remove this once https://github.com/ThePalaceProject/circulation/pull/1577 is merged
.map((l) => l.uuid)
.join(",");
try {
Expand All @@ -67,6 +67,7 @@ export class QuicksightDashboard extends React.Component<
render(): JSX.Element {
return (
<iframe
role="iframe"
title="Quicksight Dashboard"
height="1200"
width="100%"
Expand Down
51 changes: 51 additions & 0 deletions tests/jest/components/QuicksightDashboard.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
import * as React from "react";
import {screen, waitFor} from "@testing-library/react";

import QuicksightDashboard from "../../../src/components/QuicksightDashboard";
import {LibrariesData, LibraryData} from "../../../src/interfaces";
import buildStore, {RootState} from "../../../src/store"
import {setupServer} from "msw/node";
import {rest} from "msw";
import renderWithContext from "../testUtils/renderWithContext";

const libraries: LibrariesData = {libraries: [{uuid: "my-uuid"}]};
const dashboardId = "test";
const embedUrl = "http://embedUrl"
const dashboardUrlData = {embedUrl: embedUrl}

describe("QuicksightDashboard", () => {
const server = setupServer(
rest.get("*/admin/libraries", (req, res, ctx) => res(ctx.json(libraries))),

rest.get("*/admin/quicksight_embed/" + dashboardId + "?libraryUuids=" + libraries["libraries"][0]["uuid"], (req, res, ctx) => res(ctx.json(dashboardUrlData)))
);

beforeAll(() => {
server.listen();
});

afterAll(() => {
server.close();
});

it("embed url is retrieved and set in iframe", async () => {

const contextProviderProps = {
csrfToken: "",
roles: [{role: "system"}],

};

renderWithContext(
<QuicksightDashboard
dashboardId={dashboardId}
store={buildStore()}
/>,
contextProviderProps
);

await waitFor(() => {
expect(screen.getByRole('iframe')).toHaveAttribute("src", embedUrl)
});
});
});

0 comments on commit 1cf7f20

Please sign in to comment.