mirror of
https://github.com/OneUptime/oneuptime.git
synced 2026-04-06 00:32:12 +02:00
test: Update cookie utility tests to include default path and sameSite options; modify modal tests for responsive width; enhance navbar tests with mock navigation location; adjust ordered states list test for bar loader role
This commit is contained in:
@@ -35,10 +35,11 @@ describe("CookieUtils", () => {
|
||||
cookie["options"] as JSONObject,
|
||||
);
|
||||
|
||||
// setCookie adds default path and sameSite options
|
||||
expect(mockResponse.cookie).toHaveBeenCalledWith(
|
||||
cookie["name"] as string,
|
||||
cookie["value"] as string,
|
||||
cookie["options"] as JSONObject,
|
||||
{ path: "/", sameSite: "lax" },
|
||||
);
|
||||
});
|
||||
|
||||
@@ -61,7 +62,11 @@ describe("CookieUtils", () => {
|
||||
mockResponse.clearCookie = jest.fn();
|
||||
CookieUtil.removeCookie(mockResponse, cookieName);
|
||||
|
||||
expect(mockResponse.clearCookie).toHaveBeenCalledWith(cookieName);
|
||||
// removeCookie includes path and sameSite options
|
||||
expect(mockResponse.clearCookie).toHaveBeenCalledWith(cookieName, {
|
||||
path: "/",
|
||||
sameSite: "lax",
|
||||
});
|
||||
});
|
||||
|
||||
test("Should return all cookies", () => {
|
||||
@@ -111,11 +116,14 @@ describe("CookieUtils", () => {
|
||||
mockResponse.clearCookie = jest.fn();
|
||||
CookieUtil.removeAllCookies(mockRequest, mockResponse);
|
||||
|
||||
// clearCookie is called with path and sameSite options
|
||||
expect(mockResponse.clearCookie).toHaveBeenCalledWith(
|
||||
Object.keys(cookies)[0],
|
||||
{ path: "/", sameSite: "lax" },
|
||||
);
|
||||
expect(mockResponse.clearCookie).toHaveBeenCalledWith(
|
||||
Object.keys(cookies)[1],
|
||||
{ path: "/", sameSite: "lax" },
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -72,7 +72,7 @@ describe("Modal", () => {
|
||||
</Modal>,
|
||||
);
|
||||
|
||||
expect(getByTestId("modal")).toHaveClass("sm:max-w-lg");
|
||||
expect(getByTestId("modal")).toHaveClass("md:max-w-lg");
|
||||
});
|
||||
|
||||
it("displays the modal with the correct width when modalWidth is set", () => {
|
||||
@@ -88,7 +88,7 @@ describe("Modal", () => {
|
||||
</Modal>,
|
||||
);
|
||||
|
||||
expect(getByTestId("modal")).toHaveClass("sm:max-w-3xl");
|
||||
expect(getByTestId("modal")).toHaveClass("md:max-w-3xl");
|
||||
});
|
||||
|
||||
it("displays the children passed to the modal", () => {
|
||||
|
||||
@@ -2,14 +2,27 @@ import Navbar, {
|
||||
ComponentProps,
|
||||
NavItem,
|
||||
} from "../../../UI/Components/Navbar/NavBar";
|
||||
import { describe, expect, it } from "@jest/globals";
|
||||
import { describe, expect, it, beforeEach } from "@jest/globals";
|
||||
import "@testing-library/jest-dom/extend-expect";
|
||||
import { render, screen } from "@testing-library/react";
|
||||
import React from "react";
|
||||
import Route from "../../../Types/API/Route";
|
||||
import IconProp from "../../../Types/Icon/IconProp";
|
||||
import Navigation from "../../../UI/Utils/Navigation";
|
||||
import { Location } from "react-router-dom";
|
||||
|
||||
describe("Navbar", () => {
|
||||
// Mock Navigation location for Navigation utility
|
||||
beforeEach(() => {
|
||||
const mockLocation: Location = {
|
||||
pathname: "/",
|
||||
search: "",
|
||||
hash: "",
|
||||
state: null,
|
||||
key: "default",
|
||||
};
|
||||
Navigation.setLocation(mockLocation);
|
||||
});
|
||||
const defaultProps: ComponentProps = {
|
||||
children: <div>Test</div>,
|
||||
};
|
||||
|
||||
@@ -46,7 +46,7 @@ describe("OrderedSateList", () => {
|
||||
isLoading: true,
|
||||
};
|
||||
render(<OrderedStatesList {...props} />);
|
||||
expect(screen.getByRole("bar-loader")).toBeInTheDocument();
|
||||
expect(screen.getByTestId("bar-loader")).toBeInTheDocument();
|
||||
});
|
||||
it("should render an error message if error prop is present", () => {
|
||||
const props: ComponentProps<ItemData> = {
|
||||
|
||||
Reference in New Issue
Block a user