@@ -2,21 +2,32 @@ import mockIssues1 from "../fixtures/issues-page-1.json";
22import mockIssues2 from "../fixtures/issues-page-2.json" ;
33import mockIssues3 from "../fixtures/issues-page-3.json" ;
44
5- describe ( "Project List" , ( ) => {
5+ describe ( "Issue List" , ( ) => {
66 beforeEach ( ( ) => {
7+ // setup request mocks
78 cy . intercept ( "GET" , "https://prolog-api.profy.dev/project" , {
89 fixture : "projects.json" ,
9- } ) ;
10+ } ) . as ( "getProjects" ) ;
1011 cy . intercept ( "GET" , "https://prolog-api.profy.dev/issue?page=1" , {
1112 fixture : "issues-page-1.json" ,
12- } ) ;
13+ } ) . as ( "getIssues" ) ;
1314 cy . intercept ( "GET" , "https://prolog-api.profy.dev/issue?page=2" , {
1415 fixture : "issues-page-2.json" ,
1516 } ) ;
1617 cy . intercept ( "GET" , "https://prolog-api.profy.dev/issue?page=3" , {
1718 fixture : "issues-page-3.json" ,
1819 } ) ;
20+
21+ // open issues page
1922 cy . visit ( "http://localhost:3000/issues" ) ;
23+
24+ // wait for request to resolve
25+ cy . wait ( "@getProjects" ) ;
26+ cy . wait ( "@getIssues" ) ;
27+
28+ // set button aliases
29+ cy . get ( "button" , { timeout : 10000 } ) . contains ( "Previous" ) . as ( "prev-button" ) ;
30+ cy . get ( "button" ) . contains ( "Next" ) . as ( "next-button" ) ;
2031 } ) ;
2132
2233 context ( "desktop resolution" , ( ) => {
@@ -25,8 +36,8 @@ describe("Project List", () => {
2536 } ) ;
2637
2738 it ( "renders the issues" , ( ) => {
28- cy . findByRole ( "main" )
29- . findAllByRole ( "row ")
39+ cy . get ( "main" )
40+ . find ( "tr ")
3041 . each ( ( $el , index ) => {
3142 // skip the header row
3243 if ( index === 0 ) return ;
@@ -43,38 +54,29 @@ describe("Project List", () => {
4354 it ( "paginates the data" , ( ) => {
4455 // test first page
4556 cy . contains ( "Page 1 of 3" ) ;
46- cy . findByRole ( "button" , { name : "Previous" } ) . should (
47- "have.attr" ,
48- "disabled"
49- ) ;
57+ cy . get ( "@prev-button" ) . should ( "have.attr" , "disabled" ) ;
5058
5159 // test navigation to second page
52- cy . findByRole ( "button" , { name : "Next" } ) . click ( ) ;
53- cy . findByRole ( "button" , { name : "Previous" } ) . should (
54- "not.have.attr" ,
55- "disabled"
56- ) ;
60+ cy . get ( "@next-button" ) . click ( ) ;
61+ cy . get ( "@prev-button" ) . should ( "not.have.attr" , "disabled" ) ;
5762 cy . contains ( "Page 2 of 3" ) ;
5863 cy . get ( "tbody tr:first" ) . contains ( mockIssues2 . items [ 0 ] . message ) ;
5964
6065 // test navigation to third and last page
61- cy . findByRole ( " button", { name : "Next" } ) . click ( ) ;
62- cy . findByRole ( " button", { name : "Next" } ) . should ( "have.attr" , "disabled" ) ;
66+ cy . get ( "@next- button") . click ( ) ;
67+ cy . get ( "@next- button") . should ( "have.attr" , "disabled" ) ;
6368 cy . contains ( "Page 3 of 3" ) ;
6469 cy . get ( "tbody tr:first" ) . contains ( mockIssues3 . items [ 0 ] . message ) ;
6570
6671 // test navigation back to second page
67- cy . findByRole ( "button" , { name : "Previous" } ) . click ( ) ;
68- cy . findByRole ( "button" , { name : "Next" } ) . should (
69- "not.have.attr" ,
70- "disabled"
71- ) ;
72+ cy . get ( "@prev-button" ) . click ( ) ;
73+ cy . get ( "@next-button" ) . should ( "not.have.attr" , "disabled" ) ;
7274 cy . contains ( "Page 2 of 3" ) ;
7375 cy . get ( "tbody tr:first" ) . contains ( mockIssues2 . items [ 0 ] . message ) ;
7476 } ) ;
7577
76- it ( "perists page after reload" , ( ) => {
77- cy . findByRole ( " button", { name : "Next" } ) . click ( ) ;
78+ it ( "persists page after reload" , ( ) => {
79+ cy . get ( "@next- button") . click ( ) ;
7880 cy . contains ( "Page 2 of 3" ) ;
7981
8082 cy . reload ( ) ;
0 commit comments