-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
475 additions
and
51 deletions.
There are no files selected for viewing
34 changes: 34 additions & 0 deletions
34
src/pages/apps/[id]/environments/[env-id]/config/_components/RedirectsEditor.spec.tsx
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 @@ | ||
import { RenderResult } from "@testing-library/react"; | ||
import { render } from "@testing-library/react"; | ||
import RedirectsEditor from "./RedirectsEditor"; | ||
|
||
interface WrapperProps { | ||
value: string; | ||
} | ||
|
||
jest.mock("@codemirror/lang-json", () => ({ json: jest.fn() })); | ||
jest.mock("@uiw/react-codemirror", () => ({ value }: { value: string }) => ( | ||
<>{value}</> | ||
)); | ||
|
||
describe("~/pages/apps/[id]/environments/[env-id]/config/_components/RedirectsEditor.tsx", () => { | ||
let wrapper: RenderResult; | ||
let onChange: jest.Func; | ||
|
||
const createWrapper = ({ value }: WrapperProps) => { | ||
onChange = jest.fn(); | ||
|
||
wrapper = render(<RedirectsEditor value={value} onChange={onChange} />); | ||
}; | ||
|
||
test("should have a form", () => { | ||
const value = "[ { 'from': '/', 'to': '/test' } ]"; | ||
|
||
createWrapper({ value }); | ||
|
||
expect(wrapper.getByText(value)).toBeTruthy(); | ||
expect(wrapper.getByText("docs").getAttribute("href")).toBe( | ||
"https://stormkit.io/docs/features/redirects-and-path-rewrites" | ||
); | ||
}); | ||
}); |
35 changes: 35 additions & 0 deletions
35
src/pages/apps/[id]/environments/[env-id]/config/_components/RedirectsEditor.tsx
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,35 @@ | ||
import CodeMirror from "@uiw/react-codemirror"; | ||
import { json } from "@codemirror/lang-json"; | ||
import Typography from "@mui/material/Typography"; | ||
import Link from "@mui/material/Link"; | ||
import { grey } from "@mui/material/colors"; | ||
|
||
interface Props { | ||
value?: string; | ||
onChange: (r: string) => void; | ||
} | ||
|
||
export default function RedirectsEditor({ value, onChange }: Props) { | ||
return ( | ||
<> | ||
<CodeMirror | ||
maxHeight="200px" | ||
value={value} | ||
extensions={[json()]} | ||
onChange={onChange} | ||
theme="dark" | ||
/> | ||
<Typography sx={{ mt: 2, color: grey[400] }}> | ||
Check the{" "} | ||
<Link | ||
href={"https://stormkit.io/docs/features/redirects-and-path-rewrites"} | ||
target="_blank" | ||
rel="noreferrer noopener" | ||
> | ||
docs | ||
</Link>{" "} | ||
for more information. | ||
</Typography> | ||
</> | ||
); | ||
} |
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
127 changes: 127 additions & 0 deletions
127
src/pages/apps/[id]/environments/[env-id]/config/_components/TabConfigRedirects.spec.tsx
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,127 @@ | ||
import { RenderResult, waitFor } from "@testing-library/react"; | ||
import { fireEvent, render } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import mockApp from "~/testing/data/mock_app"; | ||
import mockEnvironments from "~/testing/data/mock_environments"; | ||
import { mockUpdateEnvironment } from "~/testing/nocks/nock_environment"; | ||
import TabConfigRedirects from "./TabConfigRedirects"; | ||
|
||
interface WrapperProps { | ||
app?: App; | ||
environment?: Environment; | ||
setRefreshToken?: () => void; | ||
} | ||
|
||
jest.mock("@codemirror/lang-json", () => ({ json: jest.fn() })); | ||
jest.mock("@uiw/react-codemirror", () => ({ value }: { value: string }) => ( | ||
<>{value}</> | ||
)); | ||
|
||
describe("~/pages/apps/[id]/environments/[env-id]/config/_components/TabConfigRedirects.tsx", () => { | ||
let wrapper: RenderResult; | ||
let currentApp: App; | ||
let currentEnv: Environment; | ||
let setRefreshToken: jest.Func; | ||
|
||
const createWrapper = ({ app, environment }: WrapperProps) => { | ||
setRefreshToken = jest.fn(); | ||
currentApp = app || mockApp(); | ||
currentEnv = environment || mockEnvironments({ app: currentApp })[0]; | ||
|
||
wrapper = render( | ||
<TabConfigRedirects | ||
app={currentApp} | ||
environment={currentEnv} | ||
setRefreshToken={setRefreshToken} | ||
/> | ||
); | ||
}; | ||
|
||
test("should have a form", () => { | ||
createWrapper({}); | ||
|
||
expect(wrapper.getByText("Redirects")).toBeTruthy(); | ||
expect( | ||
wrapper.getByText( | ||
"Configure redirects and path rewrites for your application." | ||
) | ||
).toBeTruthy(); | ||
|
||
const redirectsFileInput = wrapper.getByLabelText( | ||
"Redirects file location" | ||
) as HTMLInputElement; | ||
|
||
expect(redirectsFileInput.value).toBe(""); | ||
|
||
// Initially the docs should not be visible | ||
expect(() => wrapper.getByText("docs")).toThrow(); | ||
|
||
expect(wrapper.getByText("Overwrite redirects")).toBeTruthy(); | ||
|
||
fireEvent.click(wrapper.getByText("Overwrite redirects")); | ||
|
||
expect(wrapper.getByText("docs")).toBeTruthy(); | ||
}); | ||
|
||
test("should submit the form without redirects", async () => { | ||
createWrapper({}); | ||
|
||
await userEvent.type( | ||
wrapper.getByLabelText("Redirects file location"), | ||
"/redirects.json" | ||
); | ||
|
||
const scope = mockUpdateEnvironment({ | ||
environment: { | ||
...currentEnv, | ||
build: { | ||
...currentEnv.build, | ||
previewLinks: true, | ||
redirectsFile: "/redirects.json", | ||
}, | ||
}, | ||
status: 200, | ||
response: { | ||
ok: true, | ||
}, | ||
}); | ||
|
||
fireEvent.click(wrapper.getByText("Save")); | ||
|
||
await waitFor(() => { | ||
expect(scope.isDone()).toBe(true); | ||
}); | ||
}); | ||
|
||
test("should submit the form with redirects", async () => { | ||
createWrapper({}); | ||
|
||
await userEvent.type( | ||
wrapper.getByLabelText("Redirects file location"), | ||
"/redirects.json" | ||
); | ||
|
||
const scope = mockUpdateEnvironment({ | ||
environment: { | ||
...currentEnv, | ||
build: { | ||
...currentEnv.build, | ||
previewLinks: true, | ||
redirects: [], | ||
redirectsFile: "/redirects.json", | ||
}, | ||
}, | ||
status: 200, | ||
response: { | ||
ok: true, | ||
}, | ||
}); | ||
|
||
fireEvent.click(wrapper.getByLabelText("Overwrite redirects")); | ||
fireEvent.click(wrapper.getByText("Save")); | ||
|
||
await waitFor(() => { | ||
expect(scope.isDone()).toBe(true); | ||
}); | ||
}); | ||
}); |
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.