Files
lucia-frontend/cypress/e2e/accountAdmin/confirmPasswordMessage.cy.js
2024-08-13 13:24:05 +08:00

44 lines
1.6 KiB
JavaScript

import { getRandomInt } from '../../../src/utils/jsUtils';
const MSG_PWD_NOT_MATCHED = 'Confirm Password does not match.';
describe('Confirm that two input passwords are equal.', ()=>{
beforeEach(() => {
cy.visit('https://REDACTED-HOST/account-admin');
const username = 'cindy';
const password = Cypress.env('loginPwd');
cy.visit('https://REDACTED-HOST/account-admin');
cy.get('input[id="account"]').type(username);
cy.get('input[id="password"]').type(password);
cy.get('button[type="submit"]').click();
});
it('Confirm that when creating an account, the two input password fields are equal; otherwise, show the 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');
// 將 'unit-test-' 和生成的四位數字串組合
const inputValue = `unit-test-${fourDigitString}`;
// 在 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('bbbbbb');
// 確保 Confirm 按鈕存在並可點擊
cy.contains('button', 'Confirm')
.should('be.visible')
.and('be.enabled')
.click();
cy.contains(MSG_PWD_NOT_MATCHED).should('be.visible');
});
});