From 165408e31cd5f39d4d65b0f0f6fad05d52aa33a7 Mon Sep 17 00:00:00 2001 From: Charlotte Date: Mon, 9 Dec 2024 21:40:47 +0000 Subject: [PATCH] Update tests --- .../src/lib/getFrontsAdPositions.test.ts | 286 ++++++++++-------- 1 file changed, 160 insertions(+), 126 deletions(-) diff --git a/dotcom-rendering/src/lib/getFrontsAdPositions.test.ts b/dotcom-rendering/src/lib/getFrontsAdPositions.test.ts index ead1bfe3458..c8f77ef2e03 100644 --- a/dotcom-rendering/src/lib/getFrontsAdPositions.test.ts +++ b/dotcom-rendering/src/lib/getFrontsAdPositions.test.ts @@ -9,16 +9,40 @@ import { getMobileAdPositions, } from './getFrontsAdPositions'; -const defaultTestCollections: Pick[] = [ - ...Array(12), -].map(() => ({ - collectionType: 'fixed/large/slow-XIV', -})); +const generateTestCollection = ( + collectionData: Partial, +): DCRCollectionType => { + const randomInt = Math.round(Math.random() * 1000); + return { + id: `collection-${randomInt}`, + collectionType: 'fixed/large/slow-XIV', + config: { showDateHeader: false, containerLevel: undefined }, + displayName: `Collection ${randomInt}`, + grouped: { + snap: [], + huge: [], + veryBig: [], + big: [], + standard: [], + splash: [], + }, + curated: [], + backfill: [], + treats: [], + ...collectionData, + }; +}; + +const defaultTestCollections: DCRCollectionType[] = [ + ...Array(12), +].map(generateTestCollection); describe('Mobile Ads', () => { it(`Should not insert ad after container if it's the first one and it's a thrasher`, () => { - const testCollections = [...defaultTestCollections]; - testCollections.unshift({ collectionType: 'fixed/thrasher' }); + const testCollections = [ + generateTestCollection({ collectionType: 'fixed/thrasher' }), + ...defaultTestCollections.slice(0, 4), + ]; const mobileAdPositions = getMobileAdPositions(testCollections); @@ -47,8 +71,16 @@ describe('Mobile Ads', () => { it('Should not insert ad after a thrasher container', () => { const testCollections = [...defaultTestCollections]; - testCollections.splice(6, 0, { collectionType: 'fixed/thrasher' }); - testCollections.splice(9, 0, { collectionType: 'fixed/thrasher' }); + testCollections.splice( + 6, + 0, + generateTestCollection({ collectionType: 'fixed/thrasher' }), + ); + testCollections.splice( + 9, + 0, + generateTestCollection({ collectionType: 'fixed/thrasher' }), + ); const mobileAdPositions = getMobileAdPositions(testCollections); @@ -58,54 +90,40 @@ describe('Mobile Ads', () => { // We used https://www.theguardian.com/uk/commentisfree as a blueprint it('Non-network front, with more than 4 collections, without thrashers', () => { - const testCollections: Pick[] = [ - { collectionType: 'fixed/large/slow-XIV' }, - { collectionType: 'fixed/medium/slow-VI' }, - { collectionType: 'fixed/small/slow-IV' }, - { collectionType: 'fixed/small/slow-IV' }, - { collectionType: 'fixed/small/slow-IV' }, - { collectionType: 'dynamic/slow-mpu' }, - { collectionType: 'fixed/small/slow-I' }, - { collectionType: 'fixed/medium/slow-VI' }, - { collectionType: 'fixed/small/slow-IV' }, - { collectionType: 'fixed/small/slow-III' }, - { collectionType: 'fixed/medium/fast-XII' }, - { collectionType: 'fixed/small/fast-VIII' }, - { collectionType: 'news/most-popular' }, - ]; - - const mobileAdPositions = getMobileAdPositions(testCollections); + const mobileAdPositions = getMobileAdPositions(defaultTestCollections); expect(mobileAdPositions).toEqual([0, 3, 5, 7, 9, 11]); }); // We used https://www.theguardian.com/uk as a blueprint it('UK Network Front, with more than 4 collections, with thrashers at various places', () => { - const testCollections: Pick[] = [ - { collectionType: 'dynamic/fast' }, - { collectionType: 'fixed/small/slow-IV' }, - { collectionType: 'dynamic/slow' }, - { collectionType: 'dynamic/slow' }, - { collectionType: 'fixed/small/slow-V-mpu' }, - { collectionType: 'dynamic/slow' }, - { collectionType: 'fixed/thrasher' }, - { collectionType: 'fixed/small/slow-IV' }, - { collectionType: 'fixed/thrasher' }, - { collectionType: 'dynamic/fast' }, - { collectionType: 'dynamic/fast' }, - { collectionType: 'fixed/thrasher' }, - { collectionType: 'dynamic/slow-mpu' }, - { collectionType: 'fixed/small/slow-IV' }, - { collectionType: 'fixed/thrasher' }, - { collectionType: 'dynamic/slow-mpu' }, - { collectionType: 'fixed/thrasher' }, - { collectionType: 'fixed/video' }, - { collectionType: 'fixed/small/slow-IV' }, - { collectionType: 'fixed/small/slow-IV' }, - { collectionType: 'dynamic/slow-mpu' }, - { collectionType: 'fixed/small/slow-IV' }, - { collectionType: 'fixed/medium/slow-VI' }, - { collectionType: 'news/most-popular' }, + const testCollections: DCRCollectionType[] = [ + generateTestCollection({ collectionType: 'dynamic/fast' }), + generateTestCollection({ collectionType: 'fixed/small/slow-IV' }), + generateTestCollection({ collectionType: 'dynamic/slow' }), + generateTestCollection({ collectionType: 'dynamic/slow' }), + generateTestCollection({ + collectionType: 'fixed/small/slow-V-mpu', + }), + generateTestCollection({ collectionType: 'dynamic/slow' }), + generateTestCollection({ collectionType: 'fixed/thrasher' }), + generateTestCollection({ collectionType: 'fixed/small/slow-IV' }), + generateTestCollection({ collectionType: 'fixed/thrasher' }), + generateTestCollection({ collectionType: 'dynamic/fast' }), + generateTestCollection({ collectionType: 'dynamic/fast' }), + generateTestCollection({ collectionType: 'fixed/thrasher' }), + generateTestCollection({ collectionType: 'dynamic/slow-mpu' }), + generateTestCollection({ collectionType: 'fixed/small/slow-IV' }), + generateTestCollection({ collectionType: 'fixed/thrasher' }), + generateTestCollection({ collectionType: 'dynamic/slow-mpu' }), + generateTestCollection({ collectionType: 'fixed/thrasher' }), + generateTestCollection({ collectionType: 'fixed/video' }), + generateTestCollection({ collectionType: 'fixed/small/slow-IV' }), + generateTestCollection({ collectionType: 'fixed/small/slow-IV' }), + generateTestCollection({ collectionType: 'dynamic/slow-mpu' }), + generateTestCollection({ collectionType: 'fixed/small/slow-IV' }), + generateTestCollection({ collectionType: 'fixed/medium/slow-VI' }), + generateTestCollection({ collectionType: 'news/most-popular' }), ]; const mobileAdPositions = getMobileAdPositions(testCollections); @@ -115,27 +133,27 @@ describe('Mobile Ads', () => { // We used https://www.theguardian.com/international as a blueprint it('International Network Front, with more than 4 collections, with thrashers at various places', () => { - const testCollections: Pick[] = [ - { collectionType: 'dynamic/fast' }, - { collectionType: 'fixed/small/slow-IV' }, - { collectionType: 'dynamic/slow' }, - { collectionType: 'dynamic/slow-mpu' }, - { collectionType: 'dynamic/slow' }, - { collectionType: 'fixed/thrasher' }, - { collectionType: 'fixed/small/slow-IV' }, - { collectionType: 'dynamic/fast' }, - { collectionType: 'fixed/small/slow-IV' }, - { collectionType: 'fixed/thrasher' }, - { collectionType: 'dynamic/slow-mpu' }, - { collectionType: 'fixed/thrasher' }, - { collectionType: 'dynamic/slow-mpu' }, - { collectionType: 'fixed/thrasher' }, - { collectionType: 'dynamic/slow-mpu' }, - { collectionType: 'fixed/small/slow-IV' }, - { collectionType: 'fixed/small/slow-IV' }, - { collectionType: 'fixed/video' }, - { collectionType: 'fixed/medium/slow-VI' }, - { collectionType: 'news/most-popular' }, + const testCollections: DCRCollectionType[] = [ + generateTestCollection({ collectionType: 'dynamic/fast' }), + generateTestCollection({ collectionType: 'fixed/small/slow-IV' }), + generateTestCollection({ collectionType: 'dynamic/slow' }), + generateTestCollection({ collectionType: 'dynamic/slow-mpu' }), + generateTestCollection({ collectionType: 'dynamic/slow' }), + generateTestCollection({ collectionType: 'fixed/thrasher' }), + generateTestCollection({ collectionType: 'fixed/small/slow-IV' }), + generateTestCollection({ collectionType: 'dynamic/fast' }), + generateTestCollection({ collectionType: 'fixed/small/slow-IV' }), + generateTestCollection({ collectionType: 'fixed/thrasher' }), + generateTestCollection({ collectionType: 'dynamic/slow-mpu' }), + generateTestCollection({ collectionType: 'fixed/thrasher' }), + generateTestCollection({ collectionType: 'dynamic/slow-mpu' }), + generateTestCollection({ collectionType: 'fixed/thrasher' }), + generateTestCollection({ collectionType: 'dynamic/slow-mpu' }), + generateTestCollection({ collectionType: 'fixed/small/slow-IV' }), + generateTestCollection({ collectionType: 'fixed/small/slow-IV' }), + generateTestCollection({ collectionType: 'fixed/video' }), + generateTestCollection({ collectionType: 'fixed/medium/slow-VI' }), + generateTestCollection({ collectionType: 'news/most-popular' }), ]; const mobileAdPositions = getMobileAdPositions(testCollections); @@ -145,28 +163,30 @@ describe('Mobile Ads', () => { // We used https://www.theguardian.com/us as a blueprint it('US Network Front, with more than 4 collections, with thrashers at various places', () => { - const testCollections: Pick[] = [ - { collectionType: 'dynamic/fast' }, - { collectionType: 'fixed/small/slow-IV' }, - { collectionType: 'fixed/small/slow-IV' }, - { collectionType: 'dynamic/slow-mpu' }, - { collectionType: 'fixed/thrasher' }, - { collectionType: 'dynamic/slow' }, - { collectionType: 'dynamic/slow' }, - { collectionType: 'fixed/thrasher' }, - { collectionType: 'fixed/small/slow-III' }, - { collectionType: 'fixed/thrasher' }, - { collectionType: 'fixed/small/slow-IV' }, - { collectionType: 'dynamic/fast' }, - { collectionType: 'fixed/thrasher' }, - { collectionType: 'fixed/medium/slow-VI' }, - { collectionType: 'dynamic/fast' }, - { collectionType: 'dynamic/fast' }, - { collectionType: 'fixed/small/slow-V-mpu' }, - { collectionType: 'fixed/video' }, - { collectionType: 'fixed/small/slow-III' }, - { collectionType: 'fixed/thrasher' }, - { collectionType: 'news/most-popular' }, + const testCollections: DCRCollectionType[] = [ + generateTestCollection({ collectionType: 'dynamic/fast' }), + generateTestCollection({ collectionType: 'fixed/small/slow-IV' }), + generateTestCollection({ collectionType: 'fixed/small/slow-IV' }), + generateTestCollection({ collectionType: 'dynamic/slow-mpu' }), + generateTestCollection({ collectionType: 'fixed/thrasher' }), + generateTestCollection({ collectionType: 'dynamic/slow' }), + generateTestCollection({ collectionType: 'dynamic/slow' }), + generateTestCollection({ collectionType: 'fixed/thrasher' }), + generateTestCollection({ collectionType: 'fixed/small/slow-III' }), + generateTestCollection({ collectionType: 'fixed/thrasher' }), + generateTestCollection({ collectionType: 'fixed/small/slow-IV' }), + generateTestCollection({ collectionType: 'dynamic/fast' }), + generateTestCollection({ collectionType: 'fixed/thrasher' }), + generateTestCollection({ collectionType: 'fixed/medium/slow-VI' }), + generateTestCollection({ collectionType: 'dynamic/fast' }), + generateTestCollection({ collectionType: 'dynamic/fast' }), + generateTestCollection({ + collectionType: 'fixed/small/slow-V-mpu', + }), + generateTestCollection({ collectionType: 'fixed/video' }), + generateTestCollection({ collectionType: 'fixed/small/slow-III' }), + generateTestCollection({ collectionType: 'fixed/thrasher' }), + generateTestCollection({ collectionType: 'news/most-popular' }), ]; const mobileAdPositions = getMobileAdPositions(testCollections); @@ -176,23 +196,27 @@ describe('Mobile Ads', () => { // We used https://www.theguardian.com/uk/lifeandstyle as a blueprint it('Lifeandstyle front, with more than 4 collections, with thrashers at various places', () => { - const testCollections: Pick[] = [ - { collectionType: 'dynamic/slow' }, - { collectionType: 'fixed/medium/slow-VI' }, - { collectionType: 'fixed/thrasher' }, - { collectionType: 'fixed/medium/slow-VI' }, - { collectionType: 'fixed/small/slow-V-third' }, - { collectionType: 'fixed/small/slow-IV' }, - { collectionType: 'fixed/thrasher' }, - { collectionType: 'fixed/small/slow-IV' }, - { collectionType: 'fixed/thrasher' }, - { collectionType: 'fixed/medium/slow-VI' }, - { collectionType: 'fixed/medium/slow-XII-mpu' }, - { collectionType: 'fixed/small/fast-VIII' }, - { collectionType: 'fixed/thrasher' }, - { collectionType: 'fixed/small/slow-III' }, - { collectionType: 'fixed/small/slow-I' }, - { collectionType: 'news/most-popular' }, + const testCollections: DCRCollectionType[] = [ + generateTestCollection({ collectionType: 'dynamic/slow' }), + generateTestCollection({ collectionType: 'fixed/medium/slow-VI' }), + generateTestCollection({ collectionType: 'fixed/thrasher' }), + generateTestCollection({ collectionType: 'fixed/medium/slow-VI' }), + generateTestCollection({ + collectionType: 'fixed/small/slow-V-third', + }), + generateTestCollection({ collectionType: 'fixed/small/slow-IV' }), + generateTestCollection({ collectionType: 'fixed/thrasher' }), + generateTestCollection({ collectionType: 'fixed/small/slow-IV' }), + generateTestCollection({ collectionType: 'fixed/thrasher' }), + generateTestCollection({ collectionType: 'fixed/medium/slow-VI' }), + generateTestCollection({ + collectionType: 'fixed/medium/slow-XII-mpu', + }), + generateTestCollection({ collectionType: 'fixed/small/fast-VIII' }), + generateTestCollection({ collectionType: 'fixed/thrasher' }), + generateTestCollection({ collectionType: 'fixed/small/slow-III' }), + generateTestCollection({ collectionType: 'fixed/small/slow-I' }), + generateTestCollection({ collectionType: 'news/most-popular' }), ]; const mobileAdPositions = getMobileAdPositions(testCollections); @@ -202,21 +226,31 @@ describe('Mobile Ads', () => { // We used https://www.theguardian.com/tone/recipes as a blueprint it('Recipes front, with more than 4 collections, with thrasher at the first position', () => { - const testCollections: Pick[] = [ - { collectionType: 'fixed/thrasher' }, - { collectionType: 'fixed/medium/slow-VI' }, - { collectionType: 'fixed/small/slow-V-third' }, - { collectionType: 'fixed/medium/slow-XII-mpu' }, - { collectionType: 'fixed/medium/fast-XII' }, - { collectionType: 'fixed/small/slow-V-third' }, - { collectionType: 'fixed/small/fast-VIII' }, - { collectionType: 'fixed/medium/fast-XI' }, - { collectionType: 'fixed/small/slow-III' }, - { collectionType: 'fixed/small/slow-IV' }, - { collectionType: 'fixed/small/slow-V-half' }, - { collectionType: 'fixed/small/slow-V-third' }, - { collectionType: 'fixed/small/fast-VIII' }, - { collectionType: 'news/most-popular' }, + const testCollections: DCRCollectionType[] = [ + generateTestCollection({ collectionType: 'fixed/thrasher' }), + generateTestCollection({ collectionType: 'fixed/medium/slow-VI' }), + generateTestCollection({ + collectionType: 'fixed/small/slow-V-third', + }), + generateTestCollection({ + collectionType: 'fixed/medium/slow-XII-mpu', + }), + generateTestCollection({ collectionType: 'fixed/medium/fast-XII' }), + generateTestCollection({ + collectionType: 'fixed/small/slow-V-third', + }), + generateTestCollection({ collectionType: 'fixed/small/fast-VIII' }), + generateTestCollection({ collectionType: 'fixed/medium/fast-XI' }), + generateTestCollection({ collectionType: 'fixed/small/slow-III' }), + generateTestCollection({ collectionType: 'fixed/small/slow-IV' }), + generateTestCollection({ + collectionType: 'fixed/small/slow-V-half', + }), + generateTestCollection({ + collectionType: 'fixed/small/slow-V-third', + }), + generateTestCollection({ collectionType: 'fixed/small/fast-VIII' }), + generateTestCollection({ collectionType: 'news/most-popular' }), ]; const mobileAdPositions = getMobileAdPositions(testCollections);