Skip to content

Commit

Permalink
Frontend updates
Browse files Browse the repository at this point in the history
  • Loading branch information
edlouth committed Dec 1, 2023
1 parent 0b439f6 commit 6f7d921
Show file tree
Hide file tree
Showing 49 changed files with 2,067 additions and 1,304 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,6 @@ import userEvent from "@testing-library/user-event"
import { act, render, screen, waitFor } from "testing"
import ConnectorCard from "./ConnectorCard"

const onSelect = jest.fn()

test("renders", async () => {
render(
<ConnectorCard
Expand All @@ -13,7 +11,6 @@ test("renders", async () => {
metadata: null,
icon: null,
}}
onSelect={onSelect}
/>,
{
withRouter: true,
Expand All @@ -31,7 +28,6 @@ test("coming soon", async () => {
status: "coming_soon",
icon: null,
}}
onSelect={onSelect}
/>,
{
withRouter: true,
Expand All @@ -51,7 +47,6 @@ test("alpha", async () => {
status: "alpha",
icon: null,
}}
onSelect={() => {}}
/>,
{
withRouter: true,
Expand All @@ -72,18 +67,20 @@ test("click", async () => {
metadata: null,
icon: null,
}}
onSelect={onSelect}
/>,
{
withRouter: true,
routes: ["/:organisationName/:workspaceName/connections/create"],
},
)

await act(async () => {
await user.click(screen.getByText("connector 1"))
})

expect(onSelect).toHaveBeenCalled()
await waitFor(() => {
expect(screen.getByText("New Page")).toBeTruthy()
})
})

test("to", async () => {
Expand All @@ -98,7 +95,6 @@ test("to", async () => {
to: "a",
icon: null,
}}
onSelect={onSelect}
/>,
{
withRouter: true,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import {
Typography,
} from "@mui/material"
import { useNavigate } from "react-router-dom"
import useWorkspace from "helpers/useWorkspace"
import ConnectorIcon from "./ConnectorIcon"

export interface Connector {
Expand All @@ -23,14 +24,11 @@ export interface Connector {

type ConnectorCardProps = {
connector: Connector
onSelect: (connector: Connector) => void
}

const ConnectorCard: React.FC<ConnectorCardProps> = ({
connector,
onSelect,
}) => {
const ConnectorCard: React.FC<ConnectorCardProps> = ({ connector }) => {
const navigate = useNavigate()
const { routePrefix } = useWorkspace()

const comingSoon = connector.status === "coming_soon"

Expand All @@ -45,13 +43,12 @@ const ConnectorCard: React.FC<ConnectorCardProps> = ({
}}
>
<CardActionArea
onClick={() => {
if (connector.to) {
navigate(connector.to)
return
}
onSelect(connector)
}}
onClick={() =>
navigate(
connector.to ??
`${routePrefix}/connections/create?connectorId=${connector.id}`,
)
}
sx={{ height: "100%" }}
>
<List>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,13 @@ import ConnectorCard, { Connector } from "./ConnectorCard"

type ConnectorListProps = {
connectors: Connector[]
onSelect: (connector: Connector) => void
}

const ConnectorList: React.FC<ConnectorListProps> = ({
connectors,
onSelect,
}) => (
const ConnectorList: React.FC<ConnectorListProps> = ({ connectors }) => (
<Grid container spacing={2}>
{connectors.map(connector => (
<Grid item md={3} key={connector.id}>
<ConnectorCard connector={connector} onSelect={onSelect} />
<ConnectorCard connector={connector} />
</Grid>
))}
</Grid>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
import { render, screen, waitFor } from "testing"
import ConnectionCreateContent from "./ConnectionCreateContent"

const workspace = {
id: "1",
}

test("renders", async () => {
render(<ConnectionCreateContent workspace={workspace} />, {
withRouter: true,
})

await waitFor(() => {
expect(screen.queryAllByText("Select Integration")).toHaveLength(2)
})

await waitFor(() =>
expect(screen.queryAllByText("Hello World")).toHaveLength(3),
)
})

test("renders schedule", async () => {
render(<ConnectionCreateContent workspace={workspace} />, {
route: "/default/demo/connections/create?step=schedule&connectionId=1",
path: "/:organisationName/:workspaceName/connections/create",
withRouter: true,
})

await waitFor(() => {
expect(screen.getByText(/Schedule type/i)).toBeInTheDocument()
})
})

test("renders schedule missing connectionId", async () => {
render(<ConnectionCreateContent workspace={workspace} />, {
route: "/default/demo/connections/create?step=schedule",
path: "/:organisationName/:workspaceName/connections/create",
withRouter: true,
})

await waitFor(() => {
expect(screen.queryByText(/Schedule type/i)).not.toBeInTheDocument()
})

expect(screen.getByText("Page not found")).toBeInTheDocument()
})

test("renders connection", async () => {
render(<ConnectionCreateContent workspace={workspace} />, {
route: "/default/demo/connections/create?connectionId=1",
path: "/:organisationName/:workspaceName/connections/create",
withRouter: true,
})

await waitFor(() => {
expect(screen.getByText("Invite a teammate")).toBeInTheDocument()
})
})

test("renders connectorId", async () => {
render(<ConnectionCreateContent workspace={workspace} />, {
route: "/default/demo/connections/create?connectorId=1",
path: "/:organisationName/:workspaceName/connections/create",
withRouter: true,
})

await waitFor(() => {
expect(screen.getByText("Invite a teammate")).toBeInTheDocument()
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
import React from "react"
import NotFound from "pages/NotFound"
import useSearchParams from "helpers/useSearchParams"
import ConnectorSelectTab from "components/connections/create/ConnectorSelectTab"
import ScheduleTab from "./ScheduleTab"
import SetupConnectionTab from "./SetupConnectionTab"
import UpdateConnectionTab from "./UpdateConnectionTab"

interface Workspace {
id: string
}

type ConnectionCreateContentProps = {
workspace: Workspace
}

const ConnectionCreateContent: React.FC<ConnectionCreateContentProps> = ({
workspace,
}) => {
const { searchParams } = useSearchParams()

const step = searchParams.get("step")
const connectionId = searchParams.get("connectionId")

if (step === "schedule") {
if (!connectionId) return <NotFound />

return (
<ScheduleTab workspaceId={workspace.id} connectionId={connectionId} />
)
}

if (connectionId)
return (
<UpdateConnectionTab
workspaceId={workspace.id}
connectionId={connectionId}
/>
)

const connectorId = searchParams.get("connectorId")

if (connectorId)
return (
<SetupConnectionTab
workspaceId={workspace.id}
connectorId={connectorId}
/>
)

return <ConnectorSelectTab />
}

export default ConnectionCreateContent
Loading

0 comments on commit 6f7d921

Please sign in to comment.