Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Update tests to meet new standards (fixes #294) #295

Merged
merged 5 commits into from
Jun 18, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 19 additions & 20 deletions test/e2e/media.cy.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,35 @@
describe('Media', function () {
beforeEach(function () {
cy.getData()
cy.getData();
});

it('should display the media component', function () {
const mediaComponents = this.data.components.filter((component) => component._component === 'media')
mediaComponents.forEach((mediaComponent) => {
const mediaComponents = this.data.components.filter(component => component._component === 'media');
const stripHtml = cy.helpers.stripHtml;
mediaComponents.forEach(mediaComponent => {
cy.visit(`/#/preview/${mediaComponent._id}`);
const bodyWithoutHtml = mediaComponent.body.replace(/<[^>]*>/g, '');

// Test basic media component
cy.testContainsOrNotExists('.media__title', mediaComponent.displayTitle)
cy.testContainsOrNotExists('.media__body', bodyWithoutHtml)
cy.testContainsOrNotExists('.media__instruction', mediaComponent.instruction)

cy.testContainsOrNotExists('.media__body', stripHtml(mediaComponent.body));
cy.testContainsOrNotExists('.media__title', stripHtml(mediaComponent.displayTitle));
cy.testContainsOrNotExists('.media__instruction', stripHtml(mediaComponent.instruction));

if (mediaComponent._media.mp4) {
cy.get('.mejs-mediaelement video').should('have.attr', 'src', mediaComponent._media.mp4)
}
cy.get('.mejs-mediaelement video').should('have.attr', 'src', mediaComponent._media.mp4);
};
if (mediaComponent._media.poster) {
cy.get('.mejs-poster img').should('have.attr', 'src', mediaComponent._media.poster)
}
cy.get('.mejs-poster img').should('have.attr', 'src', mediaComponent._media.poster);
};

if (mediaComponent._transcript) {
cy.get('.media__transcript-body-inline').should('not.be.visible')
cy.get('button.media__transcript-btn').should('contain', mediaComponent._transcript.inlineTranscriptButton).click()
cy.get('.media__transcript-body-inline-inner').should('be.visible').should('contain', mediaComponent._transcript.inlineTranscriptBody)
cy.get('button.media__transcript-btn').should('contain', mediaComponent._transcript.inlineTranscriptCloseButton).click()
cy.get('.media__transcript-body-inline').should('not.be.visible')
}
cy.get('.media__transcript-body-inline').should('not.be.visible');
cy.get('button.media__transcript-btn').should('contain', mediaComponent._transcript.inlineTranscriptButton).click();
cy.get('.media__transcript-body-inline-inner').should('be.visible').should('contain', mediaComponent._transcript.inlineTranscriptBody);
cy.get('button.media__transcript-btn').should('contain', mediaComponent._transcript.inlineTranscriptCloseButton).click();
cy.get('.media__transcript-body-inline').should('not.be.visible');
};

// Allow the component to load and run external custom tests
cy.wait(1000)
cy.wait(1000);
});
});
});