Skip to content

Commit

Permalink
first test describe/it
Browse files Browse the repository at this point in the history
  • Loading branch information
RODO94 committed Aug 19, 2024
1 parent cd31a09 commit 70c7208
Show file tree
Hide file tree
Showing 3 changed files with 75 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -228,7 +228,7 @@ const ServiceSettings: React.FC = () => {

const handleClose = (
_event?: React.SyntheticEvent | Event,
reason?: string,
reason?: string
) => {
if (reason === "clickaway") {
return;
Expand Down Expand Up @@ -279,7 +279,7 @@ const ServiceSettings: React.FC = () => {
});

const publishedLink = `${window.location.origin}${rootFlowPath(
false,
false
)}/published`;

const subdomainLink = teamDomain && `https://${teamDomain}/${flowSlug}`;
Expand Down Expand Up @@ -405,9 +405,7 @@ const ServiceSettings: React.FC = () => {
onChange={() =>
statusForm.setFieldValue(
"status",
statusForm.values.status === "online"
? "offline"
: "online",
statusForm.values.status === "online" ? "offline" : "online"
)
}
/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
import { useStore } from "pages/FlowEditor/lib/store";
import ServiceSettings from "../ServiceSettings";
import setupServiceSettingsScreen, {
mockWindowLocationObject,
} from "./helpers/setupServiceSettingsScreen";
import { screen } from "@testing-library/react";
import { rootFlowPath } from "routes/utils";

const { getState, setState } = useStore;

describe("Check when service is offline and published, the team has a subdomain", () => {
beforeEach(async () => {
// setup state values that <ServiceSettings/> depends on
setState({
flowSettings: {},
flowStatus: "offline",
teamDomain: "mockedteamdomain.com",
teamName: "mockTeam",
isFlowPublished: true,
flowSlug: "mock-planning-permish",
});

// render the <ServiceSettings/> comp
setupServiceSettingsScreen();

// Mocking window.location.origin
jest
.spyOn(window, "location", "get")
.mockReturnValue(mockWindowLocationObject);
});

it("public link should be the current published url", async () => {
expect(
await screen.findByText(
`https://mockedteamdomain.com/mock-planning-permish`
)
).toBe;
});
});
Original file line number Diff line number Diff line change
@@ -1,7 +1,38 @@
import React from "react";

import ServiceSettings from "../../ServiceSettings";
import { setup } from "testUtils";
import { DndProvider } from "react-dnd";
import { HTML5Backend } from "react-dnd-html5-backend";
import { screen } from "@testing-library/react";

export default function setupServiceSettingsScreen() {
return <ServiceSettings />;
export default async function setupServiceSettingsScreen() {
const { user } = setup(
<DndProvider backend={HTML5Backend}>
<ServiceSettings />
</DndProvider>
);
await screen.findByText("Your public Link");
return user;
}

export const mockWindowLocationObject = {
origin: "https://mocked-origin.com",
hash: "",
host: "dummy.com",
port: "80",
protocol: "http:",
hostname: "dummy.com",
href: "http://dummy.com?page=1&name=testing",
pathname: "",
search: "",
assign: jest.fn(),
reload: jest.fn(),
replace: jest.fn(),
ancestorOrigins: {
length: 0,
contains: () => true,
item: () => null,
[Symbol.iterator]: jest.fn(),
},
};

0 comments on commit 70c7208

Please sign in to comment.