-
Notifications
You must be signed in to change notification settings - Fork 26
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
- Loading branch information
1 parent
39e1921
commit 30e4df3
Showing
14 changed files
with
450 additions
and
13 deletions.
There are no files selected for viewing
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
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
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
51 changes: 51 additions & 0 deletions
51
apps/web/src/components/connection/connectionInputStatusBadge.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,51 @@ | ||
"use client"; | ||
import { Badge, Loader } from "@mantine/core"; | ||
import React, { FC, useMemo } from "react"; | ||
import { useQuery } from "urql"; | ||
import { | ||
InputStatusDocument, | ||
InputStatusQuery, | ||
InputStatusQueryVariables, | ||
} from "../../graphql/rollups/operations"; | ||
|
||
interface ConnectionInputStatusBadgeProps { | ||
graphqlUrl: string; | ||
index: number; | ||
} | ||
|
||
const ConnectionInputStatusBadge: FC<ConnectionInputStatusBadgeProps> = ({ | ||
graphqlUrl, | ||
index, | ||
}) => { | ||
const [result] = useQuery<InputStatusQuery, InputStatusQueryVariables>({ | ||
context: useMemo( | ||
() => ({ | ||
url: graphqlUrl, | ||
}), | ||
[graphqlUrl], | ||
), | ||
query: InputStatusDocument, | ||
variables: { | ||
index, | ||
}, | ||
}); | ||
|
||
return ( | ||
<> | ||
{result.fetching ? ( | ||
<Loader | ||
data-testid="connection-input-status-loader" | ||
size="xs" | ||
/> | ||
) : result.data?.input.status ? ( | ||
<Badge variant="default" style={{ textTransform: "none" }}> | ||
{result.data.input.status} | ||
</Badge> | ||
) : ( | ||
"N/A" | ||
)} | ||
</> | ||
); | ||
}; | ||
|
||
export default ConnectionInputStatusBadge; |
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
69 changes: 69 additions & 0 deletions
69
apps/web/test/components/connection/connectionInputStatusBadge.test.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,69 @@ | ||
import { describe, it, beforeEach, expect } from "vitest"; | ||
import { render, screen } from "@testing-library/react"; | ||
import { useQuery } from "urql"; | ||
import ConnectionInputStatusBadge from "../../../src/components/connection/connectionInputStatusBadge"; | ||
import { withMantineTheme } from "../../utils/WithMantineTheme"; | ||
|
||
vi.mock("urql"); | ||
const useQueryMock = vi.mocked(useQuery, true); | ||
|
||
const Component = withMantineTheme(ConnectionInputStatusBadge); | ||
|
||
const defaultProps = { | ||
graphqlUrl: "https://drawingcanvas.fly.dev/graphql", | ||
index: 0, | ||
}; | ||
|
||
const defaultData = { | ||
input: { | ||
status: "ACTIVE", | ||
}, | ||
}; | ||
|
||
describe("ConnectionInputStatusBadge component", () => { | ||
beforeEach(() => { | ||
useQueryMock.mockReturnValue([ | ||
{ | ||
fetching: false, | ||
data: defaultData, | ||
}, | ||
] as any); | ||
}); | ||
|
||
afterEach(() => { | ||
vi.clearAllMocks(); | ||
}); | ||
|
||
it("should display loading UI while fetching data", () => { | ||
useQueryMock.mockReturnValue([ | ||
{ | ||
fetching: true, | ||
}, | ||
] as any); | ||
render(<Component {...defaultProps} />); | ||
|
||
expect( | ||
screen.getByTestId("connection-input-status-loader"), | ||
).toBeInTheDocument(); | ||
}); | ||
|
||
it("should display correct status", () => { | ||
render(<Component {...defaultProps} />); | ||
expect(screen.getByText(defaultData.input.status)).toBeInTheDocument(); | ||
}); | ||
|
||
it("should display not available label when status is unavailable", () => { | ||
useQueryMock.mockReturnValue([ | ||
{ | ||
fetching: false, | ||
data: { | ||
input: { | ||
status: undefined, | ||
}, | ||
}, | ||
}, | ||
] as any); | ||
render(<Component {...defaultProps} />); | ||
expect(screen.getByText("N/A")).toBeInTheDocument(); | ||
}); | ||
}); |
Oops, something went wrong.