-
Notifications
You must be signed in to change notification settings - Fork 35
Use variant headlines when in an Editorial Test #16577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
emma-imber
wants to merge
9
commits into
main
Choose a base branch
from
ei/use-variant-headlines-in-test
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
609f68a
Use variant headline when in editorial test
emma-imber 5b402fb
Only run test headlines on fronts listed in 'frontsThisTestCanRunOn'
emma-imber af7a051
Explicitly check test bucket participation early on instead of handli…
emma-imber 1ec5fda
Stronger type checking on variant headline
emma-imber bf3033d
Add more extensive tests
emma-imber dfe8a8f
Use isUndefined helper
emma-imber c3cde23
Drop tests from the return of the enhanceCards function
emma-imber d27d567
Merge branch 'main' into ei/use-variant-headlines-in-test
emma-imber 274bee9
Merge branch 'main' into ei/use-variant-headlines-in-test
emma-imber File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -25,6 +25,7 @@ import type { | |
| DCRFrontCard, | ||
| DCRSlideshowImage, | ||
| DCRSupportingContent, | ||
| EditorialTest, | ||
| } from '../types/front'; | ||
| import type { ArticleMedia, MainMedia } from '../types/mainMedia'; | ||
| import type { PodcastSeriesImage, TagType } from '../types/tag'; | ||
|
|
@@ -183,6 +184,63 @@ const decideVideoAtomImage = ( | |
| return undefined; | ||
| }; | ||
|
|
||
| /** | ||
| * Checks if an editorial test is active by making sure it has not been manually ended, | ||
| * that it has a valid expiry date, and that the expiry date is in the future | ||
| */ | ||
| const isActiveEditorialTest = (test: EditorialTest) => | ||
| !test.hasManuallyEndedOnThisTrail && | ||
| !!test.expiryDate && | ||
| test.expiryDate > Date.now(); | ||
|
|
||
| /** | ||
| * Looks through a list of editorial tests to see if there is an active test. If no active | ||
| * test is found, return undefined | ||
| */ | ||
| const findActiveEditorialTest = ( | ||
| tests: EditorialTest[] | undefined, | ||
| ): EditorialTest | undefined => { | ||
| return tests?.find((test) => isActiveEditorialTest(test)); | ||
| }; | ||
|
|
||
| /** | ||
| * Decide the headline to be shown for a given card. If there is an active editorial test on a card, | ||
| * return the variant headline matching the user test group. Otherwise, return the default headline | ||
| */ | ||
| export const decideHeadline = ( | ||
| faciaCard: FEFrontCard, | ||
| serverSideABTests: Record<string, string>, | ||
| pageId?: string, | ||
| ): string => { | ||
| const defaultHeadline = faciaCard.header.headline; | ||
|
|
||
| const testBucket = | ||
| serverSideABTests['fronts-and-curation-editorial-headline-test']; | ||
|
|
||
| const activeEditorialTest = findActiveEditorialTest( | ||
| faciaCard.properties.tests, | ||
| ); | ||
|
|
||
| if (isUndefined(testBucket) || !activeEditorialTest) { | ||
| return defaultHeadline; | ||
| } | ||
|
|
||
| const testCanRunOnPage = | ||
| !isUndefined(pageId) && | ||
| activeEditorialTest.frontsThisTestCanRunOn.includes(pageId); | ||
|
|
||
| if (!testCanRunOnPage) return defaultHeadline; | ||
|
|
||
| const variantMeta = activeEditorialTest.variantMeta.find( | ||
| (variant) => variant.id.toLowerCase() === testBucket, | ||
| ); | ||
|
|
||
| // make sure the variant headline isn't undefined and that it is of type string | ||
| if (typeof variantMeta?.meta.headline !== 'string') return defaultHeadline; | ||
|
Comment on lines
+238
to
+239
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 👍 thanks for tightening this check |
||
|
|
||
| return variantMeta.meta.headline; | ||
| }; | ||
|
|
||
| /** | ||
| * While the first Media Atom is *not* guaranteed to be the main media, | ||
| * it *happens to be* correct in the majority of cases. | ||
|
|
@@ -363,6 +421,7 @@ export const enhanceCards = ( | |
| pageId, | ||
| discussionApiUrl, | ||
| stripBranding = false, | ||
| serverSideABTests, | ||
| }: { | ||
| cardInTagPage: boolean; | ||
| /** Used for the data link name to indicate card position in container */ | ||
|
|
@@ -372,6 +431,7 @@ export const enhanceCards = ( | |
| discussionApiUrl: string; | ||
| /** We strip branding from cards if the branding will appear at the collection level instead */ | ||
| stripBranding?: boolean; | ||
| serverSideABTests: Record<string, string>; | ||
| }, | ||
| ): DCRFrontCard[] => | ||
| collections.map((faciaCard, index) => { | ||
|
|
@@ -448,7 +508,7 @@ export const enhanceCards = ( | |
| format, | ||
| dataLinkName, | ||
| url: decideUrl(faciaCard), | ||
| headline: faciaCard.header.headline, | ||
| headline: decideHeadline(faciaCard, serverSideABTests, pageId), | ||
| trailText: faciaCard.card.trailText, | ||
| starRating: faciaCard.card.starRating, | ||
| webPublicationDate: !isUndefined( | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for being so thorough with this test suite ✨