|
| 1 | +describe('Home View Conditional Rendering', () => { |
| 2 | + |
| 3 | + beforeEach(() => { |
| 4 | + cy.setCookie('clastic_cookie','<cookie-validation-string>'); |
| 5 | + cy.visit('http://localhost:5173/#/'); |
| 6 | + }) |
| 7 | + |
| 8 | + it('should display main dashboard elements', () => { |
| 9 | + cy.get('.dashboard-container', { timeout: 10000 }).should('exist') |
| 10 | + cy.get('.dashboard-header h1').should('be.visible') |
| 11 | + }) |
| 12 | + |
| 13 | + it('should show "New Campaign" button for organizers', () => { |
| 14 | + cy.get('.dashboard-container', { timeout: 10000 }).should('exist') |
| 15 | + cy.get('body').then(($body) => { |
| 16 | + if ($body.find('a[href="/campaign/new"]').length > 0) { |
| 17 | + cy.get('.dashboard-header-heading').within(() => { |
| 18 | + cy.contains('New Campaign').should('exist') |
| 19 | + cy.get('a[href="/campaign/new"]').should('exist') |
| 20 | + }) |
| 21 | + } |
| 22 | + }) |
| 23 | + }) |
| 24 | + |
| 25 | + it('should create a new campaign via the form submission', () => { |
| 26 | + cy.get('.dashboard-container', { timeout: 10000 }).should('exist') |
| 27 | + cy.get('body').then(($body) => { |
| 28 | + if ($body.find('a[href="/campaign/new"]').length > 0) { |
| 29 | + cy.get('a[href="/campaign/new"]').click() |
| 30 | + cy.url().should('include', '/campaign/new') |
| 31 | + cy.get('.new-campaign-card').within(() => { |
| 32 | + cy.get('input[placeholder="Campaign name"]').type('Test Campaign') |
| 33 | + cy.get('input[placeholder="example-slug"]').type('test-campaign') |
| 34 | + cy.get('input[placeholder="YYYY-MM-DD"]').eq(0).type('2025-08-01') |
| 35 | + cy.get('input[placeholder="HH:mm"]').eq(0).type('10:00') |
| 36 | + cy.get('input[placeholder="YYYY-MM-DD"]').eq(1).type('2025-08-10') |
| 37 | + cy.get('input[placeholder="HH:mm"]').eq(1).type('18:00') |
| 38 | + cy.get('.create-button').click() |
| 39 | + }) |
| 40 | + cy.url().should('match', /\/campaign\/\d+/) |
| 41 | + } |
| 42 | + }) |
| 43 | + }) |
| 44 | + |
| 45 | + it('should show new campaign card after creation', () => { |
| 46 | + cy.visit('http://localhost:5173/#/'); |
| 47 | + cy.get('.dashboard-container', { timeout: 10000 }).should('exist') |
| 48 | + cy.get('body').then(($body) => { |
| 49 | + if ($body.find('.new-campaign-card').length > 0) { |
| 50 | + cy.get('.new-campaign-card').should('be.visible') |
| 51 | + cy.get('.new-campaign-card h2').should('contain', 'Test Campaign') |
| 52 | + } |
| 53 | + }) |
| 54 | + }); |
| 55 | + |
| 56 | + |
| 57 | + it('should show "Add Organizer" button for maintainers and it', () => { |
| 58 | + cy.get('.dashboard-container', { timeout: 10000 }).should('exist') |
| 59 | + cy.get('body').then(($body) => { |
| 60 | + if ($body.find('button:contains("Add Organizer")').length > 0) { |
| 61 | + cy.contains('Add Organizer').should('exist') |
| 62 | + |
| 63 | + } |
| 64 | + }) |
| 65 | + }) |
| 66 | + |
| 67 | + it('should open dialog when "Add Organizer" button is clicked', () => { |
| 68 | + cy.get('.dashboard-container', { timeout: 10000 }).should('exist') |
| 69 | + cy.get('body').then(($body) => { |
| 70 | + if ($body.find('button:contains("Add Organizer")').length > 0) { |
| 71 | + cy.contains('Add Organizer').click() |
| 72 | + cy.get('[role="dialog"]', { timeout: 5000 }).should('exist') |
| 73 | + cy.contains('Add').should('exist') |
| 74 | + } |
| 75 | + }) |
| 76 | + }) |
| 77 | + |
| 78 | + it('should display juror campaigns if available', () => { |
| 79 | + cy.visit('http://localhost:5173/#/'); |
| 80 | + cy.get('.dashboard-container', { timeout: 10000 }).should('exist') |
| 81 | + cy.get('body').then(($body) => { |
| 82 | + if ($body.find('.juror-campaigns').length > 0) { |
| 83 | + cy.get('.juror-campaigns h2').should('contain', 'Active voting rounds') |
| 84 | + cy.get('.juror-campaigns juror-campaign-card').should('exist') |
| 85 | + } |
| 86 | + }) |
| 87 | + }) |
| 88 | + |
| 89 | + it('should display coordinator campaign cards if campaigns exist', () => { |
| 90 | + cy.visit('http://localhost:5173/#/'); |
| 91 | + cy.get('.dashboard-container', { timeout: 10000 }).should('exist'); |
| 92 | + cy.get('body').then(($body) => { |
| 93 | + if ($body.find('section.coordinator-campaigns').length > 0) { |
| 94 | + cy.get('section.coordinator-campaigns').within(() => { |
| 95 | + cy.get('h2').should('contain', 'Coordinator campaigns'); |
| 96 | + cy.get('.coordinator-campaign-card').should('exist'); |
| 97 | + }); |
| 98 | + } |
| 99 | + }); |
| 100 | + }); |
| 101 | + |
| 102 | + it('should navigate to view all campaigns page', () => { |
| 103 | + cy.get('.dashboard-container', { timeout: 10000 }).should('exist') |
| 104 | + cy.get('.dashboard-info a').click() |
| 105 | + cy.url().should('include', '/campaign/all') |
| 106 | + }) |
| 107 | + |
| 108 | + it('should navigate to campaign details page', () => { |
| 109 | + cy.get('div.coordinator-campaign-cards') |
| 110 | + .find('.coordinator-campaign-card') |
| 111 | + .first() |
| 112 | + .click() |
| 113 | + cy.url().should('match', /\/campaign\/\d+/) |
| 114 | + }) |
| 115 | + |
| 116 | + |
| 117 | +}); |
0 commit comments