-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Rough in tests for new hooks and react components
- Loading branch information
1 parent
1f9309b
commit ae2c10c
Showing
31 changed files
with
510 additions
and
149 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { Client as BulkClient } from "@gadget-client/bulk-actions-test"; | ||
import { Client } from "@gadget-client/related-products-example"; | ||
import { Client as ClientWithAuth } from "@gadget-client/super-auth"; | ||
import { Client as AuthClient } from "@gadget-client/super-auth"; | ||
|
||
export const relatedProductsApi = new Client(); | ||
export const superAuthApi = new ClientWithAuth(); | ||
export const bulkExampleApi = new BulkClient(); | ||
export const superAuthApi = new AuthClient(); |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,65 @@ | ||
import "@testing-library/jest-dom"; | ||
import { render } from "@testing-library/react"; | ||
import React from "react"; | ||
import { superAuthApi } from "../../spec/apis"; | ||
import { SignedIn } from "../../src/components/SignedIn"; | ||
import { TestWrapper, mockUrqlClient } from "../testWrapper"; | ||
|
||
describe("SignedIn", () => { | ||
test("renders without crashing", () => { | ||
expect(true).toBe(false); | ||
test("renders children when signed in", () => { | ||
const component = ( | ||
<h1> | ||
Hello<SignedIn>, Jane!</SignedIn> | ||
</h1> | ||
); | ||
|
||
const { container, rerender } = render(component, { wrapper: TestWrapper(superAuthApi) }); | ||
|
||
expect(mockUrqlClient.executeQuery).toBeCalledTimes(1); | ||
mockUrqlClient.executeQuery.pushResponse("currentSession", { | ||
data: { | ||
currentSession: { | ||
id: "123", | ||
userId: "321", | ||
user: { | ||
id: "321", | ||
firstName: "Jane", | ||
lastName: "Doe", | ||
}, | ||
}, | ||
}, | ||
stale: false, | ||
hasNext: false, | ||
}); | ||
|
||
rerender(component); | ||
|
||
// return session | ||
expect(container.outerHTML).toMatchInlineSnapshot(`"<div><h1>Hello, Jane!</h1></div>"`); | ||
}); | ||
|
||
test("renders nothing when signed out", () => { | ||
const component = ( | ||
<h1> | ||
Hello<SignedIn>, Jane!</SignedIn> | ||
</h1> | ||
); | ||
|
||
const { container, rerender } = render(component, { wrapper: TestWrapper(superAuthApi) }); | ||
|
||
expect(mockUrqlClient.executeQuery).toBeCalledTimes(1); | ||
mockUrqlClient.executeQuery.pushResponse("currentSession", { | ||
data: { | ||
currentSession: { | ||
id: "123", | ||
userId: null, | ||
user: null, | ||
}, | ||
}, | ||
stale: false, | ||
hasNext: false, | ||
}); | ||
rerender(component); | ||
expect(container.outerHTML).toMatchInlineSnapshot(`"<div><h1>Hello</h1></div>"`); | ||
}); | ||
}); |
84 changes: 81 additions & 3 deletions
84
packages/react/spec/components/SignedInOrRedirect.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 |
---|---|---|
@@ -1,5 +1,83 @@ | ||
describe("SignedInOrRedirect", () => { | ||
test("renders without crashing", () => { | ||
expect(true).toBe(false); | ||
import "@testing-library/jest-dom"; | ||
import { render } from "@testing-library/react"; | ||
import React from "react"; | ||
import { superAuthApi } from "../../spec/apis"; | ||
import { TestWrapper, mockUrqlClient } from "../../spec/testWrapper"; | ||
import { SignedInOrRedirect } from "../../src/components/SignedInOrRedirect"; | ||
|
||
describe("SignedInOrRedirectOrRedirect", () => { | ||
const { location } = window; | ||
const mockAssign = jest.fn(); | ||
|
||
beforeAll(() => { | ||
delete window.location; | ||
window.location = { assign: mockAssign }; | ||
}); | ||
|
||
afterEach(() => { | ||
mockAssign.mockClear(); | ||
}); | ||
|
||
afterAll(() => { | ||
window.location = location; | ||
}); | ||
|
||
test("redirects when signed out", () => { | ||
const component = ( | ||
<h1> | ||
<SignedInOrRedirect>Hello, Jane!</SignedInOrRedirect> | ||
</h1> | ||
); | ||
|
||
const { rerender } = render(component, { wrapper: TestWrapper(superAuthApi) }); | ||
|
||
expect(mockUrqlClient.executeQuery).toBeCalledTimes(1); | ||
mockUrqlClient.executeQuery.pushResponse("currentSession", { | ||
data: { | ||
currentSession: { | ||
id: "123", | ||
userId: null, | ||
user: null, | ||
}, | ||
}, | ||
stale: false, | ||
hasNext: false, | ||
}); | ||
|
||
rerender(component); | ||
expect(mockAssign).toHaveBeenCalledTimes(1); | ||
expect(mockAssign).toHaveBeenCalledWith("/auth/signin"); | ||
}); | ||
|
||
test("renders when signed in", () => { | ||
const component = ( | ||
<h1> | ||
<SignedInOrRedirect>Hello, Jane!</SignedInOrRedirect> | ||
</h1> | ||
); | ||
|
||
const { container, rerender } = render(component, { wrapper: TestWrapper(superAuthApi) }); | ||
|
||
expect(mockUrqlClient.executeQuery).toBeCalledTimes(1); | ||
mockUrqlClient.executeQuery.pushResponse("currentSession", { | ||
data: { | ||
currentSession: { | ||
id: "123", | ||
userId: "321", | ||
user: { | ||
id: "321", | ||
firstName: "Jane", | ||
lastName: "Doe", | ||
}, | ||
}, | ||
}, | ||
stale: false, | ||
hasNext: false, | ||
}); | ||
|
||
rerender(component); | ||
|
||
expect(mockAssign).not.toBeCalled(); | ||
expect(container.outerHTML).toMatchInlineSnapshot(`"<div><h1>Hello, Jane!</h1></div>"`); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,5 +1,64 @@ | ||
import "@testing-library/jest-dom"; | ||
import { render } from "@testing-library/react"; | ||
import React from "react"; | ||
import { superAuthApi } from "../../spec/apis"; | ||
import { TestWrapper, mockUrqlClient } from "../../spec/testWrapper"; | ||
import { SignedOut } from "../../src/components/SignedOut"; | ||
|
||
describe("SignedOut", () => { | ||
test("renders without crashing", () => { | ||
expect(true).toBe(false); | ||
test("renders children when signed out", () => { | ||
const component = ( | ||
<h1> | ||
Hello<SignedOut>, Jane!</SignedOut> | ||
</h1> | ||
); | ||
|
||
const { container, rerender } = render(component, { wrapper: TestWrapper(superAuthApi) }); | ||
|
||
expect(mockUrqlClient.executeQuery).toBeCalledTimes(1); | ||
mockUrqlClient.executeQuery.pushResponse("currentSession", { | ||
data: { | ||
currentSession: { | ||
id: "123", | ||
userId: null, | ||
user: null, | ||
}, | ||
}, | ||
stale: false, | ||
hasNext: false, | ||
}); | ||
|
||
rerender(component); | ||
expect(container.outerHTML).toMatchInlineSnapshot(`"<div><h1>Hello, Jane!</h1></div>"`); | ||
}); | ||
|
||
test("renders nothing when signed in", () => { | ||
const component = ( | ||
<h1> | ||
Hello<SignedOut>, Jane!</SignedOut> | ||
</h1> | ||
); | ||
|
||
const { container, rerender } = render(component, { wrapper: TestWrapper(superAuthApi) }); | ||
|
||
expect(mockUrqlClient.executeQuery).toBeCalledTimes(1); | ||
mockUrqlClient.executeQuery.pushResponse("currentSession", { | ||
data: { | ||
currentSession: { | ||
id: "123", | ||
userId: "321", | ||
user: { | ||
id: "321", | ||
firstName: "Jane", | ||
lastName: "Doe", | ||
}, | ||
}, | ||
}, | ||
stale: false, | ||
hasNext: false, | ||
}); | ||
|
||
rerender(component); | ||
expect(container.outerHTML).toMatchInlineSnapshot(`"<div><h1>Hello</h1></div>"`); | ||
}); | ||
}); |
Oops, something went wrong.