-
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
2a60a93
commit 2786e79
Showing
11 changed files
with
207 additions
and
29 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,26 @@ | ||
import { render } from "@testing-library/react"; | ||
import React from "react"; | ||
import { SignedIn } from "../../src/components/SignedIn"; | ||
import { TestWrapperWithAuth } from "../testWrapper"; | ||
import '@testing-library/jest-dom' | ||
|
||
describe("SignedIn", () => { | ||
test("renders without crashing", () => { | ||
expect(true).toBe(false); | ||
test("renders children when signed in", () => { | ||
// TODO: mock useSession hook | ||
const { getByText} = render(( | ||
<h1> | ||
Hello<SignedIn>, Jane!</SignedIn> | ||
</h1> | ||
), { wrapper: TestWrapperWithAuth }); | ||
expect(getByText('Hello, Jane!')).toBeInTheDocument() | ||
}); | ||
|
||
test("renders nothing when signed out", () => { | ||
const { getByText} = render(( | ||
<h1> | ||
Hello<SignedIn>, Jane!</SignedIn> | ||
</h1> | ||
), { wrapper: TestWrapperWithAuth }); | ||
expect(getByText(', Jane!')).not.toBeInTheDocument() | ||
}); | ||
}); |
43 changes: 40 additions & 3 deletions
43
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,42 @@ | ||
describe("SignedInOrRedirect", () => { | ||
test("renders without crashing", () => { | ||
expect(true).toBe(false); | ||
import { render } from "@testing-library/react"; | ||
import React from "react"; | ||
import { SignedInOrRedirect } from "../../src/components/SignedInOrRedirect"; | ||
import { TestWrapperWithAuth } from "../testWrapper"; | ||
import '@testing-library/jest-dom' | ||
|
||
describe("SignedInOrRedirectOrRedirect", () => { | ||
test("redirects when signed out", () => { | ||
render(( | ||
<SignedInOrRedirect> | ||
Hello, Jane! | ||
</SignedInOrRedirect> | ||
), { wrapper: TestWrapperWithAuth }); | ||
|
||
const mockAssign = jest.fn(); | ||
Object.defineProperty(window, 'location', { | ||
value: { | ||
assign: mockAssign, | ||
} | ||
}); | ||
|
||
expect(mockAssign).toHaveBeenCalledWith('/auth/signin'); | ||
}); | ||
|
||
test("renders when signed in", () => { | ||
const { getByText} = render(( | ||
<h1> | ||
Hello<SignedInOrRedirect>, Jane!</SignedInOrRedirect> | ||
</h1> | ||
), { wrapper: TestWrapperWithAuth }); | ||
|
||
const mockAssign = jest.fn(); | ||
Object.defineProperty(window, 'location', { | ||
value: { | ||
assign: mockAssign, | ||
} | ||
}); | ||
|
||
expect(mockAssign).not.toBeCalled(); | ||
expect(getByText(', Jane!')).not.toBeInTheDocument(); | ||
}); | ||
}); |
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,26 @@ | ||
import { render } from "@testing-library/react"; | ||
import React from "react"; | ||
import { SignedOut } from "../../src/components/SignedOut"; | ||
import { TestWrapperWithAuth } from "../testWrapper"; | ||
import '@testing-library/jest-dom' | ||
|
||
describe("SignedOut", () => { | ||
test("renders without crashing", () => { | ||
expect(true).toBe(false); | ||
test("renders children when signed out", () => { | ||
const { getByText} = render(( | ||
<h1> | ||
Hello<SignedOut>, Jane!</SignedOut> | ||
</h1> | ||
), { wrapper: TestWrapperWithAuth }); | ||
expect(getByText('Hello, Jane!')).toBeInTheDocument() | ||
}); | ||
|
||
test("renders nothing when signed in", () => { | ||
// TODO: mock useSession hook | ||
const { getByText} = render(( | ||
<h1> | ||
Hello<SignedOut>, Jane!</SignedOut> | ||
</h1> | ||
), { wrapper: TestWrapperWithAuth }); | ||
expect(getByText(', Jane!')).not.toBeInTheDocument() | ||
}); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import type { GadgetSession } from "./useSession"; | ||
|
||
export const isSessionSignedOut = (session: GadgetSession) => { | ||
return session?.userId == undefined; | ||
} | ||
|
||
export const isSessionSignedIn = (session: GadgetSession) => { | ||
return !isSessionSignedOut(session); | ||
} |
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
Oops, something went wrong.