Skip to content

Commit 0a7f5e3

Browse files
authored
Fix: Update tests to meet new standards (fixes #294) (#295)
* Added media e2e test * Added comments * Updated test * moved out html
1 parent e229c1d commit 0a7f5e3

File tree

1 file changed

+19
-20
lines changed

1 file changed

+19
-20
lines changed

test/e2e/media.cy.js

+19-20
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,35 @@
11
describe('Media', function () {
22
beforeEach(function () {
3-
cy.getData()
3+
cy.getData();
44
});
55

66
it('should display the media component', function () {
7-
const mediaComponents = this.data.components.filter((component) => component._component === 'media')
8-
mediaComponents.forEach((mediaComponent) => {
7+
const mediaComponents = this.data.components.filter(component => component._component === 'media');
8+
const stripHtml = cy.helpers.stripHtml;
9+
mediaComponents.forEach(mediaComponent => {
910
cy.visit(`/#/preview/${mediaComponent._id}`);
10-
const bodyWithoutHtml = mediaComponent.body.replace(/<[^>]*>/g, '');
11-
12-
// Test basic media component
13-
cy.testContainsOrNotExists('.media__title', mediaComponent.displayTitle)
14-
cy.testContainsOrNotExists('.media__body', bodyWithoutHtml)
15-
cy.testContainsOrNotExists('.media__instruction', mediaComponent.instruction)
11+
12+
cy.testContainsOrNotExists('.media__body', stripHtml(mediaComponent.body));
13+
cy.testContainsOrNotExists('.media__title', stripHtml(mediaComponent.displayTitle));
14+
cy.testContainsOrNotExists('.media__instruction', stripHtml(mediaComponent.instruction));
1615

1716
if (mediaComponent._media.mp4) {
18-
cy.get('.mejs-mediaelement video').should('have.attr', 'src', mediaComponent._media.mp4)
19-
}
17+
cy.get('.mejs-mediaelement video').should('have.attr', 'src', mediaComponent._media.mp4);
18+
};
2019
if (mediaComponent._media.poster) {
21-
cy.get('.mejs-poster img').should('have.attr', 'src', mediaComponent._media.poster)
22-
}
20+
cy.get('.mejs-poster img').should('have.attr', 'src', mediaComponent._media.poster);
21+
};
2322

2423
if (mediaComponent._transcript) {
25-
cy.get('.media__transcript-body-inline').should('not.be.visible')
26-
cy.get('button.media__transcript-btn').should('contain', mediaComponent._transcript.inlineTranscriptButton).click()
27-
cy.get('.media__transcript-body-inline-inner').should('be.visible').should('contain', mediaComponent._transcript.inlineTranscriptBody)
28-
cy.get('button.media__transcript-btn').should('contain', mediaComponent._transcript.inlineTranscriptCloseButton).click()
29-
cy.get('.media__transcript-body-inline').should('not.be.visible')
30-
}
24+
cy.get('.media__transcript-body-inline').should('not.be.visible');
25+
cy.get('button.media__transcript-btn').should('contain', mediaComponent._transcript.inlineTranscriptButton).click();
26+
cy.get('.media__transcript-body-inline-inner').should('be.visible').should('contain', mediaComponent._transcript.inlineTranscriptBody);
27+
cy.get('button.media__transcript-btn').should('contain', mediaComponent._transcript.inlineTranscriptCloseButton).click();
28+
cy.get('.media__transcript-body-inline').should('not.be.visible');
29+
};
3130

3231
// Allow the component to load and run external custom tests
33-
cy.wait(1000)
32+
cy.wait(1000);
3433
});
3534
});
3635
});

0 commit comments

Comments
 (0)