11import { expect , test } from "@playwright/test"
22import { firstSuperuser , firstSuperuserPassword } from "./config.ts"
33import { randomEmail , randomPassword } from "./utils/random"
4- import { logInUser , logOutUser , signUpNewUser } from "./utils/user"
4+ import { logInUser , logOutUser } from "./utils/user"
5+ import { createUser } from "./utils/privateApi.ts"
56
67const tabs = [ "My profile" , "Password" , "Appearance" ]
78
@@ -26,13 +27,11 @@ test.describe("Edit user full name and email successfully", () => {
2627 test . use ( { storageState : { cookies : [ ] , origins : [ ] } } )
2728
2829 test ( "Edit user name with a valid name" , async ( { page } ) => {
29- const fullName = "Test User"
3030 const email = randomEmail ( )
3131 const updatedName = "Test User 2"
3232 const password = randomPassword ( )
3333
34- // Sign up a new user
35- await signUpNewUser ( page , fullName , email , password )
34+ await createUser ( { email, password } )
3635
3736 // Log in the user
3837 await logInUser ( page , email , password )
@@ -50,13 +49,11 @@ test.describe("Edit user full name and email successfully", () => {
5049 } )
5150
5251 test ( "Edit user email with a valid email" , async ( { page } ) => {
53- const fullName = "Test User"
5452 const email = randomEmail ( )
5553 const updatedEmail = randomEmail ( )
5654 const password = randomPassword ( )
5755
58- // Sign up a new user
59- await signUpNewUser ( page , fullName , email , password )
56+ await createUser ( { email, password } )
6057
6158 // Log in the user
6259 await logInUser ( page , email , password )
@@ -77,13 +74,11 @@ test.describe("Edit user with invalid data", () => {
7774 test . use ( { storageState : { cookies : [ ] , origins : [ ] } } )
7875
7976 test ( "Edit user email with an invalid email" , async ( { page } ) => {
80- const fullName = "Test User"
8177 const email = randomEmail ( )
8278 const password = randomPassword ( )
8379 const invalidEmail = ""
8480
85- // Sign up a new user
86- await signUpNewUser ( page , fullName , email , password )
81+ await createUser ( { email, password } )
8782
8883 // Log in the user
8984 await logInUser ( page , email , password )
@@ -97,13 +92,11 @@ test.describe("Edit user with invalid data", () => {
9792 } )
9893
9994 test ( "Cancel edit action restores original name" , async ( { page } ) => {
100- const fullName = "Test User"
10195 const email = randomEmail ( )
10296 const password = randomPassword ( )
10397 const updatedName = "Test User"
10498
105- // Sign up a new user
106- await signUpNewUser ( page , fullName , email , password )
99+ const user = await createUser ( { email, password } )
107100
108101 // Log in the user
109102 await logInUser ( page , email , password )
@@ -114,18 +107,18 @@ test.describe("Edit user with invalid data", () => {
114107 await page . getByLabel ( "Full name" ) . fill ( updatedName )
115108 await page . getByRole ( "button" , { name : "Cancel" } ) . first ( ) . click ( )
116109 await expect (
117- page . getByLabel ( "My profile" ) . getByText ( fullName , { exact : true } ) ,
110+ page
111+ . getByLabel ( "My profile" )
112+ . getByText ( user . full_name as string , { exact : true } ) ,
118113 ) . toBeVisible ( )
119114 } )
120115
121116 test ( "Cancel edit action restores original email" , async ( { page } ) => {
122- const fullName = "Test User"
123117 const email = randomEmail ( )
124118 const password = randomPassword ( )
125119 const updatedEmail = randomEmail ( )
126120
127- // Sign up a new user
128- await signUpNewUser ( page , fullName , email , password )
121+ await createUser ( { email, password } )
129122
130123 // Log in the user
131124 await logInUser ( page , email , password )
@@ -147,13 +140,11 @@ test.describe("Change password successfully", () => {
147140 test . use ( { storageState : { cookies : [ ] , origins : [ ] } } )
148141
149142 test ( "Update password successfully" , async ( { page } ) => {
150- const fullName = "Test User"
151143 const email = randomEmail ( )
152144 const password = randomPassword ( )
153145 const NewPassword = randomPassword ( )
154146
155- // Sign up a new user
156- await signUpNewUser ( page , fullName , email , password )
147+ await createUser ( { email, password } )
157148
158149 // Log in the user
159150 await logInUser ( page , email , password )
@@ -177,13 +168,11 @@ test.describe("Change password with invalid data", () => {
177168 test . use ( { storageState : { cookies : [ ] , origins : [ ] } } )
178169
179170 test ( "Update password with weak passwords" , async ( { page } ) => {
180- const fullName = "Test User"
181171 const email = randomEmail ( )
182172 const password = randomPassword ( )
183173 const weakPassword = "weak"
184174
185- // Sign up a new user
186- await signUpNewUser ( page , fullName , email , password )
175+ await createUser ( { email, password } )
187176
188177 // Log in the user
189178 await logInUser ( page , email , password )
@@ -201,14 +190,12 @@ test.describe("Change password with invalid data", () => {
201190 test ( "New password and confirmation password do not match" , async ( {
202191 page,
203192 } ) => {
204- const fullName = "Test User"
205193 const email = randomEmail ( )
206194 const password = randomPassword ( )
207195 const newPassword = randomPassword ( )
208196 const confirmPassword = randomPassword ( )
209197
210- // Sign up a new user
211- await signUpNewUser ( page , fullName , email , password )
198+ await createUser ( { email, password } )
212199
213200 // Log in the user
214201 await logInUser ( page , email , password )
@@ -223,12 +210,10 @@ test.describe("Change password with invalid data", () => {
223210 } )
224211
225212 test ( "Current password and new password are the same" , async ( { page } ) => {
226- const fullName = "Test User"
227213 const email = randomEmail ( )
228214 const password = randomPassword ( )
229215
230- // Sign up a new user
231- await signUpNewUser ( page , fullName , email , password )
216+ await createUser ( { email, password } )
232217
233218 // Log in the user
234219 await logInUser ( page , email , password )
0 commit comments