|
| 1 | +// packages/common-ui/cypress/component/StudySessionTimer.cy.ts |
| 2 | +import StudySessionTimer from '../../src/components/StudySessionTimer.vue'; |
| 3 | + |
| 4 | +describe('StudySessionTimer', () => { |
| 5 | + it('renders correctly with default props', () => { |
| 6 | + cy.mount(StudySessionTimer, { |
| 7 | + props: { |
| 8 | + timeRemaining: 180, |
| 9 | + sessionTimeLimit: 5, |
| 10 | + }, |
| 11 | + }); |
| 12 | + |
| 13 | + // Check for the circular progress component |
| 14 | + cy.get('[role="progressbar"]').should('exist'); |
| 15 | + |
| 16 | + // Check for the formatted time text (visible in tooltip) |
| 17 | + cy.get('.v-tooltip').trigger('mouseenter'); |
| 18 | + cy.contains('3:00 left!').should('exist'); |
| 19 | + }); |
| 20 | + |
| 21 | + it('changes color when time is low', () => { |
| 22 | + cy.mount(StudySessionTimer, { |
| 23 | + props: { |
| 24 | + timeRemaining: 30, // 30 seconds (below 60 seconds threshold) |
| 25 | + sessionTimeLimit: 5, |
| 26 | + }, |
| 27 | + }); |
| 28 | + |
| 29 | + // Check for orange color class |
| 30 | + cy.get('[role="progressbar"]') |
| 31 | + .should('have.class', 'orange') |
| 32 | + .or('have.class', 'orange-darken-3'); |
| 33 | + |
| 34 | + // Check for the time text |
| 35 | + cy.get('.v-tooltip').trigger('mouseenter'); |
| 36 | + cy.contains('30 seconds left!').should('exist'); |
| 37 | + }); |
| 38 | + |
| 39 | + it('shows button on hover and emits add-time event when clicked', () => { |
| 40 | + const onAddTime = cy.spy().as('onAddTime'); |
| 41 | + |
| 42 | + cy.mount(StudySessionTimer, { |
| 43 | + props: { |
| 44 | + timeRemaining: 180, |
| 45 | + sessionTimeLimit: 5, |
| 46 | + 'onAdd-time': onAddTime, |
| 47 | + }, |
| 48 | + }); |
| 49 | + |
| 50 | + // Button should not be visible initially |
| 51 | + cy.get('button').should('not.be.visible'); |
| 52 | + |
| 53 | + // Button should appear on hover |
| 54 | + cy.get('.timer-container').trigger('mouseenter'); |
| 55 | + cy.get('button').should('be.visible'); |
| 56 | + |
| 57 | + // Click should emit event |
| 58 | + cy.get('button').click(); |
| 59 | + cy.get('@onAddTime').should('have.been.called'); |
| 60 | + }); |
| 61 | + |
| 62 | + it('does not show button when time is zero', () => { |
| 63 | + cy.mount(StudySessionTimer, { |
| 64 | + props: { |
| 65 | + timeRemaining: 0, |
| 66 | + sessionTimeLimit: 5, |
| 67 | + }, |
| 68 | + }); |
| 69 | + |
| 70 | + // Even on hover, button should not appear |
| 71 | + cy.get('.timer-container').trigger('mouseenter'); |
| 72 | + cy.get('button').should('not.exist'); |
| 73 | + }); |
| 74 | + |
| 75 | + it('displays correct percentage for progress indicator', () => { |
| 76 | + cy.mount(StudySessionTimer, { |
| 77 | + props: { |
| 78 | + timeRemaining: 150, // 2.5 minutes |
| 79 | + sessionTimeLimit: 5, // 5 minutes |
| 80 | + }, |
| 81 | + }); |
| 82 | + |
| 83 | + // Progress should be 50% (2.5 minutes of 5 minutes) |
| 84 | + cy.get('[role="progressbar"]').should('have.attr', 'aria-valuenow', '50'); |
| 85 | + }); |
| 86 | + |
| 87 | + it('displays correct percentage when under 60 seconds', () => { |
| 88 | + cy.mount(StudySessionTimer, { |
| 89 | + props: { |
| 90 | + timeRemaining: 30, // 30 seconds |
| 91 | + sessionTimeLimit: 5, // 5 minutes |
| 92 | + }, |
| 93 | + }); |
| 94 | + |
| 95 | + // Progress should be 50% (30 seconds of 60 seconds in the final minute) |
| 96 | + cy.get('[role="progressbar"]').should('have.attr', 'aria-valuenow', '50'); |
| 97 | + }); |
| 98 | +}); |
0 commit comments