-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(Pipelines): Add connection picker (#476)
- Loading branch information
1 parent
2d27f76
commit 98dd463
Showing
13 changed files
with
425 additions
and
5 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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
61 changes: 61 additions & 0 deletions
61
src/workspaces/features/WorkspaceConnectionPicker/WorkspaceConnectionPicker.generated.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,61 @@ | ||
import * as Types from '../../../graphql-types'; | ||
|
||
import { gql } from '@apollo/client'; | ||
import * as Apollo from '@apollo/client'; | ||
const defaultOptions = {} as const; | ||
export type WorkspaceConnectionPickerQueryVariables = Types.Exact<{ | ||
slug: Types.Scalars['String']['input']; | ||
}>; | ||
|
||
|
||
export type WorkspaceConnectionPickerQuery = { __typename?: 'Query', workspace?: { __typename?: 'Workspace', slug: string, connections: Array<{ __typename?: 'Connection', id: string, name: string, slug: string, type: Types.ConnectionType }> } | null }; | ||
|
||
export type WorkspaceConnectionPicker_WorkspaceFragment = { __typename?: 'Workspace', slug: string, connections: Array<{ __typename?: 'Connection', id: string, name: string, slug: string, type: Types.ConnectionType }> }; | ||
|
||
export const WorkspaceConnectionPicker_WorkspaceFragmentDoc = gql` | ||
fragment WorkspaceConnectionPicker_workspace on Workspace { | ||
slug | ||
connections { | ||
id | ||
name | ||
slug | ||
type | ||
} | ||
} | ||
`; | ||
export const WorkspaceConnectionPickerDocument = gql` | ||
query WorkspaceConnectionPicker($slug: String!) { | ||
workspace(slug: $slug) { | ||
slug | ||
...WorkspaceConnectionPicker_workspace | ||
} | ||
} | ||
${WorkspaceConnectionPicker_WorkspaceFragmentDoc}`; | ||
|
||
/** | ||
* __useWorkspaceConnectionPickerQuery__ | ||
* | ||
* To run a query within a React component, call `useWorkspaceConnectionPickerQuery` and pass it any options that fit your needs. | ||
* When your component renders, `useWorkspaceConnectionPickerQuery` returns an object from Apollo Client that contains loading, error, and data properties | ||
* you can use to render your UI. | ||
* | ||
* @param baseOptions options that will be passed into the query, supported options are listed on: https://www.apollographql.com/docs/react/api/react-hooks/#options; | ||
* | ||
* @example | ||
* const { data, loading, error } = useWorkspaceConnectionPickerQuery({ | ||
* variables: { | ||
* slug: // value for 'slug' | ||
* }, | ||
* }); | ||
*/ | ||
export function useWorkspaceConnectionPickerQuery(baseOptions: Apollo.QueryHookOptions<WorkspaceConnectionPickerQuery, WorkspaceConnectionPickerQueryVariables>) { | ||
const options = {...defaultOptions, ...baseOptions} | ||
return Apollo.useQuery<WorkspaceConnectionPickerQuery, WorkspaceConnectionPickerQueryVariables>(WorkspaceConnectionPickerDocument, options); | ||
} | ||
export function useWorkspaceConnectionPickerLazyQuery(baseOptions?: Apollo.LazyQueryHookOptions<WorkspaceConnectionPickerQuery, WorkspaceConnectionPickerQueryVariables>) { | ||
const options = {...defaultOptions, ...baseOptions} | ||
return Apollo.useLazyQuery<WorkspaceConnectionPickerQuery, WorkspaceConnectionPickerQueryVariables>(WorkspaceConnectionPickerDocument, options); | ||
} | ||
export type WorkspaceConnectionPickerQueryHookResult = ReturnType<typeof useWorkspaceConnectionPickerQuery>; | ||
export type WorkspaceConnectionPickerLazyQueryHookResult = ReturnType<typeof useWorkspaceConnectionPickerLazyQuery>; | ||
export type WorkspaceConnectionPickerQueryResult = Apollo.QueryResult<WorkspaceConnectionPickerQuery, WorkspaceConnectionPickerQueryVariables>; |
98 changes: 98 additions & 0 deletions
98
src/workspaces/features/WorkspaceConnectionPicker/WorkspaceConnectionPicker.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,98 @@ | ||
import WorkspaceConnectionPicker from "./WorkspaceConnectionPicker"; | ||
import { queryByRole, render, screen } from "@testing-library/react"; | ||
import userEvent from "@testing-library/user-event"; | ||
import { MockedProvider } from "@apollo/client/testing"; | ||
import { faker } from "@faker-js/faker"; | ||
import { useQuery } from "@apollo/client"; | ||
import { ConnectionType } from "graphql-types"; | ||
|
||
jest.mock("@apollo/client", () => ({ | ||
__esModule: true, | ||
useQuery: jest.fn(), | ||
gql: jest.fn(() => "GQL"), | ||
})); | ||
|
||
const useQueryMock = useQuery as jest.Mock; | ||
|
||
const WORKSPACE = { | ||
slug: faker.datatype.uuid(), | ||
connections: [ | ||
{ | ||
id: faker.datatype.uuid(), | ||
name: "dhis2-dev", | ||
slug: "dhis2-dev", | ||
type: ConnectionType.Dhis2, | ||
}, | ||
{ | ||
id: faker.datatype.uuid(), | ||
name: "dhis2-staging", | ||
slug: "dhis2-staging", | ||
type: ConnectionType.Dhis2, | ||
}, | ||
{ | ||
id: faker.datatype.uuid(), | ||
name: "iaso-dev", | ||
slug: "iaso-dev", | ||
type: ConnectionType.Iaso, | ||
}, | ||
], | ||
}; | ||
|
||
describe("WorkspaceConnectionPicker", () => { | ||
it("display all connections", async () => { | ||
const user = userEvent.setup(); | ||
|
||
useQueryMock.mockReturnValue({ | ||
loading: true, | ||
data: { | ||
workspace: WORKSPACE, | ||
}, | ||
}); | ||
const onChange = jest.fn(); | ||
|
||
const { container } = render( | ||
<WorkspaceConnectionPicker | ||
workspaceSlug={WORKSPACE.slug} | ||
onChange={onChange} | ||
value={[]} | ||
/>, | ||
); | ||
|
||
await user.click(await screen.findByTestId("combobox-button")); | ||
const option = await screen.queryAllByRole("option"); | ||
expect(option.length).toBe(WORKSPACE.connections.length); | ||
|
||
await user.click(await screen.findByText(WORKSPACE.connections[0].name)); | ||
expect(onChange).toHaveBeenCalledWith(WORKSPACE.connections[0]); | ||
expect(container).toMatchSnapshot(); | ||
}); | ||
|
||
it("display only connections with a given type", async () => { | ||
const user = userEvent.setup(); | ||
|
||
useQueryMock.mockReturnValue({ | ||
loading: true, | ||
data: { | ||
workspace: WORKSPACE, | ||
}, | ||
}); | ||
const onChange = jest.fn(); | ||
|
||
render( | ||
<WorkspaceConnectionPicker | ||
workspaceSlug={WORKSPACE.slug} | ||
onChange={onChange} | ||
value={[]} | ||
type={ConnectionType.Dhis2} | ||
/>, | ||
); | ||
|
||
await user.click(await screen.findByTestId("combobox-button")); | ||
const option = await screen.queryAllByRole("option"); | ||
const dhis2Connections = WORKSPACE.connections.filter( | ||
(c) => c.type === ConnectionType.Dhis2, | ||
); | ||
|
||
expect(option.length).toBe(dhis2Connections.length); | ||
}); | ||
}); |
Oops, something went wrong.