docbrown/app/javascript/articles/__tests__/utilities/feedUtilities.js
Ridhwana 8003691b37
Restructure the way we render the feed + add billboard locations on signed in feed (#19652)
* feat: fix of there is no article

* feat: set the feed order in a data structure rather than in a view

* feat: update yarn.lock

* feat: push the items to the array

* feat: update feed to only show billboards if we have the correct length of items in the feed

* fix: organizedFeedItems.legth

* feat: rename 'featured' to 'image'

* feat: rename 'featured' to 'image'

* feat: rename 'featured' to 'image'

* feat: add some utilities for the feed that we can use in the FeedTest

* feat/WIP: the setup for the feed tests and a first working test

* test: imageItem

* fix: the podcasts can be passed through as an array of objects in the feedItems so that they can be grouped in one card

* feat: remove podcastEpisode state and the attribute in the object

* fix: check that the items exist before trying to slice them

* feat: setup the userdata and the podcast data in the test

* whoops - commit the podcast episodes

* feat: write soem more tests for the feed and including the podcasts

* feat: add some more tests

* feat: add more billboards tests to chcek the order of stuff

* feat: set the timeframe not empty

* feat: update the logic for organizaed feed by inserting the last on first

* doc: jsdoc for functions

* refactor: break the code up into smaller functions

* refactor: make the code more readable and easier to follow

* refactor: pull function out into a utlity

* feat: add specs to utility

* feat: chcek if pinned post

* test the latest timeframe correctly

* chore: update var name

* move the podcast items out of the object clause

* feat: update text

* feat: add a pack file that duplicates initializeDisplayAdVisibility

* feat: create callbacks that will help us to determine when the feed has been rendered so that we can observe the dsplay ads accordingly

* chore: rename to billboards instead of display ad

* feat: first pass at some error handling whilst maintaining the order of the items

* test: for feed error

* feat: abstract out some code

* update the feed items for errors

* chore: comment

* feat: update the variable names

* feat: update honeybadger message
2023-07-03 15:00:44 +02:00

685 lines
19 KiB
JavaScript

export const assetPath = (relativeUrl) => `/images/${relativeUrl}`;
export const feedPosts = [
{
title: 'That Good Night Et molestias',
path: '/douglas_esmeralda/that-good-night-et-molestias-5fak',
id: 85,
user_id: 9,
comments_count: 0,
public_reactions_count: 3,
organization_id: null,
reading_time: 1,
video_thumbnail_url: null,
video: null,
video_duration_in_minutes: '00:00',
experience_level_rating: 5,
experience_level_rating_distribution: 5,
user: {
name: 'Esmeralda "The Esmeralda" Douglas \\:/',
username: 'douglas_esmeralda',
slug: 'douglas_esmeralda',
profile_image_90:
'/uploads/user/profile_image/9/a80aa112-0bbc-4c25-9535-3a21d0cd56a0.png',
profile_image_url:
'/uploads/user/profile_image/9/a80aa112-0bbc-4c25-9535-3a21d0cd56a0.png',
},
pinned: false,
main_image: 'https://pigment.github.io/fake-logos/logos/medium/color/1.png',
tag_list: ['performance', 'be', 'javascript'],
readable_publish_date: 'May 15',
flare_tag: null,
class_name: 'Article',
cloudinary_video_url: null,
published_at_int: 1684156003,
published_timestamp: '2023-05-15T13:06:43Z',
main_image_background_hex_color: '#dddddd',
public_reaction_categories: [
{
slug: 'like',
name: 'Like',
icon: 'sparkle-heart',
position: 1,
},
{
slug: 'unicorn',
name: 'Unicorn',
icon: 'multi-unicorn',
position: 2,
},
],
top_comments: [],
},
{
title: 'After Many a Summer Dies the Swan Qui pariatur',
path: '/tyler_blanda/after-many-a-summer-dies-the-swan-qui-pariatur-3o0p',
id: 142,
user_id: 6,
comments_count: 0,
public_reactions_count: 3,
organization_id: null,
reading_time: 1,
video_thumbnail_url: null,
video: null,
video_duration_in_minutes: '00:00',
experience_level_rating: 5,
experience_level_rating_distribution: 5,
user: {
name: 'Tyler "The Tyler" Blanda \\:/',
username: 'tyler_blanda',
slug: 'tyler_blanda',
profile_image_90:
'/uploads/user/profile_image/6/3cc1898b-cd2a-4ec2-a379-e0c9102a2262.png',
profile_image_url:
'/uploads/user/profile_image/6/3cc1898b-cd2a-4ec2-a379-e0c9102a2262.png',
},
pinned: false,
main_image:
'https://pigment.github.io/fake-logos/logos/medium/color/12.png',
tag_list: [],
readable_publish_date: 'May 15',
flare_tag: null,
class_name: 'Article',
cloudinary_video_url: null,
published_at_int: 1684156197,
published_timestamp: '2023-05-15T13:09:57Z',
main_image_background_hex_color: '#dddddd',
public_reaction_categories: [
{
slug: 'like',
name: 'Like',
icon: 'sparkle-heart',
position: 1,
},
{
slug: 'unicorn',
name: 'Unicorn',
icon: 'multi-unicorn',
position: 2,
},
],
top_comments: [],
},
{
title: 'Number the Stars Et ab',
path: '/schroeder_irvin/number-the-stars-et-ab-18p4',
id: 143,
user_id: 2,
comments_count: 0,
public_reactions_count: 4,
organization_id: null,
reading_time: 1,
video_thumbnail_url: null,
video: null,
video_duration_in_minutes: '00:00',
experience_level_rating: 5,
experience_level_rating_distribution: 5,
user: {
name: 'Irvin "The Irvin" Schroeder \\:/',
username: 'schroeder_irvin',
slug: 'schroeder_irvin',
profile_image_90:
'/uploads/user/profile_image/2/8eb14853-857f-4502-a9fd-507b27c6c300.png',
profile_image_url:
'/uploads/user/profile_image/2/8eb14853-857f-4502-a9fd-507b27c6c300.png',
},
pinned: false,
main_image: 'https://pigment.github.io/fake-logos/logos/medium/color/7.png',
tag_list: [],
readable_publish_date: 'May 15',
flare_tag: null,
class_name: 'Article',
cloudinary_video_url: null,
published_at_int: 1684156197,
published_timestamp: '2023-05-15T13:09:57Z',
main_image_background_hex_color: '#dddddd',
public_reaction_categories: [
{
slug: 'like',
name: 'Like',
icon: 'sparkle-heart',
position: 1,
},
{
slug: 'unicorn',
name: 'Unicorn',
icon: 'multi-unicorn',
position: 2,
},
],
top_comments: [],
},
{
title: 'Now Sleeps the Crimson Petal Nihil aut',
path: '/schroeder_irvin/now-sleeps-the-crimson-petal-nihil-aut-a8o',
id: 141,
user_id: 2,
comments_count: 0,
public_reactions_count: 4,
organization_id: null,
reading_time: 1,
video_thumbnail_url: null,
video: null,
video_duration_in_minutes: '00:00',
experience_level_rating: 5,
experience_level_rating_distribution: 5,
user: {
name: 'Irvin "The Irvin" Schroeder \\:/',
username: 'schroeder_irvin',
slug: 'schroeder_irvin',
profile_image_90:
'/uploads/user/profile_image/2/8eb14853-857f-4502-a9fd-507b27c6c300.png',
profile_image_url:
'/uploads/user/profile_image/2/8eb14853-857f-4502-a9fd-507b27c6c300.png',
},
pinned: true,
main_image: 'https://pigment.github.io/fake-logos/logos/medium/color/6.png',
tag_list: [],
readable_publish_date: 'May 15',
flare_tag: null,
class_name: 'Article',
cloudinary_video_url: null,
published_at_int: 1684156197,
published_timestamp: '2023-05-15T13:09:57Z',
main_image_background_hex_color: '#dddddd',
public_reaction_categories: [
{
slug: 'like',
name: 'Like',
icon: 'sparkle-heart',
position: 1,
},
{
slug: 'unicorn',
name: 'Unicorn',
icon: 'multi-unicorn',
position: 2,
},
],
top_comments: [],
},
{
title: 'Dying of the Light Et libero',
path: '/thiel_erminia/dying-of-the-light-et-libero-2b70',
id: 151,
user_id: 68,
comments_count: 0,
public_reactions_count: 3,
organization_id: null,
reading_time: 1,
video_thumbnail_url: null,
video: null,
video_duration_in_minutes: '00:00',
experience_level_rating: 5,
experience_level_rating_distribution: 5,
user: {
name: 'Erminia "The Erminia" Thiel \\:/',
username: 'thiel_erminia',
slug: 'thiel_erminia',
profile_image_90:
'/uploads/user/profile_image/68/bb57f764-9b55-475f-b54e-4135bff64379.png',
profile_image_url:
'/uploads/user/profile_image/68/bb57f764-9b55-475f-b54e-4135bff64379.png',
},
pinned: false,
main_image: 'https://pigment.github.io/fake-logos/logos/medium/color/6.png',
tag_list: [],
readable_publish_date: 'May 15',
flare_tag: null,
class_name: 'Article',
cloudinary_video_url: null,
published_at_int: 1684156198,
published_timestamp: '2023-05-15T13:09:58Z',
main_image_background_hex_color: '#dddddd',
public_reaction_categories: [
{
slug: 'like',
name: 'Like',
icon: 'sparkle-heart',
position: 1,
},
],
top_comments: [],
},
{
title: 'A Confederacy of Dunces Ut et',
path: '/macgyver_anamaria/a-confederacy-of-dunces-ut-et-5618',
id: 107,
user_id: 69,
comments_count: 0,
public_reactions_count: 4,
organization_id: null,
reading_time: 1,
video_thumbnail_url: null,
video: null,
video_duration_in_minutes: '00:00',
experience_level_rating: 5,
experience_level_rating_distribution: 5,
user: {
name: 'Anamaria "The Anamaria" MacGyver \\:/',
username: 'macgyver_anamaria',
slug: 'macgyver_anamaria',
profile_image_90:
'/uploads/user/profile_image/69/10f094e2-707a-483a-9e6f-ca2ca59c5ac3.png',
profile_image_url:
'/uploads/user/profile_image/69/10f094e2-707a-483a-9e6f-ca2ca59c5ac3.png',
},
pinned: false,
main_image: 'https://pigment.github.io/fake-logos/logos/medium/color/5.png',
tag_list: [],
readable_publish_date: 'May 15',
flare_tag: null,
class_name: 'Article',
cloudinary_video_url: null,
published_at_int: 1684156194,
published_timestamp: '2023-05-15T13:09:54Z',
main_image_background_hex_color: '#dddddd',
public_reaction_categories: [
{
slug: 'like',
name: 'Like',
icon: 'sparkle-heart',
position: 1,
},
{
slug: 'unicorn',
name: 'Unicorn',
icon: 'multi-unicorn',
position: 2,
},
],
top_comments: [],
},
{
title: 'The Torment of Others Quia recusandae',
path: '/douglas_esmeralda/the-torment-of-others-quia-recusandae-4jmh',
id: 126,
user_id: 9,
comments_count: 0,
public_reactions_count: 2,
organization_id: null,
reading_time: 1,
video_thumbnail_url: null,
video: null,
video_duration_in_minutes: '00:00',
experience_level_rating: 5,
experience_level_rating_distribution: 5,
user: {
name: 'Esmeralda "The Esmeralda" Douglas \\:/',
username: 'douglas_esmeralda',
slug: 'douglas_esmeralda',
profile_image_90:
'/uploads/user/profile_image/9/a80aa112-0bbc-4c25-9535-3a21d0cd56a0.png',
profile_image_url:
'/uploads/user/profile_image/9/a80aa112-0bbc-4c25-9535-3a21d0cd56a0.png',
},
pinned: false,
main_image:
'https://pigment.github.io/fake-logos/logos/medium/color/13.png',
tag_list: [],
readable_publish_date: 'May 15',
flare_tag: null,
class_name: 'Article',
cloudinary_video_url: null,
published_at_int: 1684156195,
published_timestamp: '2023-05-15T13:09:55Z',
main_image_background_hex_color: '#dddddd',
public_reaction_categories: [
{
slug: 'unicorn',
name: 'Unicorn',
icon: 'multi-unicorn',
position: 2,
},
],
top_comments: [],
},
{
title: 'Ah, Wilderness! Ad consectetur',
path: '/tyler_blanda/ah-wilderness-ad-consectetur-2cj9',
id: 146,
user_id: 6,
comments_count: 0,
public_reactions_count: 2,
organization_id: null,
reading_time: 1,
video_thumbnail_url: null,
video: null,
video_duration_in_minutes: '00:00',
experience_level_rating: 5,
experience_level_rating_distribution: 5,
user: {
name: 'Tyler "The Tyler" Blanda \\:/',
username: 'tyler_blanda',
slug: 'tyler_blanda',
profile_image_90:
'/uploads/user/profile_image/6/3cc1898b-cd2a-4ec2-a379-e0c9102a2262.png',
profile_image_url:
'/uploads/user/profile_image/6/3cc1898b-cd2a-4ec2-a379-e0c9102a2262.png',
},
pinned: false,
main_image:
'https://pigment.github.io/fake-logos/logos/medium/color/13.png',
tag_list: [],
readable_publish_date: 'May 15',
flare_tag: null,
class_name: 'Article',
cloudinary_video_url: null,
published_at_int: 1684156197,
published_timestamp: '2023-05-15T13:09:57Z',
main_image_background_hex_color: '#dddddd',
public_reaction_categories: [
{
slug: 'unicorn',
name: 'Unicorn',
icon: 'multi-unicorn',
position: 2,
},
],
top_comments: [],
},
{
title: 'Nectar in a Sieve Voluptas iusto',
path: '/o_hara_aaron/nectar-in-a-sieve-voluptas-iusto-2937',
id: 109,
user_id: 5,
comments_count: 0,
public_reactions_count: 3,
organization_id: null,
reading_time: 1,
video_thumbnail_url: null,
video: null,
video_duration_in_minutes: '00:00',
experience_level_rating: 5,
experience_level_rating_distribution: 5,
user: {
name: 'Aaron "The Aaron" O\'Hara \\:/',
username: 'o_hara_aaron',
slug: 'o_hara_aaron',
profile_image_90:
'/uploads/user/profile_image/5/e7705afd-19be-49a9-9a77-c20c061d3248.png',
profile_image_url:
'/uploads/user/profile_image/5/e7705afd-19be-49a9-9a77-c20c061d3248.png',
},
pinned: false,
main_image:
'https://pigment.github.io/fake-logos/logos/medium/color/10.png',
tag_list: [],
readable_publish_date: 'May 15',
flare_tag: null,
class_name: 'Article',
cloudinary_video_url: null,
published_at_int: 1684156194,
published_timestamp: '2023-05-15T13:09:54Z',
main_image_background_hex_color: '#dddddd',
public_reaction_categories: [
{
slug: 'like',
name: 'Like',
icon: 'sparkle-heart',
position: 1,
},
{
slug: 'unicorn',
name: 'Unicorn',
icon: 'multi-unicorn',
position: 2,
},
],
top_comments: [],
},
{
title: 'The Golden Bowl Unde velit',
path: '/o_hara_aaron/the-golden-bowl-unde-velit-2d8e',
id: 106,
user_id: 5,
comments_count: 0,
public_reactions_count: 2,
organization_id: null,
reading_time: 1,
video_thumbnail_url: null,
video: null,
video_duration_in_minutes: '00:00',
experience_level_rating: 5,
experience_level_rating_distribution: 5,
user: {
name: 'Aaron "The Aaron" O\'Hara \\:/',
username: 'o_hara_aaron',
slug: 'o_hara_aaron',
profile_image_90:
'/uploads/user/profile_image/5/e7705afd-19be-49a9-9a77-c20c061d3248.png',
profile_image_url:
'/uploads/user/profile_image/5/e7705afd-19be-49a9-9a77-c20c061d3248.png',
},
pinned: false,
main_image:
'https://pigment.github.io/fake-logos/logos/medium/color/10.png',
tag_list: [],
readable_publish_date: 'May 15',
flare_tag: null,
class_name: 'Article',
cloudinary_video_url: null,
published_at_int: 1684156193,
published_timestamp: '2023-05-15T13:09:53Z',
main_image_background_hex_color: '#dddddd',
public_reaction_categories: [
{
slug: 'like',
name: 'Like',
icon: 'sparkle-heart',
position: 1,
},
{
slug: 'unicorn',
name: 'Unicorn',
icon: 'multi-unicorn',
position: 2,
},
],
top_comments: [],
},
];
export const feedPostsWherePinnedAndImagePostsSame = [
{
title: 'That Good Night Et molestias',
path: '/douglas_esmeralda/that-good-night-et-molestias-5fak',
id: 85,
user_id: 9,
comments_count: 0,
public_reactions_count: 3,
organization_id: null,
reading_time: 1,
video_thumbnail_url: null,
video: null,
video_duration_in_minutes: '00:00',
experience_level_rating: 5,
experience_level_rating_distribution: 5,
user: {
name: 'Esmeralda "The Esmeralda" Douglas \\:/',
username: 'douglas_esmeralda',
slug: 'douglas_esmeralda',
profile_image_90:
'/uploads/user/profile_image/9/a80aa112-0bbc-4c25-9535-3a21d0cd56a0.png',
profile_image_url:
'/uploads/user/profile_image/9/a80aa112-0bbc-4c25-9535-3a21d0cd56a0.png',
},
pinned: true,
main_image: 'https://pigment.github.io/fake-logos/logos/medium/color/1.png',
tag_list: ['performance', 'be', 'javascript'],
readable_publish_date: 'May 15',
flare_tag: null,
class_name: 'Article',
cloudinary_video_url: null,
published_at_int: 1684156003,
published_timestamp: '2023-05-15T13:06:43Z',
main_image_background_hex_color: '#dddddd',
public_reaction_categories: [
{
slug: 'like',
name: 'Like',
icon: 'sparkle-heart',
position: 1,
},
{
slug: 'unicorn',
name: 'Unicorn',
icon: 'multi-unicorn',
position: 2,
},
],
top_comments: [],
},
{
title: 'After Many a Summer Dies the Swan Qui pariatur',
path: '/tyler_blanda/after-many-a-summer-dies-the-swan-qui-pariatur-3o0p',
id: 142,
user_id: 6,
comments_count: 0,
public_reactions_count: 3,
organization_id: null,
reading_time: 1,
video_thumbnail_url: null,
video: null,
video_duration_in_minutes: '00:00',
experience_level_rating: 5,
experience_level_rating_distribution: 5,
user: {
name: 'Tyler "The Tyler" Blanda \\:/',
username: 'tyler_blanda',
slug: 'tyler_blanda',
profile_image_90:
'/uploads/user/profile_image/6/3cc1898b-cd2a-4ec2-a379-e0c9102a2262.png',
profile_image_url:
'/uploads/user/profile_image/6/3cc1898b-cd2a-4ec2-a379-e0c9102a2262.png',
},
pinned: false,
main_image:
'https://pigment.github.io/fake-logos/logos/medium/color/12.png',
tag_list: [],
readable_publish_date: 'May 15',
flare_tag: null,
class_name: 'Article',
cloudinary_video_url: null,
published_at_int: 1684156197,
published_timestamp: '2023-05-15T13:09:57Z',
main_image_background_hex_color: '#dddddd',
public_reaction_categories: [
{
slug: 'like',
name: 'Like',
icon: 'sparkle-heart',
position: 1,
},
{
slug: 'unicorn',
name: 'Unicorn',
icon: 'multi-unicorn',
position: 2,
},
],
top_comments: [],
},
{
title: 'Number the Stars Et ab',
path: '/schroeder_irvin/number-the-stars-et-ab-18p4',
id: 143,
user_id: 2,
comments_count: 0,
public_reactions_count: 4,
organization_id: null,
reading_time: 1,
video_thumbnail_url: null,
video: null,
video_duration_in_minutes: '00:00',
experience_level_rating: 5,
experience_level_rating_distribution: 5,
user: {
name: 'Irvin "The Irvin" Schroeder \\:/',
username: 'schroeder_irvin',
slug: 'schroeder_irvin',
profile_image_90:
'/uploads/user/profile_image/2/8eb14853-857f-4502-a9fd-507b27c6c300.png',
profile_image_url:
'/uploads/user/profile_image/2/8eb14853-857f-4502-a9fd-507b27c6c300.png',
},
pinned: false,
main_image: 'https://pigment.github.io/fake-logos/logos/medium/color/7.png',
tag_list: [],
readable_publish_date: 'May 15',
flare_tag: null,
class_name: 'Article',
cloudinary_video_url: null,
published_at_int: 1684156197,
published_timestamp: '2023-05-15T13:09:57Z',
main_image_background_hex_color: '#dddddd',
public_reaction_categories: [
{
slug: 'like',
name: 'Like',
icon: 'sparkle-heart',
position: 1,
},
{
slug: 'unicorn',
name: 'Unicorn',
icon: 'multi-unicorn',
position: 2,
},
],
top_comments: [],
},
];
export const podcastEpisodes = [
{
slug: 's22e8-from-opera-to-code-anna-mcdougall',
title: 'S22:E8 - From Opera to Code (Anna McDougall)',
podcast_id: 1,
image: { url: null },
id: null,
tag_list: [],
podcast: {
id: 1,
title: 'CodeNewbie',
slug: 'codenewbie',
image_90:
'/uploads/podcast/image/1/3f7dca78-b9fb-4b7f-b985-49b34417d37b.jpeg',
},
},
{
slug: 's22e2-building-the-bridge-across-the-tech-gap-michelle-glauser',
title:
'S22:E2 - Building the bridge across the tech gap (Michelle Glauser)',
podcast_id: 1,
image: { url: null },
id: null,
tag_list: [],
podcast: {
id: 1,
title: 'CodeNewbie',
slug: 'codenewbie',
image_90:
'/uploads/podcast/image/1/3f7dca78-b9fb-4b7f-b985-49b34417d37b.jpeg',
},
},
{
slug: 's22e7-starting-out-in-open-source-brian-douglas',
title: 'S22:E7 - Starting out in Open Source (Brian Douglas)',
podcast_id: 1,
image: { url: null },
id: null,
tag_list: [],
podcast: {
id: 1,
title: 'CodeNewbie',
slug: 'codenewbie',
image_90:
'/uploads/podcast/image/1/3f7dca78-b9fb-4b7f-b985-49b34417d37b.jpeg',
},
},
];
export const firstBillboard = 'billboard one';
export const secondBillboard = 'billboard two';
export const thirdBillboard = 'billboard three';