1+ /// <reference types="cypress" />
2+
13describe ( 'Tạo bài tập mới' , ( ) => {
24 beforeEach ( ( ) => {
35 // Đăng nhập
46 cy . visit ( '/auth/identity/login' ) ;
57 cy . get ( '#username-input' ) . type ( 'admin' ) ;
6- cy . get ( '#password-input' ) . type ( 'admin123 ' ) ;
8+ cy . get ( '#password-input' ) . type ( 'adminRoot123 ' ) ;
79 cy . contains ( 'button' , 'Đăng nhập' ) . click ( ) ;
810
9- // Check đã vào trang list
11+ // Chọn tab "Bài tập"
12+ cy . contains ( 'a, button, li' , 'Bài tập' ) . click ( ) ;
1013 cy . url ( ) . should ( 'include' , '/exercise/exercise-layout/list' ) ;
1114 } ) ;
1215
1316 it ( 'Tạo bài tập thành công' , ( ) => {
1417 cy . fixture ( 'exercise-data' ) . then ( ( exercise ) => {
15- // Mở modal
16- cy . get ( 'app-btn-type1' ) . first ( ) . click ( ) ;
18+ // Click nút "Tạo thủ công"
19+ cy . get ( 'button[data-description="Tạo thủ công"]' )
20+ . should ( 'be.visible' )
21+ . click ( ) ;
1722
18- cy . get ( '. modal-content' ) . should ( 'be.visible' ) ;
19- cy . contains ( 'h2' , 'Tạo bài tập mới' ) . should ( 'exist ' ) ;
23+ // Đợi modal hiển thị
24+ cy . get ( 'app-exercise-modal' ) . should ( 'be.visible ' ) ;
2025
2126 // Step 1
2227 cy . get ( '#title' ) . type ( exercise . title ) ;
@@ -35,12 +40,32 @@ describe('Tạo bài tập mới', () => {
3540
3641 // Step 2
3742 cy . get ( '#description' ) . type ( exercise . description ) ;
38- cy . get ( '#orgId' ) . type ( exercise . orgId ) ;
43+
44+ // // 👉 Nếu có orgId trong data thì mới nhập và chọn, không thì bỏ qua
45+ // if (exercise.orgId && exercise.orgId.trim() !== '') {
46+ // cy.get('#orgSearch').type(exercise.orgId);
47+
48+ // // Chọn tổ chức đầu tiên trong dropdown (force: true)
49+ // cy.get('.dropdown-item').first().click({ force: true });
50+
51+ // // Kiểm tra đã chọn thành công
52+ // cy.get('.selected-org').should('contain.text', exercise.orgId);
53+ // } else {
54+ // cy.log('⚠️ Không có orgId trong fixture, bỏ qua bước chọn tổ chức');
55+ // }
56+
3957 cy . get ( '#startTime' ) . type ( exercise . startTime ) ;
4058 cy . get ( '#endTime' ) . type ( exercise . endTime ) ;
4159 cy . get ( '#duration' ) . type ( exercise . duration . toString ( ) ) ;
42- cy . get ( '#allowDiscussionId' ) . type ( exercise . allowDiscussionId ) ;
43- cy . get ( '#resourceIds' ) . type ( exercise . resourceIds ) ;
60+
61+ // Nếu có field allowDiscussionId & resourceIds trong FE thì giữ lại
62+ // if (exercise.allowDiscussionId) {
63+ // cy.get('#allowDiscussionId').type(exercise.allowDiscussionId);
64+ // }
65+ // if (exercise.resourceIds) {
66+ // cy.get('#resourceIds').type(exercise.resourceIds);
67+ // }
68+
4469 cy . get ( '#tags' ) . type ( exercise . tags ) ;
4570
4671 if ( exercise . allowAiQuestion ) {
@@ -49,12 +74,19 @@ describe('Tạo bài tập mới', () => {
4974 } ) ;
5075 }
5176
52- cy . contains ( 'button' , 'Tạo mới' ) . click ( ) ;
77+ // 👉 Click "Tạo mới"
78+ cy . contains ( 'button' , 'Tạo mới' ) . click ( { force : true } ) ;
5379
54- // ✅ Check modal đóng (không còn class open)
55- cy . get ( '.modal-create-overlay' ) . should ( 'not.have.class' , 'open' ) ;
80+ // // Check modal đóng
81+ // // Ổn định hơn
82+ // cy.get('app-exercise-modal input#title').should('not.exist');
83+ // // hoặc
84+ // cy.get('app-exercise-modal .modal-content').should(
85+ // 'not.have.class',
86+ // 'open'
87+ // );
5688
57- // ✅ Check notification thành công
89+ // Check notification thành công
5890 cy . get ( 'app-notification-card' )
5991 . should ( 'contain.text' , 'Tạo bài tập thành công!' )
6092 . and ( 'be.visible' ) ;
0 commit comments