Skip to content

Commit 7b75529

Browse files
committed
add test for StudySessionTimer
1 parent 17ee843 commit 7b75529

File tree

1 file changed

+72
-0
lines changed

1 file changed

+72
-0
lines changed
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
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+
isActive: true,
11+
showTooltip: true,
12+
},
13+
});
14+
15+
// Check for the circular progress component
16+
cy.get('[role="progressbar"]').should('exist');
17+
18+
// Check for the formatted time text
19+
cy.contains('3:00 left!').should('exist');
20+
21+
// Verify the button is visible when active
22+
cy.get('button').should('exist');
23+
cy.get('.mdi-plus').should('exist');
24+
});
25+
26+
it('changes color when time is low', () => {
27+
cy.mount(StudySessionTimer, {
28+
props: {
29+
timeRemaining: 30, // 30 seconds (below 60 seconds threshold)
30+
sessionTimeLimit: 5,
31+
isActive: true,
32+
showTooltip: true,
33+
},
34+
});
35+
36+
// Check for orange color class
37+
cy.get('[role="progressbar"]').should('exist');
38+
cy.contains('30 seconds left!').should('exist');
39+
});
40+
41+
it('emits add-time event when button is clicked', () => {
42+
const onAddTime = cy.spy().as('onAddTime');
43+
44+
cy.mount(StudySessionTimer, {
45+
props: {
46+
timeRemaining: 180,
47+
sessionTimeLimit: 5,
48+
isActive: true,
49+
showTooltip: true,
50+
},
51+
attrs: {
52+
onAddTime,
53+
},
54+
});
55+
56+
cy.get('button').click();
57+
cy.get('@onAddTime').should('have.been.called');
58+
});
59+
60+
it('does not show button when timer is not active', () => {
61+
cy.mount(StudySessionTimer, {
62+
props: {
63+
timeRemaining: 180,
64+
sessionTimeLimit: 5,
65+
isActive: false,
66+
showTooltip: true,
67+
},
68+
});
69+
70+
cy.get('button').should('not.exist');
71+
});
72+
});

0 commit comments

Comments
 (0)