-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added inviter context and fixed some visual bugs.
- Loading branch information
1 parent
28ff609
commit 7df8773
Showing
10 changed files
with
100 additions
and
27 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { InviterContext, InviterContextProvider } from '@/contexts/inviter-context'; | ||
import '@testing-library/jest-dom'; | ||
import { cleanup, render, screen } from '@testing-library/react'; | ||
import { useContext } from 'react'; | ||
|
||
function MockChildComponent() { | ||
const {inviterInfo} = useContext(InviterContext); | ||
return ( | ||
<div data-testid="test">{inviterInfo ? inviterInfo.name : "your friend"}</div> | ||
); | ||
} | ||
|
||
describe('UserContextProvider', () => { | ||
afterEach(cleanup); | ||
it('defaults to an inviterInfo value of null.', () => { | ||
render( | ||
<InviterContextProvider> | ||
<MockChildComponent /> | ||
</InviterContextProvider> | ||
); | ||
const noInviter = screen.queryByTestId('test'); | ||
expect(noInviter).toHaveTextContent('your friend'); | ||
}); | ||
}); |
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,17 @@ | ||
import { Inviter } from "@/models/Inviter"; | ||
import { createContext, PropsWithChildren, useState } from "react"; | ||
|
||
export type InviterContextType = { | ||
inviterInfo:InviterInfo; | ||
} | ||
|
||
type InviterInfo = Inviter | null; | ||
|
||
//setting the default context to {activeUser:null} allows for testing unwrapped components | ||
export const InviterContext = createContext<InviterContextType>({inviterInfo: null}); | ||
|
||
export function InviterContextProvider({children}:PropsWithChildren) { | ||
const [inviterInfo,setInviterInfo] = useState<InviterInfo>(null); | ||
return <InviterContext.Provider value={{inviterInfo}}>{children}</InviterContext.Provider> | ||
} | ||
|
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,5 @@ | ||
export type Inviter = { | ||
name:string; | ||
avatar:'1' | '2' | '3' | '4'; | ||
inviterId:string; | ||
} |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.user-no-drag { | ||
-moz-drag-over: none; | ||
-webkit-user-drag: none; | ||
} |
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,6 @@ | ||
.user-no-select { | ||
-moz-user-select: none; | ||
-webkit-user-select: none; | ||
-ms-user-select: none; | ||
user-select: none; | ||
} |