1
- import { customRender , signInAsAdmin } from "./testUtils" ;
2
- import { screen , renderHook } from "@testing-library/react" ;
3
- import { useAtom , useSetAtom } from "jotai" ;
1
+ import { customRender , signIn } from "./testUtils" ;
2
+ import { screen , fireEvent } from "@testing-library/react" ;
4
3
5
4
import App from "@src/App" ;
6
5
import JotaiTestPage from "@src/pages/Test/JotaiTestPage" ;
7
6
8
- import { globalScope , currentUserAtom } from "@src/atoms/globalScope" ;
9
-
10
7
test ( "renders without crashing" , async ( ) => {
11
8
customRender ( < JotaiTestPage /> ) ;
12
9
expect ( await screen . findByText ( / S i g n i n w i t h G o o g l e / i) ) . toBeInTheDocument ( ) ;
@@ -16,18 +13,53 @@ test("renders without crashing", async () => {
16
13
) . toBeGreaterThan ( 0 ) ;
17
14
} ) ;
18
15
19
- test ( "signs in" , async ( ) => {
20
- const initialAtomValues = await signInAsAdmin ( ) ;
16
+ describe ( "sign in with roles" , ( ) => {
17
+ test ( "signs in as admin" , async ( ) => {
18
+ customRender ( < App /> , await signIn ( "admin" ) , true ) ;
19
+ expect ( ( await screen . findAllByText ( / t a b l e s / i) ) . length ) . toBeGreaterThan ( 0 ) ;
21
20
22
- customRender ( < App /> , initialAtomValues , true ) ;
23
- // const {
24
- // result: { current: currentUser },
25
- // } = renderHook(() => useSetAtom(currentUserAtom, globalScope) );
26
- // expect(currentUser).toBeDefined( );
21
+ const userMenuButton = screen . getByLabelText ( "Open user menu" ) ;
22
+ expect ( userMenuButton ) . toBeInTheDocument ( ) ;
23
+ fireEvent . click ( userMenuButton ) ;
24
+ expect ( await screen . findByText ( / a d m i n @ e x a m p l e . c o m / i ) ) . toBeInTheDocument ( ) ;
25
+ } ) ;
27
26
28
- // expect(await screen.findByText(/Loading/i)).toBeInTheDocument();
29
- expect ( ( await screen . findAllByText ( / t a b l e s d / i) ) . length ) . toBeGreaterThan ( 0 ) ;
30
- } ) ;
27
+ test ( "signs in as ops" , async ( ) => {
28
+ customRender ( < App /> , await signIn ( "ops" ) , true ) ;
29
+ expect ( ( await screen . findAllByText ( / t a b l e s / i) ) . length ) . toBeGreaterThan ( 0 ) ;
30
+
31
+ const userMenuButton = screen . getByLabelText ( "Open user menu" ) ;
32
+ expect ( userMenuButton ) . toBeInTheDocument ( ) ;
33
+ fireEvent . click ( userMenuButton ) ;
34
+ expect ( await screen . findByText ( / o p s @ e x a m p l e .c o m / i) ) . toBeInTheDocument ( ) ;
35
+ } ) ;
36
+
37
+ test ( "signs in as editor" , async ( ) => {
38
+ customRender ( < App /> , await signIn ( "editor" ) , true ) ;
39
+ expect ( ( await screen . findAllByText ( / t a b l e s / i) ) . length ) . toBeGreaterThan ( 0 ) ;
40
+
41
+ const userMenuButton = screen . getByLabelText ( "Open user menu" ) ;
42
+ expect ( userMenuButton ) . toBeInTheDocument ( ) ;
43
+ fireEvent . click ( userMenuButton ) ;
44
+ expect ( await screen . findByText ( / e d i t o r @ e x a m p l e .c o m / i) ) . toBeInTheDocument ( ) ;
45
+ } ) ;
31
46
32
- // TODO:
33
- // test("signs in without roles in auth")
47
+ test ( "signs in as viewer" , async ( ) => {
48
+ customRender ( < App /> , await signIn ( "viewer" ) , true ) ;
49
+ expect ( ( await screen . findAllByText ( / t a b l e s / i) ) . length ) . toBeGreaterThan ( 0 ) ;
50
+
51
+ const userMenuButton = screen . getByLabelText ( "Open user menu" ) ;
52
+ expect ( userMenuButton ) . toBeInTheDocument ( ) ;
53
+ fireEvent . click ( userMenuButton ) ;
54
+ expect ( await screen . findByText ( / v i e w e r @ e x a m p l e .c o m / i) ) . toBeInTheDocument ( ) ;
55
+ } ) ;
56
+
57
+ test ( "signs in with no roles" , async ( ) => {
58
+ customRender ( < App /> , await signIn ( "noRoles" ) , true ) ;
59
+
60
+ expect ( await screen . findByText ( / A c c e s s d e n i e d / i) ) . toBeInTheDocument ( ) ;
61
+ expect (
62
+ await screen . findByText ( / Y o u r a c c o u n t h a s n o r o l e s s e t / i)
63
+ ) . toBeInTheDocument ( ) ;
64
+ } ) ;
65
+ } ) ;
0 commit comments