@@ -40,54 +40,47 @@ export const LoggedIn = meta.story({
4040 } ,
4141} )
4242
43+ LoggedIn . test ( 'log out should delete cookie' , async ( { canvas, userEvent } ) => {
44+ await expect ( ( await cookies ( ) ) . get ( userCookieKey ) ?. value ) . toContain ( 'storybookjs' )
45+ await userEvent . click ( await canvas . findByRole ( 'button' , { name : 'logout' } ) )
46+ await expectToHaveBeenNavigatedTo ( { pathname : '/' } )
47+ await expect ( ( await cookies ( ) ) . get ( userCookieKey ) ) . toBeUndefined ( )
48+ } )
49+
4350export const NotLoggedIn = meta . story ( )
4451
45- export const LoginShouldGetOAuthTokenAndSetCookie = meta . story ( {
46- parameters : {
47- msw : {
48- // Mock out OAUTH
49- handlers : [
50- http . post ( 'https://github.com/login/oauth/access_token' , async ( { request } ) => {
51- let json = ( await request . json ( ) ) as any
52- return Response . json ( { access_token : json . code } )
53- } ) ,
54- http . get ( 'https://api.github.com/user' , async ( { request } ) =>
55- Response . json ( {
56- login : request . headers . get ( 'Authorization' ) ?. replace ( 'token ' , '' ) ,
52+ NotLoggedIn . test (
53+ 'login should get oauth token and set cookie' ,
54+ {
55+ parameters : {
56+ msw : {
57+ // Mock out OAUTH
58+ handlers : [
59+ http . post ( 'https://github.com/login/oauth/access_token' , async ( { request } ) => {
60+ let json = ( await request . json ( ) ) as any
61+ return Response . json ( { access_token : json . code } )
5762 } ) ,
58- ) ,
59- ] ,
63+ http . get ( 'https://api.github.com/user' , async ( { request } ) =>
64+ Response . json ( {
65+ login : request . headers . get ( 'Authorization' ) ?. replace ( 'token ' , '' ) ,
66+ } ) ,
67+ ) ,
68+ ] ,
69+ } ,
70+ } ,
71+ async beforeEach ( ) {
72+ mocked ( login ) . mockImplementation ( async ( ) => {
73+ return await auth . GET ( new Request ( '/auth?code=storybookjs' ) )
74+ } )
6075 } ,
6176 } ,
62- play : async ( { mount, userEvent } ) => {
63- // Point the login implementation to the endpoint github would have redirected too.
64- mocked ( login ) . mockImplementation ( async ( ) => {
65- return await auth . GET ( new Request ( '/auth?code=storybookjs' ) )
66- } )
67- const canvas = await mount ( )
77+ async ( { canvas, userEvent } ) => {
6878 await expect ( ( await cookies ( ) ) . get ( userCookieKey ) ?. value ) . toBeUndefined ( )
6979 await userEvent . click ( await canvas . findByRole ( 'menuitem' , { name : / l o g i n t o a d d / i } ) )
7080 await expectToHaveBeenNavigatedTo ( { pathname : '/' } )
7181 await expect ( ( await cookies ( ) ) . get ( userCookieKey ) ?. value ) . toContain ( 'storybookjs' )
7282 } ,
73- } )
74-
75- export const LogoutShouldDeleteCookie = meta . story ( {
76- play : async ( { mount, userEvent } ) => {
77- ; ( await cookies ( ) ) . set ( userCookieKey , await createUserCookie ( 'storybookjs' ) )
78- const canvas = await mount ( )
79- await expect ( ( await cookies ( ) ) . get ( userCookieKey ) ?. value ) . toContain ( 'storybookjs' )
80- await userEvent . click ( await canvas . findByRole ( 'button' , { name : 'logout' } ) )
81- await expectToHaveBeenNavigatedTo ( { pathname : '/' } )
82- await expect ( ( await cookies ( ) ) . get ( userCookieKey ) ) . toBeUndefined ( )
83- } ,
84- } )
85-
86- // export const SearchInputShouldFilterNotes = meta.story({
87- // parameters: {
88- // nextjs: { navigation: { query: { q: 'RSC' } } },
89- // },
90- // })
83+ )
9184
9285export const EmptyState = meta . story ( {
9386 async beforeEach ( ) {
@@ -98,3 +91,9 @@ export const EmptyState = meta.story({
9891export const Loading = meta . story ( {
9992 render : ( ) => < NoteSkeleton /> ,
10093} )
94+
95+ // export const SearchInputShouldFilterNotes = meta.story({
96+ // parameters: {
97+ // nextjs: { navigation: { query: { q: 'RSC' } } },
98+ // },
99+ // })
0 commit comments