Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
cemms1 committed Jan 3, 2025
1 parent e04fe00 commit 165408e
Showing 1 changed file with 160 additions and 126 deletions.
286 changes: 160 additions & 126 deletions dotcom-rendering/src/lib/getFrontsAdPositions.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,40 @@ import {
getMobileAdPositions,
} from './getFrontsAdPositions';

const defaultTestCollections: Pick<DCRCollectionType, 'collectionType'>[] = [
...Array<number>(12),
].map(() => ({
collectionType: 'fixed/large/slow-XIV',
}));
const generateTestCollection = (
collectionData: Partial<DCRCollectionType>,
): 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<DCRCollectionType>(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);

Expand Down Expand Up @@ -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);

Expand All @@ -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<DCRCollectionType, 'collectionType'>[] = [
{ 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<DCRCollectionType, 'collectionType'>[] = [
{ 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);
Expand All @@ -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<DCRCollectionType, 'collectionType'>[] = [
{ 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);
Expand All @@ -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<DCRCollectionType, 'collectionType'>[] = [
{ 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);
Expand All @@ -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<DCRCollectionType, 'collectionType'>[] = [
{ 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);
Expand All @@ -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<DCRCollectionType, 'collectionType'>[] = [
{ 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);
Expand Down

0 comments on commit 165408e

Please sign in to comment.