From 880cac23a476209438320b379b8d4e128ae4dc8d Mon Sep 17 00:00:00 2001 From: Cindy Chang Date: Wed, 3 Jul 2024 14:57:46 +0800 Subject: [PATCH] Cypress: edit account and see success message --- cypress/e2e/accountAdmin/editAccount.cy.js | 43 +++++++++++++++++++ .../AccountAdmin/AccountAdmin.vue | 16 +++---- 2 files changed, 51 insertions(+), 8 deletions(-) create mode 100644 cypress/e2e/accountAdmin/editAccount.cy.js diff --git a/cypress/e2e/accountAdmin/editAccount.cy.js b/cypress/e2e/accountAdmin/editAccount.cy.js new file mode 100644 index 0000000..9297974 --- /dev/null +++ b/cypress/e2e/accountAdmin/editAccount.cy.js @@ -0,0 +1,43 @@ +const TEST_ACCOUNT = 'tester-user'; +const MODAL_TITLE_ACCOUNT_EDIT = 'Account Edit'; +const MSG_ACCOUNT_EDITED = 'Saved'; + +describe('Edit an account', ()=>{ + beforeEach(() => { + cy.visit('https://REDACTED-HOST/account/account-admin'); + const username = 'cindy'; + const password = 'REDACTED-PWD'; + + cy.visit('https://REDACTED-HOST/account/account-admin'); + + cy.get('input[id="account"]').type(username); + cy.get('input[id="password"]').type(password); + cy.get('button[type="submit"]').click(); + }); + + it('Edit an account; modify name and see saved message.', () => { + cy.contains('.account-cell', TEST_ACCOUNT, { timeout: 10000 }).should('be.visible'); + // 找到包含 TEST_ACCOUNT 字串的 .account-cell 元素 + cy.contains('.account-cell', TEST_ACCOUNT, { timeout: 10000 }) + .parents('tr') // 找到 .account-cell 元素的祖先 tr 元素 + .find('.btn-edit') // 在該 tr 元素內找到 .btn-edit 按鈕 + .should('be.visible') // 驗證該按鈕可見 + .click(); // 點擊該按鈕 + + cy.contains('h1', MODAL_TITLE_ACCOUNT_EDIT).should('be.visible'); + const randomNumber = Math.floor(Math.random() * 1001); + // 將整數轉換為四位數字串,並補零 + const fourDigitString = randomNumber.toString().padStart(4, '0'); + cy.get('#input_name_field').type( TEST_ACCOUNT + fourDigitString); + cy.get('#input_first_pwd').type('aaaaaa'); + cy.get('#input_second_pwd').type('aaaaaa'); + + cy.contains('button', 'Confirm') + .should('be.visible') + .and('be.enabled') + .click(); + + cy.contains(MSG_ACCOUNT_EDITED).should('be.visible'); //表示帳號創建成功 + }); +}); + \ No newline at end of file diff --git a/src/views/AccountManagement/AccountAdmin/AccountAdmin.vue b/src/views/AccountManagement/AccountAdmin/AccountAdmin.vue index 7c76649..ed8a0e0 100644 --- a/src/views/AccountManagement/AccountAdmin/AccountAdmin.vue +++ b/src/views/AccountManagement/AccountAdmin/AccountAdmin.vue @@ -16,7 +16,7 @@