Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
58 changes: 45 additions & 13 deletions cypress/e2e/exercise-create.cy.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,27 @@
/// <reference types="cypress" />

describe('Tạo bài tập mới', () => {
beforeEach(() => {
// Đăng nhập
cy.visit('/auth/identity/login');
cy.get('#username-input').type('admin');
cy.get('#password-input').type('admin123');
cy.get('#password-input').type('adminRoot123');
cy.contains('button', 'Đăng nhập').click();

// Check đã vào trang list
// Chọn tab "Bài tập"
cy.contains('a, button, li', 'Bài tập').click();
cy.url().should('include', '/exercise/exercise-layout/list');
});

it('Tạo bài tập thành công', () => {
cy.fixture('exercise-data').then((exercise) => {
// Mở modal
cy.get('app-btn-type1').first().click();
// Click nút "Tạo thủ công"
cy.get('button[data-description="Tạo thủ công"]')
.should('be.visible')
.click();

cy.get('.modal-content').should('be.visible');
cy.contains('h2', 'Tạo bài tập mới').should('exist');
// Đợi modal hiển thị
cy.get('app-exercise-modal').should('be.visible');

// Step 1
cy.get('#title').type(exercise.title);
Expand All @@ -35,12 +40,32 @@ describe('Tạo bài tập mới', () => {

// Step 2
cy.get('#description').type(exercise.description);
cy.get('#orgId').type(exercise.orgId);

// // 👉 Nếu có orgId trong data thì mới nhập và chọn, không thì bỏ qua
// if (exercise.orgId && exercise.orgId.trim() !== '') {
// cy.get('#orgSearch').type(exercise.orgId);

// // Chọn tổ chức đầu tiên trong dropdown (force: true)
// cy.get('.dropdown-item').first().click({ force: true });

// // Kiểm tra đã chọn thành công
// cy.get('.selected-org').should('contain.text', exercise.orgId);
// } else {
// cy.log('⚠️ Không có orgId trong fixture, bỏ qua bước chọn tổ chức');
// }

cy.get('#startTime').type(exercise.startTime);
cy.get('#endTime').type(exercise.endTime);
cy.get('#duration').type(exercise.duration.toString());
cy.get('#allowDiscussionId').type(exercise.allowDiscussionId);
cy.get('#resourceIds').type(exercise.resourceIds);

// Nếu có field allowDiscussionId & resourceIds trong FE thì giữ lại
// if (exercise.allowDiscussionId) {
// cy.get('#allowDiscussionId').type(exercise.allowDiscussionId);
// }
// if (exercise.resourceIds) {
// cy.get('#resourceIds').type(exercise.resourceIds);
// }

cy.get('#tags').type(exercise.tags);

if (exercise.allowAiQuestion) {
Expand All @@ -49,12 +74,19 @@ describe('Tạo bài tập mới', () => {
});
}

cy.contains('button', 'Tạo mới').click();
// 👉 Click "Tạo mới"
cy.contains('button', 'Tạo mới').click({ force: true });

// ✅ Check modal đóng (không còn class open)
cy.get('.modal-create-overlay').should('not.have.class', 'open');
// // Check modal đóng
// // Ổn định hơn
// cy.get('app-exercise-modal input#title').should('not.exist');
// // hoặc
// cy.get('app-exercise-modal .modal-content').should(
// 'not.have.class',
// 'open'
// );

// Check notification thành công
// Check notification thành công
cy.get('app-notification-card')
.should('contain.text', 'Tạo bài tập thành công!')
.and('be.visible');
Expand Down
8 changes: 6 additions & 2 deletions cypress/e2e/login-form.cy.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
/// <reference types="cypress" />

describe('Trang đăng nhập', () => {
beforeEach(() => {
cy.visit('/auth/identity/login');
Expand All @@ -12,10 +14,12 @@ describe('Trang đăng nhập', () => {

it('Đăng nhập thành công với tài khoản hợp lệ', () => {
cy.get('#username-input').type('admin');
cy.get('#password-input').type('admin123');
cy.get('#password-input').type('adminRoot123');
cy.contains('button', 'Đăng nhập').click();

cy.url().should('include', '/exercise/exercise-layout/list');
// ✅ sửa lại URL cho đúng thực tế
cy.url().should('include', '/post-features/post-list');

cy.window().then((win) => {
expect(win.localStorage.getItem('token')).to.exist;
});
Expand Down
Loading