Files
lucia-frontend/cypress/e2e/accountAdmin/editAccount.cy.js
2024-07-03 14:57:46 +08:00

43 lines
1.7 KiB
JavaScript

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'); //表示帳號創建成功
});
});