11package sandboxui
22
33import (
4+ "context"
5+ "errors"
46 "regexp"
57 "testing"
68
9+ "github.com/codeready-toolchain/toolchain-e2e/testsupport"
10+ "github.com/codeready-toolchain/toolchain-e2e/testsupport/cleanup"
711 sandboxui "github.com/codeready-toolchain/toolchain-e2e/testsupport/devsandbox-dashboard"
812 "github.com/playwright-community/playwright-go"
913 "github.com/spf13/viper"
1014 "github.com/stretchr/testify/assert"
1115 "github.com/stretchr/testify/require"
1216)
1317
14- // TestHomepage tests the homepage layout and welcome text
15- // when the user accesses the Developer Sandbox Dashboard for the first time
16- func TestHomepage (t * testing.T ) {
17- page := sandboxui .Setup (t , "test-homepage" )
18+ // TestFreshSignup tests the complete fresh signup flow:
19+ // 1. Homepage layout when first accessing the dashboard
20+ // 2. Clicking "Try it" to signup
21+ // 3. Accessing OpenShift after signup
22+ func TestFreshSignup (t * testing.T ) {
23+ // Step 1: Setup the browser and login (LoadConfig called inside Setup)
24+ page := sandboxui .Setup (t , "test-fresh-signup" )
25+
26+ // Ensure the user signup is not present in the system
27+ env := viper .GetString ("ENVIRONMENT" )
28+ username := viper .GetString ("SSO_USERNAME" )
29+ ensureNoUserSignup (t , env , username )
30+
31+ // Step 2: Verify homepage layout on first access
32+ verifyHomepage (t , page )
33+
34+ // Step 3: Perform signup by clicking "Try it"
35+ performSignup (t , page , env , username )
36+
37+ // Step 4: Verify OpenShift access
38+ verifyDevSandboxAccess (t , page , env )
39+ }
40+
41+ func ensureNoUserSignup (t * testing.T , env , username string ) {
42+ if env == sandboxui .TestEnv {
43+ awaitilities := testsupport .WaitForDeployments (t )
44+ hostAwait := awaitilities .Host ()
45+ userSignup , err := sandboxui .WaitForUserSignup (t , hostAwait , username )
46+ if err != nil && ! errors .Is (err , context .DeadlineExceeded ) {
47+ require .NoError (t , err ) // fail on unexpected errors
48+ }
49+ if userSignup != nil {
50+ // delete user signup
51+ err := sandboxui .DeleteUserSignup (t , hostAwait , userSignup )
52+ require .NoError (t , err )
53+ }
54+ }
55+ }
1856
57+ // verifyHomepage checks the homepage layout and welcome text
58+ // when the user accesses the Developer Sandbox Dashboard for the first time
59+ func verifyHomepage (t * testing.T , page playwright.Page ) {
1960 homeLink := page .Locator ("a" ).Filter (playwright.LocatorFilterOptions {
2061 HasText : "Home" ,
2162 })
@@ -43,11 +84,9 @@ func TestHomepage(t *testing.T) {
4384 require .NoError (t , err )
4485}
4586
46- // TestSignup tests the signup flow (automatically approved)
47- // when the user clicks on "Try it" for the first time
48- func TestSignup (t * testing.T ) {
49- page := sandboxui .Setup (t , "test-signup" )
50-
87+ // performSignup executes the signup flow by clicking "Try it"
88+ // and waits for the signup to be approved
89+ func performSignup (t * testing.T , page playwright.Page , env , username string ) {
5190 article := page .GetByRole ("article" )
5291 loadingIcon := page .Locator ("svg.v5-MuiCircularProgress-svg" ).First ()
5392
@@ -85,6 +124,15 @@ func TestSignup(t *testing.T) {
85124 err = tryItButton .Click ()
86125 require .NoError (t , err )
87126
127+ if env == sandboxui .TestEnv {
128+ // add signup to cleanup
129+ awaitilities := testsupport .WaitForDeployments (t )
130+ hostAwait := awaitilities .Host ()
131+ userSignup , err := sandboxui .WaitForUserSignup (t , hostAwait , username )
132+ require .NoError (t , err )
133+ cleanup .AddCleanTasks (t , hostAwait .Client , userSignup )
134+ }
135+
88136 // wait for loading icon to disappear
89137 err = loadingIcon .WaitFor (playwright.LocatorWaitForOptions {State : playwright .WaitForSelectorStateHidden })
90138 require .NoError (t , err )
@@ -100,18 +148,17 @@ func TestSignup(t *testing.T) {
100148 require .NoError (t , err )
101149
102150 trialText := article .GetByText ("Your free trial expires in 30 days" )
103- err = trialText .WaitFor ()
151+ err = trialText .WaitFor (playwright.LocatorWaitForOptions {
152+ Timeout : playwright .Float (30000 ),
153+ })
104154 require .NoError (t , err )
105155}
106156
107- // TestDevSandbox tests the access to Openshift after the user is signed up
108- func TestDevSandbox (t * testing.T ) {
109- page := sandboxui .Setup (t , "test-devsandbox" )
110- env := viper .GetString ("ENVIRONMENT" )
111-
157+ // verifyDevSandboxAccess tests access to OpenShift after the user is signed up
158+ func verifyDevSandboxAccess (t * testing.T , page playwright.Page , env string ) {
112159 imgName := "Red Hat OpenShift Service on"
113160 logMessage := "Log in with…"
114- if env == sandboxui .UIE2ETestsEnv {
161+ if env == sandboxui .TestEnv {
115162 imgName = "Red Hat OpenShift"
116163 logMessage = "Log in with"
117164 }
@@ -135,14 +182,16 @@ func TestDevSandbox(t *testing.T) {
135182
136183 sandboxui .IsVisible (t , tryItBtn )
137184
138- // open the article in a new popup and wait for it to fully load
185+ // open the "Try it" button in a new popup and wait for it to fully load
139186 devSandboxPage , err := sandboxui .ClickAndWaitForPopup (page , tryItBtn )
140187 require .NoError (t , err )
141188
142189 img := devSandboxPage .GetByRole ("img" , playwright.PageGetByRoleOptions {
143190 Name : imgName ,
144191 })
145- err = img .WaitFor ()
192+ err = img .WaitFor (playwright.LocatorWaitForOptions {
193+ Timeout : playwright .Float (30000 ),
194+ })
146195 require .NoError (t , err )
147196
148197 h := devSandboxPage .GetByRole ("heading" , playwright.PageGetByRoleOptions {})
0 commit comments