44 generateUniqueUsername ,
55 navigateTo ,
66 selectVuetifyOptionByName ,
7+ expectToHaveUrl ,
78} from "../utils/helpers" ;
89
910async function setupCreateUserAccountPage ( page : Page ) {
@@ -15,12 +16,10 @@ async function setupCreateUserAccountPage(page: Page) {
1516 const institutionSelectLocator = page . getByTestId (
1617 "createUserAccount-institution-select" ,
1718 ) ;
18-
1919 const roleSelectLocator = page . getByTestId ( "createUserAccount-role-select" ) ;
2020
2121 // fields
2222 const usernameLocator = page . getByLabel ( / u s e r n a m e / i) ;
23-
2423 const nameLocator = page
2524 . getByTestId ( "createUserAccount-name-input" )
2625 . getByRole ( "textbox" ) ;
@@ -38,6 +37,7 @@ async function setupCreateUserAccountPage(page: Page) {
3837 . getByTestId ( "createUserAccount-confirmPassword-input" )
3938 . getByRole ( "textbox" ) ;
4039
40+ // buttons
4141 const saveButtonLocator = page . getByTestId ( "createUserAccount-save-button" ) ;
4242 const cancelButtonLocator = page . getByTestId (
4343 "createUserAccount-cancel-button" ,
@@ -57,12 +57,6 @@ async function setupCreateUserAccountPage(page: Page) {
5757 } ;
5858}
5959
60- async function expectSuccessfulCreateRedirect ( page : Page ) {
61- await expect ( page ) . toHaveURL ( / \/ u s e r - a c c o u n t s (?: $ | [ ? # ] ) / i, {
62- timeout : 10_000 ,
63- } ) ;
64- }
65-
6660//TODO this test was left with kinda big redundancies to explain to the apprentices in simple terms what is going on. Small refactor later
6761test . describe ( "1.1 User Accounts - CREATE Add" , ( ) => {
6862 test . beforeEach ( async ( { page } ) => {
@@ -160,7 +154,7 @@ test.describe("1.1 User Accounts - CREATE Add", () => {
160154
161155 expect ( actualPayload ) . toMatchObject ( expectedPayload ) ;
162156
163- await expectSuccessfulCreateRedirect ( page ) ;
157+ await expectToHaveUrl ( page , "user-accounts" ) ;
164158
165159 //note that this test does not test if the backend actually saves the data correctly. This could be done in 2 ways:
166160 // 1: Navigate to User accounts, search for the username entered in the test, and look at the details - This however creates a dependency on get all, and get by id working. If one of those is broken, this test would fail too
@@ -243,7 +237,7 @@ test.describe("1.1 User Accounts - CREATE Add", () => {
243237 ) ;
244238
245239 // expected to not change URL
246- await expect ( page ) . toHaveURL ( / \/ u s e r - a c c o u n t s \ /c r e a t e (?: $ | [ ? # ] ) / i ) ;
240+ await expectToHaveUrl ( page , " user-accounts/create" ) ;
247241 } ) ;
248242
249243 test ( "C Server Error - user account already exists (duplicate username)" , async ( {
@@ -313,8 +307,7 @@ test.describe("1.1 User Accounts - CREATE Add", () => {
313307 expect ( createResponse . status ( ) ) . toBe ( 400 ) ;
314308 expect ( createResponse . ok ( ) ) . toBeFalsy ( ) ;
315309
316- await expect ( page ) . toHaveURL ( / \/ u s e r - a c c o u n t s \/ c r e a t e (?: $ | [ ? # ] ) / i) ;
317-
310+ await expectToHaveUrl ( page , "user-accounts/create" ) ;
318311 //check toast
319312 const toast = page . locator ( ".toast-item[role='alert']" ) ;
320313
0 commit comments