import {mockKalturaBe, loadPlayer} from './env';
const MANIFEST = `#EXTM3U
#EXT-X-MEDIA:TYPE=AUDIO,GROUP-ID="audio",LANGUAGE="en",NAME="English",AUTOSELECT=YES,DEFAULT=YES,URI="${location.origin}/media/index_1.m3u8",SUBTITLES="subs"
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=509496,RESOLUTION=480x272,AUDIO="audio",SUBTITLES="subs"
${location.origin}/media/index.m3u8`;
const MANIFEST_SAFARI = `#EXTM3U
#EXT-X-MEDIA:TYPE=SUBTITLES,GROUP-ID="subs",NAME="English",DEFAULT=NO,AUTOSELECT=YES,FORCED=NO,LANGUAGE="en",URI="${location.origin}/media/index_1.m3u8"
#EXT-X-STREAM-INF:PROGRAM-ID=1,BANDWIDTH=504265,RESOLUTION=480x272,AUDIO="audio",SUBTITLES="subs"
${location.origin}/media/index.m3u8`;
Cypress.on('uncaught:exception', (err, runnable) => {
return false;
});
describe('Info plugin', () => {
beforeEach(() => {
// manifest
cy.intercept('GET', '**/a.m3u8*', Cypress.browser.name === 'webkit' ? MANIFEST_SAFARI : MANIFEST);
// thumbnails
cy.intercept('GET', '**/width/164/vid_slices/100', {fixture: '100.jpeg'});
cy.intercept('GET', '**/height/360/width/640', {fixture: '640.jpeg'});
// kava
cy.intercept('POST', '**/index.php?service=analytics*', {});
});
it('should open and close Info plugin', () => {
mockKalturaBe();
loadPlayer().then(() => {
cy.get('[data-testid="infoPluginButton"]').click({force: true});
cy.get('[data-testid="infoRoot"]').should('exist');
cy.get('.playkit-close-overlay').click({force: true});
cy.get('[data-testid="infoRoot"]').should('not.exist');
});
});
describe('accessibility', () => {
it('should name the dialog after the entry name', () => {
mockKalturaBe();
loadPlayer().then(() => {
cy.get('[data-testid="infoPluginButton"]').click({force: true});
cy.get('[role="dialog"]')
.invoke('attr', 'aria-labelledby')
.should('match', /-info-title$/)
.then(titleId => {
cy.get(`[role="dialog"] h2[id="${titleId}"]`).should('have.text', 'MPEG Dash with MultiAudio New Transcoding');
});
});
});
it('should name the dialog with a fallback title when the entry has no name', () => {
cy.fixture('vod-without-description.json').then(response => {
response[1].objects[0].name = '';
cy.intercept('http://mock-api/service/multirequest', req => {
if (req.body[2]?.service === 'baseEntry' && req.body[2]?.action === 'list') {
req.reply(response);
}
});
});
loadPlayer().then(() => {
cy.get('[data-testid="infoPluginButton"]').click({force: true});
cy.get('[role="dialog"]')
.invoke('attr', 'aria-labelledby')
.then(titleId => {
cy.get(`[role="dialog"] h2[id="${titleId}"]`).should('have.text', 'Video info');
});
});
});
// closes Info by keyboard, then checks the overlay state, focus restore and that player shortcuts respond again
const assertKeyboardClose = (closeByKeyboard: () => void) => {
mockKalturaBe();
loadPlayer().then((kalturaPlayer: any) => {
cy.get('[data-testid="infoPluginButton"]').focus().click({force: true});
cy.get('[data-testid="infoRoot"]').should('exist');
cy.wrap(kalturaPlayer).should((player: any) => {
expect(player.ui.store.getState().overlay.isOpen).to.be.true;
});
closeByKeyboard();
cy.get('[data-testid="infoRoot"]').should('not.exist');
cy.wrap(kalturaPlayer).should((player: any) => {
expect(player.ui.store.getState().overlay.isOpen).to.be.false;
});
cy.focused().should('have.attr', 'data-testid', 'infoPluginButton');
// M toggles mute only when the player keyboard handler is not blocked by an open overlay.
// force: the upper bar may still be fading in, and a keydown does not need the button to be visible
cy.wrap(kalturaPlayer)
.its('muted')
.then(mutedBefore => {
cy.focused().trigger('keydown', {code: 'KeyM', key: 'm', keyCode: 77, force: true});
cy.wrap(kalturaPlayer).its('muted').should('eq', !mutedBefore);
});
});
};
it('should close on Escape, restore focus and re-enable player keyboard shortcuts', () => {
assertKeyboardClose(() => cy.get('[role="dialog"]').trigger('keydown', {code: 'Escape', key: 'Escape', keyCode: 27}));
});
it('should close on Enter on the close button, restore focus and re-enable player keyboard shortcuts', () => {
assertKeyboardClose(() => cy.get('.playkit-close-overlay').focus().trigger('keydown', {code: 'Enter', key: 'Enter', keyCode: 13}));
});
});
describe('entry name', () => {
it('should render entry name without description and broadcast date', () => {
mockKalturaBe();
loadPlayer().then(() => {
cy.get('[data-testid="infoPluginButton"]').click({force: true});
cy.get('[data-testid="entryDescription"]').should('not.exist');
cy.get('[data-testid="broadcastedDate"]').should('not.exist');
cy.get('[data-testid="entryName"]').should($div => {
expect($div.text()).to.eq('MPEG Dash with MultiAudio New Transcoding');
});
});
});
});
describe('entry description', () => {
it('should render entry description', () => {
mockKalturaBe('vod-with-description.json');
loadPlayer().then(() => {
cy.get('[data-testid="infoPluginButton"]').click({force: true});
cy.get('[data-testid="entryDescription"]').should($div => {
expect($div.text()).to.eq(
'Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris blandit aliquet elit, eget tincidunt nibh pulvinar a.'
);
});
});
});
it('should sanitize and render description with html tags inside', () => {
const result = `line one
line two
line three
Praesent sapien massa, convallis a pellentesque nec, egestas non nisi. Mauris blandit aliquet elit, eget tincidunt nibh pulvinar a. Curabitur arcu erat, accumsan id imperdiet et, porttitor at sem. Vestibulum ante ipsum primis in faucibus;
Last line
- one
- two