Skip to content

Commit e9d55ab

Browse files
committed
Fix cypress test for calendar block.
1 parent 7683192 commit e9d55ab

File tree

2 files changed

+36
-19
lines changed

2 files changed

+36
-19
lines changed

frontend/cypress/tests/main/blocks-calendar.cy.js

Lines changed: 35 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -8,14 +8,28 @@ describe('Event Calendar Block Tests', () => {
88
cy.intercept('PATCH', '/**/my-page').as('save');
99

1010
const now = new Date();
11-
startDate = new Date(now);
12-
startDate.setMonth(startDate.getMonth() + 1);
1311

14-
// End = start + 7 days
15-
endDate = new Date(startDate.getTime() + 7 * 24 * 60 * 60 * 1000);
12+
// Start = 7th of month
13+
startDate = new Date(now.getFullYear(), now.getMonth(), 7);
14+
15+
// End = 14th of same month
16+
endDate = new Date(startDate.getFullYear(), startDate.getMonth(), 14);
17+
18+
// Always 11th for eventStart
19+
const eventStart = new Date(
20+
startDate.getFullYear(),
21+
startDate.getMonth(),
22+
11,
23+
);
24+
25+
// Always 12th for eventEnd
26+
const eventEnd = new Date(
27+
startDate.getFullYear(),
28+
startDate.getMonth(),
29+
12,
30+
);
31+
1632
const formatDate = (date) => date.toISOString().replace('.000Z', '+00:00');
17-
const eventStart = new Date((startDate.getTime() + endDate.getTime()) / 2);
18-
const eventEnd = new Date(eventStart.getTime() + 2 * 24 * 60 * 60 * 1000);
1933

2034
// given a logged in editor and a page in edit mode
2135
cy.autologin();
@@ -48,6 +62,15 @@ describe('Event Calendar Block Tests', () => {
4862
contentType: 'Event',
4963
contentId: 'my-second-event',
5064
contentTitle: 'Second Event',
65+
bodyModifier(body) {
66+
const baseYear = now.getFullYear();
67+
const baseMonth = now.getMonth();
68+
const startDate = new Date(baseYear, baseMonth, 16);
69+
body.start = formatDate(startDate);
70+
body.end = formatDate(new Date(startDate.getTime() + 1000));
71+
72+
return body;
73+
},
5174
});
5275
cy.visit('/my-page');
5376
cy.wait('@content');
@@ -72,7 +95,7 @@ describe('Event Calendar Block Tests', () => {
7295
.should('not.exist');
7396
});
7497

75-
it.skip('Add Event Calendar block and test the daterange', () => {
98+
it('Add Event Calendar block and test the daterange', () => {
7699
// Adding new event calendar block and setting the date of evet.
77100

78101
cy.addNewBlock('event');
@@ -84,7 +107,7 @@ describe('Event Calendar Block Tests', () => {
84107
.type(startDate.getDate().toString());
85108
cy.get('.react-aria-Group [slot="start"] [data-type="month"]')
86109
.focus()
87-
.type((startDate.getMonth() + 1).toString());
110+
.type((startDate.getMonth() + 1).toString()); // we have to add one here because the month index starts from 0. but above not because formatDate function takes care of that.
88111

89112
cy.get('.react-aria-Group [slot="start"] [data-type="year"]')
90113
.focus()
@@ -243,7 +266,7 @@ describe('Event Calendar Block Tests', () => {
243266
});
244267
});
245268

246-
it.skip('Test the daterange with facet and input', () => {
269+
it('Test the daterange with facet and input', () => {
247270
// Adding new event calendar block and setting the two event content published.
248271
cy.setWorkflow({
249272
path: 'my-first-event',
@@ -409,16 +432,9 @@ describe('Event Calendar Block Tests', () => {
409432
cy.get('#toolbar-save').click();
410433
cy.wait('@content');
411434
cy.url().should('eq', Cypress.config().baseUrl + '/my-page');
412-
cy.get('.card-listing')
413-
.contains('My First Event')
414-
.closest('.card-listing')
415-
.find('.image-wrapper .date-inset')
416-
.should('have.class', 'has-end-date');
417-
418-
cy.get('.card-listing')
419-
.contains('Second Event')
420-
.closest('.card-listing')
421-
.find('.image-wrapper .date-inset')
435+
cy.get('a[href="/my-second-event"]')
436+
.next('div.card-inner')
437+
.find('.date-inset')
422438
.should('not.have.class', 'has-end-date');
423439
});
424440

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix cypress test for calendar block. @iFlameing

0 commit comments

Comments
 (0)