Skip to content

Commit 1a5623a

Browse files
test: add e2e tests to add and edit application password expiry
1 parent 3d31c0d commit 1a5623a

1 file changed

Lines changed: 57 additions & 1 deletion

File tree

tests/e2e/specs/profile/applications-passwords.test.js

Lines changed: 57 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,56 @@ test.describe( 'Manage applications passwords', () => {
4040
);
4141
} );
4242

43+
test('should correctly create a new application password with expiration', async ( {
44+
page,
45+
applicationPasswords
46+
} ) => {
47+
const expiresDate = new Date();
48+
expiresDate.setDate( expiresDate.getDate() + 7 );
49+
const expiresString = expiresDate.toISOString().split( 'T' )[ 0 ];
50+
51+
await applicationPasswords.create( TEST_APPLICATION_NAME, expiresString );
52+
53+
const [ app ] = await applicationPasswords.get();
54+
expect( app['name'] ).toBe( TEST_APPLICATION_NAME );
55+
expect( app['expires'] ).not.toBeNull();
56+
expect( app['expires'].startsWith( expiresString ) ).toBe( true );
57+
58+
const successMessage = page.getByRole( 'alert' );
59+
await expect( successMessage ).toHaveClass( /notice-success/ );
60+
} );
61+
62+
test('should correctly update an application password expiration date', async ( {
63+
page,
64+
applicationPasswords
65+
} ) => {
66+
await applicationPasswords.create();
67+
68+
const [ app ] = await applicationPasswords.get();
69+
expect( app['expires'] ).toBeNull();
70+
71+
const editButton = page.getByRole( 'button', { name: 'Edit Expiration Date' } );
72+
await expect( editButton ).toBeVisible();
73+
await editButton.click();
74+
75+
const expiresInput = page.locator( '.edit-expires-input' );
76+
await expect( expiresInput ).toBeVisible();
77+
78+
const expiresDate = new Date();
79+
expiresDate.setDate( expiresDate.getDate() + 10 );
80+
const expiresString = expiresDate.toISOString().split( 'T' )[ 0 ];
81+
await expiresInput.fill( expiresString );
82+
83+
const saveButton = page.getByRole( 'button', { name: 'Save' } );
84+
await saveButton.click();
85+
86+
await expect( page.getByRole( 'alert' ) ).toContainText( 'Application password expiration updated.' );
87+
88+
const [ updatedApp ] = await applicationPasswords.get();
89+
expect( updatedApp['expires'] ).not.toBeNull();
90+
expect( updatedApp['expires'].startsWith( expiresString ) ).toBe( true );
91+
} );
92+
4393
test( 'should correctly revoke a single application password', async ( {
4494
page,
4595
applicationPasswords
@@ -94,13 +144,19 @@ class ApplicationPasswords {
94144
this.admin = admin;
95145
}
96146

97-
async create(applicationName = TEST_APPLICATION_NAME) {
147+
async create(applicationName = TEST_APPLICATION_NAME, expires = null) {
98148
await this.admin.visitAdminPage( '/profile.php' );
99149

100150
const newPasswordField = this.page.getByRole( 'textbox', { name: 'New Application Password Name' } );
101151
await expect( newPasswordField ).toBeVisible();
102152
await newPasswordField.fill( applicationName );
103153

154+
if ( expires ) {
155+
const newPasswordExpiresField = this.page.getByLabel( 'Expires on' );
156+
await expect( newPasswordExpiresField ).toBeVisible();
157+
await newPasswordExpiresField.fill( expires );
158+
}
159+
104160
await this.page.getByRole( 'button', { name: 'Add Application Password' } ).click();
105161
await expect( this.page.getByRole( 'alert' ) ).toBeVisible();
106162
}

0 commit comments

Comments
 (0)