Rewrite old E2E tests to use fixture-based API mocking, eliminating need for real credentials
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -1,61 +1,27 @@
|
||||
import { getRandomInt } from '../../../src/utils/jsUtils';
|
||||
import { loginWithFixtures } from '../../support/intercept';
|
||||
|
||||
const TEST_ACCOUNT = '000000';
|
||||
const MODAL_TITLE_ACCOUNT_EDIT = 'Account Edit';
|
||||
const MSG_ACCOUNT_EDITED = 'Saved';
|
||||
const NUM_OF_SCROLLS = 5;
|
||||
|
||||
Cypress.Commands.add('manualScrollToBottom', (repeats = 20) => {
|
||||
for (let i = 0; i < repeats; i++) {
|
||||
cy.scrollTo('bottom', { duration: 500 });
|
||||
cy.wait(500);
|
||||
}
|
||||
describe('Edit an account', () => {
|
||||
beforeEach(() => {
|
||||
loginWithFixtures();
|
||||
cy.visit('/account-admin');
|
||||
cy.wait('@getUsers');
|
||||
});
|
||||
|
||||
it('Edit an account; modify name and see saved message.', () => {
|
||||
cy.get('.btn-edit').first().click();
|
||||
cy.wait('@getUserDetail');
|
||||
|
||||
cy.contains('h1', MODAL_TITLE_ACCOUNT_EDIT).should('exist');
|
||||
cy.get('#input_name_field').clear().type('Updated Name');
|
||||
|
||||
cy.contains('button', 'Confirm')
|
||||
.should('be.visible')
|
||||
.and('be.enabled')
|
||||
.click();
|
||||
cy.wait('@putUser');
|
||||
cy.contains(MSG_ACCOUNT_EDITED).should('be.visible');
|
||||
});
|
||||
});
|
||||
|
||||
describe('Edit an account', ()=>{
|
||||
beforeEach(() => {
|
||||
cy.visit('/account-admin');
|
||||
const username = Cypress.env('user').username;
|
||||
const password = Cypress.env('user').password;
|
||||
|
||||
cy.visit('/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.', () => {
|
||||
// 為了讓帳號出現,必須不斷往下滾動捲軸
|
||||
for(let i = 0; i < NUM_OF_SCROLLS; i++) {
|
||||
cy.get('#acct_mgmt_data_grid').scrollTo('bottom');
|
||||
cy.wait(500);
|
||||
}
|
||||
|
||||
|
||||
// 由於可能在畫面上是 hidden ,這邊使用 exist 而不是使用 visible
|
||||
cy.contains('.account-cell', TEST_ACCOUNT, { timeout: 10000 }).should('be.exist');
|
||||
// 找到包含 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.exist') // 驗證該按鈕可見
|
||||
.click(); // 點擊該按鈕
|
||||
|
||||
cy.contains('h1', MODAL_TITLE_ACCOUNT_EDIT).should('be.exist');
|
||||
const randomNumber = getRandomInt(1000);
|
||||
// 將整數轉換為四位數字串,並補零
|
||||
const fourDigitString = randomNumber.toString().padStart(4, '0');
|
||||
cy.get('#input_name_field').clear().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'); //表示帳號創建成功
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user