1+ describe ( "Fetch Status" , ( ) => {
2+
3+ it ( "Fetch data with no authenticated user" , ( ) => {
4+
5+ cy . visit ( "/" ) ;
6+
7+ // Go immediately to query
8+ cy . contains ( "A book query testing sources with and without authentication required" ) . click ( ) ;
9+
10+ // Check if the public and restricted sources appear
11+ cy . get ( '[aria-label="Sources info"]' ) . click ( ) ;
12+
13+ cy . contains ( "http://localhost:8080/example/favourite-books" ) ;
14+ cy . contains ( "http://localhost:8080/example/wish-list" ) ;
15+
16+ // Check if the correct icons appear
17+ cy . get ( '[aria-label="Authentication required"]' ) . should ( "exist" ) ;
18+ cy . get ( '[aria-label="Fetch failed"]' ) . should ( "exist" ) ;
19+
20+ cy . get ( '[aria-label="No authentication required"]' ) . should ( "exist" ) ;
21+ cy . get ( '[aria-label="Fetch was succesful"]' ) . should ( "exist" ) ;
22+
23+
24+ // Checking that a non-authorized book is not appearing
25+ cy . contains ( "It Ends With Us" ) . should ( "not.exist" ) ;
26+
27+ // Checking that a book that we may see appears
28+ cy . contains ( "Too Late" ) ;
29+
30+ } ) ;
31+
32+ it ( "Fetch data with authenticated user" , ( ) => {
33+
34+ cy . visit ( "/" ) ;
35+
36+ // Login as user 'example'
37+ cy . get ( '[aria-label="Profile"]' ) . click ( ) ;
38+ cy . contains ( '[role="menuitem"]' , "Login" ) . click ( ) ;
39+
40+ cy . get ( 'input[name="idp"]' ) . clear ( ) ;
41+ cy . get ( 'input[name="idp"]' ) . type ( "http://localhost:8080" ) ;
42+ cy . contains ( "Login" ) . click ( ) ;
43+
44+ cy . get ( "input#email" ) . type ( "hello@example.com" ) ;
45+ cy . get ( "input#password" ) . type ( "abc123" ) ;
46+ cy . contains ( "button" , "Log in" ) . click ( ) ;
47+ cy . contains ( "button" , "Authorize" ) . click ( ) ;
48+
49+ cy . url ( ) . should ( "eq" , "http://localhost:5173/" ) ;
50+
51+ // Go to the mixed book query
52+ cy . contains ( "A book query testing sources with and without authentication required" ) . click ( ) ;
53+
54+ // Check if the public and restricted sources appear
55+ cy . get ( '[aria-label="Sources info"]' ) . click ( ) ;
56+
57+ cy . contains ( "http://localhost:8080/example/favourite-books" ) ;
58+ cy . contains ( "http://localhost:8080/example/wish-list" ) ;
59+
60+ // Check if the correct icons appear
61+ cy . get ( '[aria-label="Authentication required"]' ) . should ( "exist" ) ;
62+ cy . get ( '[aria-label="Fetch Failed"]' ) . should ( "not.exist" ) ;
63+
64+ cy . get ( '[aria-label="No authentication required"]' ) . should ( "exist" ) ;
65+ cy . get ( '[aria-label="Fetch was succesful"]' ) . should ( "exist" ) ;
66+
67+ // Checking that you see authorized books
68+ cy . contains ( "It Ends With Us" ) ;
69+ cy . contains ( "Too Late" ) ;
70+ } ) ;
71+
72+ } )
0 commit comments