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,42 +1,36 @@
|
||||
import { getRandomInt } from '../../../src/utils/jsUtils';
|
||||
import { loginWithFixtures } from '../../support/intercept';
|
||||
|
||||
describe('Create 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();
|
||||
});
|
||||
describe('Create an Account', () => {
|
||||
beforeEach(() => {
|
||||
loginWithFixtures();
|
||||
// Override: new usernames should return 404 (account doesn't exist yet)
|
||||
cy.intercept('GET', '/api/users/unit-test-*', {
|
||||
statusCode: 404,
|
||||
body: { detail: 'Not found' },
|
||||
}).as('checkNewUser');
|
||||
cy.visit('/account-admin');
|
||||
cy.wait('@getUsers');
|
||||
});
|
||||
|
||||
it('Create a new account; role is admin; should appear Saved message', () => {
|
||||
cy.contains('button', 'Create New').should('be.visible');
|
||||
cy.contains('button', 'Create New').click();
|
||||
|
||||
const randomNumber = getRandomInt(1000);
|
||||
|
||||
// 將整數轉換為四位數字串,並補零
|
||||
const fourDigitString = randomNumber.toString().padStart(4, '0');
|
||||
it('Create a new account with admin role; should show saved message.', () => {
|
||||
cy.contains('button', 'Create New').should('be.visible').click();
|
||||
|
||||
// 將 'unit-test-' 和生成的四位數字串組合
|
||||
const inputValue = `unit-test-${fourDigitString}`;
|
||||
cy.get('#input_account_field').type('unit-test-0001');
|
||||
cy.get('#input_name_field').type('unit-test-0001');
|
||||
cy.get('#input_first_pwd').type('aaaaaa');
|
||||
cy.get('.checkbox-and-text').first().find('div').first().click();
|
||||
|
||||
// 在 id 為 input_account_field 的 input 元素內填入值
|
||||
cy.get('#input_account_field').type(inputValue);
|
||||
cy.get('#input_name_field').type(inputValue);
|
||||
cy.get('#input_first_pwd').type('aaaaaa');
|
||||
cy.get('#input_second_pwd').type('aaaaaa');
|
||||
cy.get('.checkbox-and-text').first().find('div').first().click();
|
||||
// 確保 Confirm 按鈕存在並可點擊
|
||||
cy.contains('button', 'Confirm')
|
||||
.should('be.visible')
|
||||
.and('be.enabled')
|
||||
.click();
|
||||
cy.contains('Account added').should('be.visible'); //表示帳號創建成功
|
||||
});
|
||||
cy.contains('button', 'Confirm')
|
||||
.should('be.visible')
|
||||
.and('be.enabled')
|
||||
.click();
|
||||
cy.wait('@postUser');
|
||||
cy.contains('Account added').should('be.visible');
|
||||
});
|
||||
|
||||
it('Confirm button is disabled when required fields are empty.', () => {
|
||||
cy.contains('button', 'Create New').should('be.visible').click();
|
||||
cy.get('#input_account_field').type('test');
|
||||
cy.contains('button', 'Confirm').should('be.disabled');
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user