|
| 1 | +// vue-skuilder/cypress/e2e/course-registration.cy.js |
| 2 | +describe('Course Registration', () => { |
| 3 | + let username; |
| 4 | + |
| 5 | + beforeEach(() => { |
| 6 | + // Register a new user before each test |
| 7 | + cy.registerUser().then((user) => { |
| 8 | + username = user; |
| 9 | + // Wait for registration to complete and redirect |
| 10 | + cy.url().should('include', `/u/${username}/new`); |
| 11 | + }); |
| 12 | + }); |
| 13 | + |
| 14 | + it('should display available courses on the quilts page', () => { |
| 15 | + // Navigate to the quilts (courses) page |
| 16 | + cy.visit('/quilts'); |
| 17 | + |
| 18 | + // Check that the available courses section is visible |
| 19 | + cy.contains('h2', 'Available Quilts').should('be.visible'); |
| 20 | + |
| 21 | + // Verify that course cards are displayed |
| 22 | + cy.get('[data-cy="available-course-card"]').should('have.length.at.least', 1); |
| 23 | + }); |
| 24 | + |
| 25 | + it('should allow a user to register for a course', () => { |
| 26 | + // Navigate to the quilts page |
| 27 | + cy.visit('/quilts'); |
| 28 | + |
| 29 | + // Get the first available course and store its name |
| 30 | + cy.get('[data-cy="available-course-card"]') |
| 31 | + .first() |
| 32 | + .find('[data-cy="course-title"]') |
| 33 | + .invoke('text') |
| 34 | + .then((text) => { |
| 35 | + let courseName = text.trim(); |
| 36 | + |
| 37 | + // Now click the register button |
| 38 | + cy.get('[data-cy="available-course-card"]') |
| 39 | + .first() |
| 40 | + .find('[data-cy="register-course-button"]') |
| 41 | + .click(); |
| 42 | + |
| 43 | + // Wait a moment for registration to process |
| 44 | + cy.wait(1000); |
| 45 | + |
| 46 | + // Verify the course appears in the user's registered courses |
| 47 | + cy.get('[data-cy="registered-course"]').should('contain', courseName); |
| 48 | + }); |
| 49 | + }); |
| 50 | + |
| 51 | + it('should allow registration using the custom command', () => { |
| 52 | + // Register for the first available course |
| 53 | + cy.registerForCourse(); |
| 54 | + |
| 55 | + // Verify registration by checking the registered courses panel |
| 56 | + cy.get('[data-cy="registered-quilts-panel"]').click(); |
| 57 | + cy.get('[data-cy="registered-course"]').should('have.length.at.least', 1); |
| 58 | + }); |
| 59 | + |
| 60 | + it('should show registered courses on the study page', () => { |
| 61 | + // Register for a course first |
| 62 | + cy.registerForCourse(); |
| 63 | + |
| 64 | + // Navigate to the study page |
| 65 | + cy.visit('/study'); |
| 66 | + |
| 67 | + // Check that the registered course appears in the study options |
| 68 | + cy.get('[data-cy="select-quilts-header"]').should('be.visible'); |
| 69 | + cy.get('[data-cy="course-checkbox"]').should('have.length.at.least', 1); |
| 70 | + |
| 71 | + // Check that the start button is available |
| 72 | + cy.get('[data-cy="start-studying-button"]').should('be.visible'); |
| 73 | + }); |
| 74 | + |
| 75 | + it('should allow a user to drop a registered course', () => { |
| 76 | + // First register for a course |
| 77 | + cy.registerForCourse(); |
| 78 | + |
| 79 | + // Verify registration completed successfully |
| 80 | + cy.get('[data-cy="registered-course"]').should('have.length.at.least', 1); |
| 81 | + |
| 82 | + // Get the name of the registered course for later verification |
| 83 | + cy.get('[data-cy="registered-course-title"]') |
| 84 | + .first() |
| 85 | + .invoke('text') |
| 86 | + .then((courseName) => { |
| 87 | + // Click the drop button for this course |
| 88 | + cy.get('[data-cy="drop-course-button"]').first().click(); |
| 89 | + |
| 90 | + // Wait for the drop operation to complete |
| 91 | + cy.wait(1000); |
| 92 | + |
| 93 | + // Verify the course is no longer in registered courses |
| 94 | + cy.get('[data-cy="registered-course-title"]').should('not.exist'); |
| 95 | + |
| 96 | + // Check that the course appears again in available courses |
| 97 | + cy.contains('h2', 'Available Quilts') |
| 98 | + .parent() |
| 99 | + .find('[data-cy="course-title"]') |
| 100 | + .should('contain', courseName); |
| 101 | + }); |
| 102 | + }); |
| 103 | +}); |
0 commit comments