|
1 | | -import { cities } from '../../config/conference-data'; |
| 1 | +import { agenda, cities } from '../../config/conference-data'; |
2 | 2 | import { City } from '../../types/types'; |
3 | 3 | import { resolveCfpUrl } from '../../utils/pretalx'; |
4 | 4 |
|
| 5 | +const monthIndexByName: Record<string, number> = { |
| 6 | + january: 0, |
| 7 | + february: 1, |
| 8 | + march: 2, |
| 9 | + april: 3, |
| 10 | + may: 4, |
| 11 | + june: 5, |
| 12 | + july: 6, |
| 13 | + august: 7, |
| 14 | + september: 8, |
| 15 | + october: 9, |
| 16 | + november: 10, |
| 17 | + december: 11, |
| 18 | +}; |
| 19 | + |
| 20 | +function isCfpDeadlinePassed(cfpDate: string): boolean { |
| 21 | + if (!cfpDate || cfpDate.toLowerCase() === 'not announced yet') { |
| 22 | + return false; |
| 23 | + } |
| 24 | + |
| 25 | + const match = cfpDate.match(/^(\d{1,2})\s+([a-zA-Z]+),?\s+(\d{4})$/); |
| 26 | + |
| 27 | + if (!match) { |
| 28 | + return false; |
| 29 | + } |
| 30 | + |
| 31 | + const month = monthIndexByName[match[2].toLowerCase()]; |
| 32 | + |
| 33 | + if (month === undefined) { |
| 34 | + return false; |
| 35 | + } |
| 36 | + |
| 37 | + const deadline = new Date(Number(match[3]), month, Number(match[1]), 23, 59); |
| 38 | + |
| 39 | + return Date.now() > deadline.getTime(); |
| 40 | +} |
| 41 | + |
5 | 42 | it('should render guideline if cfp is open, and agenda otherwise', () => { |
6 | 43 | cy.wrap(cities).each((city: City) => { |
7 | | - cy.visit(`http://localhost:3000/venue/${city.name}`); |
| 44 | + cy.visit(`/venue/${encodeURIComponent(city.name)}`); |
8 | 45 |
|
9 | 46 | cy.getTestData(`venue-${city.name}`).then((val) => { |
10 | | - if (resolveCfpUrl(city.cfp)) { |
| 47 | + const hasAgenda = agenda.some((item) => item.city === city.name); |
| 48 | + |
| 49 | + if (hasAgenda) { |
| 50 | + cy.getTestData('agenda-com').should('be.visible'); |
| 51 | + } else if (resolveCfpUrl(city.cfp) && !isCfpDeadlinePassed(city.cfpDate)) { |
11 | 52 | cy.getTestData('guideline-com').should('be.visible'); |
12 | 53 | } else { |
13 | 54 | cy.getTestData('agenda-com').should('be.visible'); |
|
0 commit comments