Skip to content

Commit

Permalink
update test structure
Browse files Browse the repository at this point in the history
  • Loading branch information
rmccar committed Sep 9, 2024
1 parent 15cdc58 commit b7d141c
Showing 1 changed file with 25 additions and 21 deletions.
46 changes: 25 additions & 21 deletions src/components/video/video.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe('script: video', () => {
expect(displayStyle).toBe('none');
});

describe('when cookies are accepted on page load', () => {
describe('when cookies are accepted on page load, Youtube videos', () => {
beforeEach(async () => {
await page.setCookie({
name: 'ons_cookie_policy',
Expand Down Expand Up @@ -67,23 +67,25 @@ describe('script: video', () => {
expect(hasClass).toBe(true);
}, 10000);

it('should not add dnt to YouTube videos', async () => {
it('should not add dnt', async () => {
const src = await page.$eval('.ons-js-video-iframe', (node) => node.getAttribute('src'));
expect(src.includes('?dnt=1')).toBe(false);
}, 10000);
});

it('should add dnt to Vimeo videos', async () => {
await setTestPage('/test', renderComponent('video', EXAMPLE_VIDEO_VIMEO));
describe('when cookies are accepted on page load, Vimeo videos', () => {
it('should add dnt', async () => {
await setTestPage('/test', renderComponent('video', EXAMPLE_VIDEO_VIMEO));

const src = await page.$eval('.ons-js-video-iframe', (node) => node.getAttribute('src'));
const src = await page.$eval('.ons-js-video-iframe', (node) => node.getAttribute('src'));

await setTimeout(100);
await setTimeout(100);

expect(src.includes('?dnt=1')).toBe(true);
}, 10000);
expect(src.includes('?dnt=1')).toBe(true);
}, 10000);
});

describe('when cookies are accepted via banner', () => {
describe('when cookies are accepted via banner, YouTube videos', () => {
beforeEach(async () => {
await setTestPage(
'/test',
Expand Down Expand Up @@ -112,24 +114,26 @@ describe('script: video', () => {
expect(hasClass).toBe(true);
}, 10000);

it('should not add dnt to YouTube videos', async () => {
it('should not add dnt', async () => {
const src = await page.$eval('.ons-js-video-iframe', (node) => node.getAttribute('src'));
expect(src.includes('?dnt=1')).toBe(false);
}, 10000);
});

it('should add dnt to Vimeo videos', async () => {
await setTestPage(
'/test',
`${renderComponent('video', EXAMPLE_VIDEO_VIMEO)}
<div class="ons-cookies-banner ons-u-db"><button class="ons-js-accept-cookies">Accept</button></div>`,
);
await page.click('.ons-js-accept-cookies');
describe('when cookies are accepted on page load, Vimeo videos', () => {
it('should add dnt', async () => {
await setTestPage(
'/test',
`${renderComponent('video', EXAMPLE_VIDEO_VIMEO)}
<div class="ons-cookies-banner ons-u-db"><button class="ons-js-accept-cookies">Accept</button></div>`,
);
await page.click('.ons-js-accept-cookies');

const src = await page.$eval('.ons-js-video-iframe', (node) => node.getAttribute('src'));
const src = await page.$eval('.ons-js-video-iframe', (node) => node.getAttribute('src'));

await setTimeout(100);
await setTimeout(100);

expect(src.includes('?dnt=1')).toBe(true);
}, 10000);
expect(src.includes('?dnt=1')).toBe(true);
}, 10000);
});
});

0 comments on commit b7d141c

Please sign in to comment.