diff --git a/frontend/rabbi_gerzi/cypress/e2e/media.cy.ts b/frontend/rabbi_gerzi/cypress/e2e/media.cy.ts index 0233789..9aca794 100644 --- a/frontend/rabbi_gerzi/cypress/e2e/media.cy.ts +++ b/frontend/rabbi_gerzi/cypress/e2e/media.cy.ts @@ -1,3 +1,14 @@ +function loginAsAdmin(): void { + cy.visit('/login') + + cy.get('[data-cy="login-email"]').type('admin@rabbigerzi.test') + cy.get('[data-cy="login-password"]').type('password123!@#') + cy.get('[data-cy="login-submit"]').click() + + cy.url().should('eq', Cypress.config().baseUrl + '/') + cy.getCookie('auth_token').should('exist') +} + describe('media page sets', () => { it('fetches and renders seeded set cards', () => { const introductionAudioTitle = @@ -163,4 +174,35 @@ describe('media page sets', () => { .and('include', 'https://www.youtube.com/embed/yHx-r4p6hHU') .and('include', 'start=1') }) + + it('does not show the create set card to logged-out users', () => { + cy.visit('/media') + + cy.get('[data-cy="media-create-set-card"]').should('not.exist') + }) + + it('creates a set from the logged-in media page modal', () => { + loginAsAdmin() + cy.visit('/media') + cy.intercept('POST', /\/api\/sets$/).as('createSet') + + cy.get('[data-cy="media-create-set-card"]') + .should('be.visible') + .and('contain.text', 'Create another set') + .click() + cy.get('[data-cy="create-set-modal"]').should('be.visible') + cy.get('[data-cy="create-set-name"]').type('New Cypress Set') + cy.get('[data-cy="create-set-description"]') + .type('Created through the media page modal') + cy.get('[data-cy="create-set-icon"]') + .selectFile('public/assets/baderech-haavodah-icon.png') + cy.get('[data-cy="create-set-submit"]').click() + cy.wait('@createSet') + + cy.location('pathname').should('match', /^\/admin\/element\/\d+$/) + cy.get('[data-cy="admin-element-title"]') + .should('have.value', 'New Cypress Set') + cy.get('[data-cy="admin-element-description"]') + .should('have.value', 'Created through the media page modal') + }) })