-
Notifications
You must be signed in to change notification settings - Fork 278
[WS-2839]: Hide articles in myNews page when metadata is not present #14170
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
LukasFrm
wants to merge
12
commits into
latest
Choose a base branch
from
WS-2839-hide-articles-in-mynews-page-when-metadata-is-not-present
base: latest
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.
+168
−9
Open
Changes from 3 commits
Commits
Show all changes
12 commits
Select commit
Hold shift + click to select a range
94de5f0
fix: add sanitiseMetadataString; tests
LukasFrm ee39d79
feat: add filtering for articles with no metadata
LukasFrm f85311d
Merge branch 'latest' into WS-2839-hide-articles-in-mynews-page-when-…
LukasFrm 29b8f8f
fix: update sanitiseMetadataString to collapse whitespace and \ handling
LukasFrm d42a2c7
Merge branch 'WS-2839-hide-articles-in-mynews-page-when-metadata-is-n…
LukasFrm 3b5363a
fix: add headline sanitisation
LukasFrm 8df7ebe
tests: headline sanitisation
LukasFrm 5ecaaee
Merge branch 'latest' into WS-2839-hide-articles-in-mynews-page-when-…
LukasFrm 291f5f2
Merge branch 'latest' into WS-2839-hide-articles-in-mynews-page-when-…
LukasFrm ffd615d
fix: buildCurrentMetadata to use direct variables
LukasFrm 6f8e953
fix: remove extractHeadlineFromBlocks
LukasFrm d2220fe
tests: update stale
LukasFrm 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
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 |
|---|---|---|
| @@ -0,0 +1,152 @@ | ||
| import type { Article } from '#app/models/types/optimo'; | ||
| import { sanitiseMetadataString, buildCurrentMetadata } from './uasUtility'; | ||
|
|
||
| jest.mock('#app/lib/utilities/ichefURL', () => | ||
| jest.fn(() => 'https://ichef.test.bbci.co.uk/ace/ws/320/image.jpg'), | ||
| ); | ||
|
|
||
| const buildMockArticleWithAltText = (altText: string): Article => | ||
| ({ | ||
| metadata: { | ||
| locators: { | ||
| canonicalUrl: 'https://www.bbc.com/hindi/articles/cwy0pz7qydzo', | ||
| }, | ||
| }, | ||
| content: { | ||
| model: { | ||
| blocks: [ | ||
| { | ||
| type: 'headline', | ||
| model: { | ||
| blocks: [ | ||
| { | ||
| model: { | ||
| blocks: [{ model: { text: 'Test headline' } }], | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| promo: { | ||
| images: { | ||
| defaultPromoImage: { | ||
| blocks: [ | ||
| { | ||
| type: 'altText', | ||
| model: { | ||
| blocks: [ | ||
| { | ||
| type: 'text', | ||
| model: { | ||
| blocks: [ | ||
| { | ||
| type: 'paragraph', | ||
| model: { text: altText }, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| { | ||
| type: 'rawImage', | ||
| model: { | ||
| locator: '5bde/live/e4af80b0-6f4c-11f0-8dbd-f3d32ebd3327.jpg', | ||
| originCode: 'cpsprodpb', | ||
| width: 1024, | ||
| height: 576, | ||
| }, | ||
| }, | ||
| ], | ||
| }, | ||
| }, | ||
| }, | ||
| }) as unknown as Article; | ||
|
|
||
| describe('sanitiseMetadataString', () => { | ||
| it('removes a trailing newline', () => { | ||
| expect(sanitiseMetadataString('शाहरुख़ ख़ान\n')).toBe('शाहरुख़ ख़ान'); | ||
| }); | ||
|
|
||
| it('removes a trailing carriage return + newline', () => { | ||
| expect(sanitiseMetadataString('Some text\r\n')).toBe('Some text'); | ||
| }); | ||
|
|
||
| it('removes embedded newlines', () => { | ||
| expect(sanitiseMetadataString('Line one\nLine two')).toBe( | ||
| 'Line oneLine two', | ||
| ); | ||
| }); | ||
|
|
||
| it('trims leading and trailing whitespace', () => { | ||
| expect(sanitiseMetadataString(' hello ')).toBe('hello'); | ||
| }); | ||
|
|
||
| it('returns an empty string for undefined input', () => { | ||
| expect(sanitiseMetadataString(undefined)).toBe(''); | ||
| }); | ||
|
|
||
| it('returns an empty string for an empty string input', () => { | ||
| expect(sanitiseMetadataString('')).toBe(''); | ||
| }); | ||
|
|
||
| it('leaves clean strings unchanged', () => { | ||
| expect(sanitiseMetadataString('Normal alt text')).toBe('Normal alt text'); | ||
| }); | ||
| }); | ||
|
|
||
| describe('buildCurrentMetadata', () => { | ||
| it('strips trailing newline from promoImageAltText before sending to UAS', () => { | ||
| const article = buildMockArticleWithAltText('शाहरुख़ ख़ान\n'); | ||
|
|
||
| const metadata = buildCurrentMetadata(article, { | ||
| articleId: 'cwy0pz7qydzo', | ||
| service: 'hindi', | ||
| }); | ||
|
|
||
| expect(metadata.promoImageAltText).toBe('शाहरुख़ ख़ान'); | ||
| }); | ||
|
|
||
| it('strips embedded newlines from promoImageAltText', () => { | ||
| const article = buildMockArticleWithAltText('Line one\nLine two\n'); | ||
|
|
||
| const metadata = buildCurrentMetadata(article, { | ||
| articleId: 'cwy0pz7qydzo', | ||
| service: 'hindi', | ||
| }); | ||
|
|
||
| expect(metadata.promoImageAltText).toBe('Line oneLine two'); | ||
| }); | ||
|
|
||
| it('handles clean alt text without modification', () => { | ||
| const article = buildMockArticleWithAltText('Clean alt text'); | ||
|
|
||
| const metadata = buildCurrentMetadata(article, { | ||
| articleId: 'cwy0pz7qydzo', | ||
| service: 'hindi', | ||
| }); | ||
|
|
||
| expect(metadata.promoImageAltText).toBe('Clean alt text'); | ||
| }); | ||
|
|
||
| it('includes all expected metadata fields', () => { | ||
| const article = buildMockArticleWithAltText('Image description'); | ||
|
|
||
| const metadata = buildCurrentMetadata(article, { | ||
| articleId: 'cwy0pz7qydzo', | ||
| service: 'hindi', | ||
| }); | ||
|
|
||
| expect(metadata).toMatchObject({ | ||
| articleId: 'cwy0pz7qydzo', | ||
| service: 'hindi', | ||
| title: 'Test headline', | ||
| locatorUrl: 'https://www.bbc.com/hindi/articles/cwy0pz7qydzo', | ||
| promoImageAltText: 'Image description', | ||
| }); | ||
| }); | ||
| }); |
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.
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.
Uh oh!
There was an error while loading. Please reload this page.