@@ -6,68 +6,119 @@ import {
66} from "../../support/utils/projects" ;
77import { login } from "../../support/utils/general" ;
88import { User } from "../../support/types/user" ;
9+ import { validateLoginV2 } from "../../support/commands/general" ;
10+ import type { Project } from "../../support/types/projects" ;
911
1012const projectTestConfig = {
1113 projectAlreadyExists : false ,
12- projectName : generatorProjectName ( "dashboardV2" ) ,
14+ projectName : `project-dashboard-test- ${ getRandomString ( ) } ` ,
1315} ;
1416
15- const prefixProjectTitle = "My Renku Project" ;
16- const sessionId = [ "dashboard" , getRandomString ( ) ] ;
17+ const anonymousSession = {
18+ id : [ "dashboard-anonymousUser" , getRandomString ( ) ] ,
19+ setup : ( ) => {
20+ cy . log ( "Anonymous session" ) ;
21+ } ,
22+ } ;
23+ const loggedSession = {
24+ id : [ "dashboard-loggedUser" , getRandomString ( ) ] ,
25+ setup : ( ) => {
26+ cy . log ( "Logged in session" ) ;
27+ cy . robustLogin ( "v2" ) ;
28+ } ,
29+ } ;
1730
1831describe ( "Dashboard v2 - Authenticated user" , ( ) => {
19- const projectSlug = projectTestConfig . projectName ;
20- let projectId : string | null = null ;
21-
22- after ( ( ) => {
23- if ( ! projectTestConfig . projectAlreadyExists ) {
24- deleteProject ( projectId ) ;
25- }
26- } ) ;
32+ let projectId : string = "" ;
2733
28- beforeEach ( ( ) => {
29- login ( sessionId ) ;
34+ before ( ( ) => {
35+ cy . session ( loggedSession . id , loggedSession . setup , validateLoginV2 ) ;
3036
3137 getUserData ( ) . then ( ( user : User ) => {
3238 createProjectIfMissingV2 ( {
33- description : "Test project for dashboard tests" ,
34- name : `${ prefixProjectTitle } ${ projectSlug } ` ,
39+ name : projectTestConfig . projectName ,
3540 namespace : user . username ,
36- slug : projectSlug ,
41+ slug : projectTestConfig . projectName ,
42+ description : "Test project for dashboard tests" ,
3743 visibility : "private" ,
3844 } ) . then ( ( response ) => {
3945 projectId = response . body . id ;
4046 } ) ;
4147 } ) ;
4248 } ) ;
4349
44- it ( "Can see own project on the dashboard" , ( ) => {
50+ after ( ( ) => {
51+ if ( ! projectTestConfig . projectAlreadyExists ) {
52+ deleteProject ( projectId ) ;
53+ }
54+ } ) ;
55+
56+ beforeEach ( ( ) => {
57+ cy . session ( loggedSession . id , loggedSession . setup , validateLoginV2 ) ;
58+ } ) ;
59+
60+ it ( "Can see own project on the dashboard or in the search results" , ( ) => {
61+ let projectIsOnDashboard : boolean = false ;
62+ cy . intercept ( "/api/data/projects?direct_member=true*" , ( request ) => {
63+ request . on ( "after:response" , ( response ) => {
64+ expect ( response . statusCode ) . to . eq ( 200 ) ;
65+ const projects = response . body as Project [ ] ;
66+ projectIsOnDashboard = projects . some ( ( { id } ) => id === projectId ) ;
67+ } ) ;
68+ } ) . as ( "projectList" ) ;
69+
4570 cy . visit ( "/" ) ;
46- cy . getDataCy ( "dashboard-project-list" )
47- . find ( "a" )
48- . should ( "have.length.at.least" , 1 ) ;
49- cy . getDataCy ( "dashboard-project-list" )
50- . find ( "a" )
51- . should ( "contain.text" , `${ prefixProjectTitle } ${ projectSlug } ` ) ;
52- cy . getDataCy ( "dashboard-project-list" )
53- . find ( "a" )
54- . should ( "contain.text" , projectSlug ) ;
71+
72+ cy . wait ( "@projectList" ) . then ( ( ) => {
73+ cy . getDataCy ( "dashboard-project-list" )
74+ . find ( "a" )
75+ . should ( "have.length.at.least" , 1 ) ;
76+
77+ if ( projectIsOnDashboard ) {
78+ cy . getDataCy ( "dashboard-project-list" )
79+ . find ( "a" )
80+ . should ( "contain.text" , projectTestConfig . projectName ) ;
81+ cy . getDataCy ( "dashboard-project-list" )
82+ . find ( "a" )
83+ . should ( "contain.text" , projectTestConfig . projectName ) ;
84+ } else {
85+ cy . getDataCy ( "view-my-Projects-btn" )
86+ . contains ( new RegExp ( "View all my [0-9]+ projects" ) )
87+ . click ( ) ;
88+ cy . getDataCy ( "search-list-item" ) . should ( "have.length.at.least" , 1 ) ;
89+ cy . getDataCy ( "search-query-input" )
90+ . clear ( )
91+ . type ( projectTestConfig . projectName ) ;
92+ cy . getDataCy ( "search-query-button" ) . click ( ) ;
93+ cy . getDataCy ( "search-list-item" )
94+ . contains ( projectTestConfig . projectName )
95+ . should ( "be.visible" ) ;
96+ }
97+ } ) ;
5598 } ) ;
5699
57100 it ( "Can find project in the search results" , ( ) => {
58101 cy . visit ( "/" ) ;
59102 cy . getDataCy ( "view-my-Projects-btn" ) . click ( ) ;
60103 cy . getDataCy ( "search-list-item" ) . should ( "have.length.at.least" , 1 ) ;
61- cy . getDataCy ( "search-list-item" ) . should (
62- "contain.text" ,
63- `${ prefixProjectTitle } ${ projectSlug } ` ,
64- ) ;
104+ cy . getDataCy ( "search-query-input" )
105+ . clear ( )
106+ . type ( projectTestConfig . projectName ) ;
107+ cy . getDataCy ( "search-query-button" ) . click ( ) ;
108+ cy . getDataCy ( "search-list-item" )
109+ . contains ( projectTestConfig . projectName )
110+ . should ( "be.visible" ) ;
65111 } ) ;
66112} ) ;
67113
68114describe ( "Dashboard v2 - Non-Authenticated user" , ( ) => {
115+ beforeEach ( ( ) => {
116+ cy . session ( anonymousSession . id , anonymousSession . setup ) ;
117+ } ) ;
118+
69119 it ( "Cannot see projects and groups on Dashboard when logged out" , ( ) => {
70120 cy . visit ( "/" ) ;
121+ cy . get ( "#rk-anon-home-frame" ) . should ( "be.visible" ) ;
71122 cy . getDataCy ( "user-container" ) . should ( "not.exist" ) ;
72123 } ) ;
73124} ) ;
0 commit comments