Skip to content

Commit 3f5c463

Browse files
masudul-tikwebrenemadsen
authored andcommitted
added timeplanner validation and test cases for it
1 parent 815f528 commit 3f5c463

File tree

7 files changed

+3653
-85
lines changed

7 files changed

+3653
-85
lines changed

eform-client/cypress/e2e/plugins/time-planning-pn/f/420_SDK.sql

Lines changed: 2438 additions & 0 deletions
Large diffs are not rendered by default.

eform-client/cypress/e2e/plugins/time-planning-pn/f/420_eform-angular-time-planning-plugin.sql

Lines changed: 496 additions & 0 deletions
Large diffs are not rendered by default.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import loginPage from '../../../Login.page';
2+
import pluginPage from '../../../Plugin.page';
3+
4+
describe('Enable Backend Config plugin', () => {
5+
beforeEach(() => {
6+
cy.visit('http://localhost:4200');
7+
loginPage.login();
8+
pluginPage.Navbar.goToPluginsPage();
9+
});
10+
11+
it('should activate the plugin', () => {
12+
const pluginName = 'Microting Time Planning Plugin';
13+
pluginPage.enablePluginByName(pluginName);
14+
});
15+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// create canary in a coal mine test asserting true
2+
it('asserts true', () => {
3+
// @ts-ignore
4+
expect(true).to.be.true // this will pass
5+
});
Lines changed: 142 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,142 @@
1+
import loginPage from '../../../Login.page';
2+
3+
describe('Dashboard edit values', () => {
4+
beforeEach(() => {
5+
cy.visit('http://localhost:4200');
6+
loginPage.login();
7+
cy.get('mat-nested-tree-node').contains('Timeregistrering').click();
8+
cy.intercept('POST', '**/api/time-planning-pn/plannings/index').as('index-update');
9+
cy.intercept('PUT', '**/api/time-planning-pn/plannings/*').as('saveWorkdayEntity');
10+
11+
cy.get('mat-tree-node').contains('Dashboard').click();
12+
cy.wait('@index-update', {timeout: 60000});
13+
cy.get('#workingHoursSite').click();
14+
cy.get('.ng-option').contains('ac ad').click();
15+
cy.get('#cell0_0').click();
16+
17+
cy.get('#plannedStartOfShift1')
18+
.closest('.flex-row')
19+
.find('button mat-icon')
20+
.contains('delete')
21+
.click({force: true});
22+
cy.wait(500);
23+
24+
cy.get('#plannedEndOfShift1')
25+
.closest('.flex-row')
26+
.find('button mat-icon')
27+
.contains('delete')
28+
.click({force: true});
29+
cy.wait(500);
30+
31+
cy.get('#start1StartedAt')
32+
.closest('.flex-row')
33+
.find('button mat-icon')
34+
.contains('delete')
35+
.click({force: true});
36+
cy.wait(500);
37+
38+
cy.get('#stop1StoppedAt')
39+
.closest('.flex-row')
40+
.find('button mat-icon')
41+
.contains('delete')
42+
.click({force: true});
43+
cy.wait(500);
44+
});
45+
46+
// Set a timepicker value
47+
const setTimepickerValue = (selector: string, hour: string, minute: string) => {
48+
cy.get(selector).click();
49+
cy.get('ngx-material-timepicker-face')
50+
.contains(hour)
51+
.click({force: true});
52+
cy.get('ngx-material-timepicker-face')
53+
.contains(minute)
54+
.click({force: true});
55+
cy.wait(1000);
56+
cy.contains('button', /^Ok$/).click({force: true});
57+
};
58+
59+
// Get error message for a given input path
60+
const assertInputError = (errorTestId: string, expectedMessage: string) => {
61+
cy.wait(3000);
62+
cy.get(`[data-testid="${errorTestId}"]`)
63+
.should('be.visible')
64+
.and('contain', expectedMessage);
65+
};
66+
67+
// --- Planned Shift Duration Validator ---
68+
it('should show an error when planned stop time is before start time', () => {
69+
setTimepickerValue('#plannedStartOfShift1', '10', '00');
70+
setTimepickerValue('#plannedEndOfShift1', '9', '00');
71+
assertInputError('plannedEndOfShift1-Error', 'Stop time cannot be before start time');
72+
});
73+
74+
it('should show an error when planned break is longer than the shift duration', () => {
75+
setTimepickerValue('#plannedStartOfShift1', '1', '00');
76+
setTimepickerValue('#plannedBreakOfShift1', '9', '00');
77+
setTimepickerValue('#plannedEndOfShift1', '10', '00');
78+
assertInputError('plannedBreakOfShift1-Error', 'Break cannot be equal or longer than shift duration');
79+
});
80+
81+
it('should show an error when planned start and stop are the same', () => {
82+
setTimepickerValue('#plannedStartOfShift1', '9', '00');
83+
setTimepickerValue('#plannedEndOfShift1', '9', '00');
84+
assertInputError('plannedEndOfShift1-Error', 'Start and Stop cannot be the same');
85+
});
86+
87+
// --- Actual Shift Duration Validator ---
88+
it('should show an error when actual stop time is before start time', () => {
89+
setTimepickerValue('#start1StartedAt', '11', '00');
90+
setTimepickerValue('#stop1StoppedAt', '9', '00');
91+
setTimepickerValue('#pause1Id', '0', '00');
92+
assertInputError('stop1StoppedAt-Error', 'Stop time cannot be before start time');
93+
});
94+
95+
it('should show an error when actual pause is longer than the shift duration', () => {
96+
setTimepickerValue('#start1StartedAt', '8', '00');
97+
setTimepickerValue('#stop1StoppedAt', '10', '00');
98+
setTimepickerValue('#pause1Id', '2', '00');
99+
assertInputError('pause1Id-Error', 'Break cannot be equal or longer than shift duration');
100+
});
101+
102+
it('should show an error when actual start and stop are the same', () => {
103+
setTimepickerValue('#start1StartedAt', '9', '00');
104+
setTimepickerValue('#stop1StoppedAt', '9', '00');
105+
setTimepickerValue('#pause1Id', '0', '00');
106+
assertInputError('stop1StoppedAt-Error', 'Start and Stop cannot be the same');
107+
});
108+
109+
// --- Shift-Wise Validator ---
110+
it('should show an error if planned Shift 2 starts before planned Shift 1 ends', () => {
111+
setTimepickerValue('#plannedStartOfShift1', '8', '00');
112+
setTimepickerValue('#plannedEndOfShift1', '12', '00');
113+
setTimepickerValue('#plannedStartOfShift2', '11', '00');
114+
assertInputError('plannedStartOfShift2-Error', 'Start time cannot be earlier than previous shift\'s end time');
115+
});
116+
117+
it('should show an error if actual Shift 2 starts before actual Shift 1 ends', () => {
118+
setTimepickerValue('#start1StartedAt', '8', '00');
119+
setTimepickerValue('#stop1StoppedAt', '12', '00');
120+
setTimepickerValue('#start2StartedAt', '11', '00');
121+
assertInputError('start2StartedAt-Error', 'Start time cannot be earlier than previous shift\'s end time');
122+
});
123+
124+
125+
it('should select midnight to some hours', () => {
126+
setTimepickerValue('#plannedStartOfShift1', '00', '00');
127+
setTimepickerValue('#plannedEndOfShift1', '2', '00');
128+
setTimepickerValue('#start1StartedAt', '00', '00');
129+
setTimepickerValue('#stop1StoppedAt', '2', '00');
130+
cy.get('#planHours').should('have.value', '2');
131+
cy.get('#todaysFlex').should('have.value', '0.00');
132+
});
133+
134+
it('should select some hours to midnight', () => {
135+
setTimepickerValue('#plannedStartOfShift1', '2', '00');
136+
setTimepickerValue('#plannedEndOfShift1', '00', '00');
137+
setTimepickerValue('#start1StartedAt', '2', '00');
138+
setTimepickerValue('#stop1StoppedAt', '00', '00');
139+
cy.get('#planHours').should('have.value', '22');
140+
cy.get('#todaysFlex').should('have.value', '0.00');
141+
});
142+
});

0 commit comments

Comments
 (0)