Skip to content
This repository has been archived by the owner on Aug 13, 2023. It is now read-only.

Add service variant compatiablity #2668

Merged
merged 23 commits into from
Nov 26, 2019
Merged
Show file tree
Hide file tree
Changes from 3 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
c372186
add zhongwen example, and add service/variant values to variant services
Nov 22, 2019
16cfcec
add variant as a story prop and add tests
Nov 22, 2019
393a333
Merge branch 'latest' into add-service-variant-compatiablity
sareh Nov 22, 2019
d078f56
bump package.json and changelog
Nov 22, 2019
0e4de8f
Merge branch 'add-service-variant-compatiablity' of https://github.co…
Nov 22, 2019
e74838d
update the locale and text for zhongwen example
Nov 22, 2019
00d7088
correct PR number
Nov 22, 2019
15f6e83
separate getServiceAndVariant to make code more readable
Nov 25, 2019
b2ccd1d
resolve conflicts
Nov 25, 2019
3903db4
Merge branch 'latest' into add-service-variant-compatiablity
EinsteinNjoroge Nov 25, 2019
9f81644
apply code review changes
Nov 25, 2019
9365c5e
Merge branch 'add-service-variant-compatiablity' of https://github.co…
Nov 25, 2019
4cc4087
install ramda at the root of psammead
Nov 25, 2019
31c4d3c
use ramda path check for hasVariant function
Nov 25, 2019
51d4dc2
Merge branch 'latest' into add-service-variant-compatiablity
thekp Nov 25, 2019
787d463
resolve conflicts
Nov 25, 2019
ddd1442
Merge branch 'add-service-variant-compatiablity' of https://github.co…
Nov 25, 2019
3b8df61
turkce is being used in our loadable service list in simorgh
Nov 25, 2019
92896be
remove hasVariant function
Nov 25, 2019
30d5ddd
Merge branch 'latest' into add-service-variant-compatiablity
thekp Nov 25, 2019
31cb7aa
Update packages/utilities/psammead-storybook-helpers/src/withServices…
thekp Nov 26, 2019
75ecb13
Update packages/utilities/psammead-storybook-helpers/src/withServices…
thekp Nov 26, 2019
b5564aa
change function selectedItem to selectedService
Nov 26, 2019
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 24 additions & 2 deletions packages/utilities/psammead-storybook-helpers/src/text-variants.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
const LANGUAGE_VARIANTS = {
const EXAMPLES = {
afaanoromoo: {
text:
"Gammadoo ta'uun akkanumaan hin dhufu, waan shaakalamuudha jetti saantoos.",
Expand Down Expand Up @@ -145,11 +145,15 @@ const LANGUAGE_VARIANTS = {
locale: 'ru',
},
serbianCyr: {
service: 'serbian',
variant: 'cyr',
text: 'Караџић се годинама крио пре него што је ухапшен 2008. године',
script: 'cyrillic',
locale: 'sr-cyrl',
},
serbianLat: {
service: 'serbian',
variant: 'cyr',
text: 'Karadžić se godinama krio pre nego što je uhapšen 2008. godine',
script: 'latin',
locale: 'sr',
Expand Down Expand Up @@ -190,11 +194,15 @@ const LANGUAGE_VARIANTS = {
locale: 'tr',
},
ukChinaSimp: {
service: 'ukchina',
variant: 'simp',
text: '该计划的批评者说,这个政策不能解决住房短缺的问题(Credit: Alamy)',
script: 'chinese',
locale: 'zh-cn',
},
ukChinaTrad: {
service: 'ukchina',
variant: 'trad',
text: '該計劃的批評者說,這個政策不能解決住房短缺的問題(Credit: Alamy)',
script: 'chinese',
locale: 'zh-tw',
Expand Down Expand Up @@ -228,6 +236,20 @@ const LANGUAGE_VARIANTS = {
script: 'latin',
locale: 'yo',
},
zhongwenSimp: {
service: 'zhongwen',
variant: 'simp',
text: '该计划的批评者说,这个政策不能解决住房短缺的问题(Credit: Alamy)',
script: 'chinese',
locale: 'zh-cn',
},
zhongwenTrad: {
service: 'zhongwen',
variant: 'trad',
text: '該計劃的批評者說,這個政策不能解決住房短缺的問題(Credit: Alamy)',
script: 'chinese',
locale: 'zh-tw',
},
};

export default LANGUAGE_VARIANTS;
export default EXAMPLES;
Original file line number Diff line number Diff line change
Expand Up @@ -2,20 +2,41 @@ import React from 'react';
import { Helmet } from 'react-helmet';
import { select } from '@storybook/addon-knobs';
import * as scripts from '@bbc/gel-foundations/scripts';
import LANGUAGE_VARIANTS from './text-variants';
import EXAMPLES from './text-variants';
thekp marked this conversation as resolved.
Show resolved Hide resolved

const DEFAULT_SERVICE = 'news';
const SERVICES_LIST = Object.keys(EXAMPLES);

export default ({
defaultService = 'news',
services = Object.keys(LANGUAGE_VARIANTS),
defaultService = DEFAULT_SERVICE,
services = SERVICES_LIST,
} = {}) => storyFn => {
const includesService = service => services.includes(service);
const service = select(
const getServiceAndVariant = selectedItem =>
thekp marked this conversation as resolved.
Show resolved Hide resolved
EXAMPLES[selectedItem].variant
? {
service: EXAMPLES[selectedItem].service,
variant: EXAMPLES[selectedItem].variant,
}
: { service: selectedItem };

const includesSelectedService = selectedItem =>
services.includes(selectedItem);

const selectedItem = select(
thekp marked this conversation as resolved.
Show resolved Hide resolved
'Select a service',
services.filter(includesService),
services.filter(includesSelectedService),
defaultService,
);
const { text, script, locale, dir = 'ltr' } = LANGUAGE_VARIANTS[service];
const storyProps = { text, script: scripts[script], locale, dir, service };

const { text, script, locale, dir = 'ltr' } = EXAMPLES[selectedItem];

const storyProps = {
text,
script: scripts[script],
locale,
dir,
...getServiceAndVariant(selectedItem),
thekp marked this conversation as resolved.
Show resolved Hide resolved
};
return (
<>
<Helmet htmlAttributes={{ dir }} />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import { render, waitForDomChange } from '@testing-library/react';
import * as knobs from '@storybook/addon-knobs';
import * as scripts from '@bbc/gel-foundations/scripts';
import withServicesKnob from './withServicesKnob';
import LANGUAGE_VARIANTS from './text-variants';
import EXAMPLES from './text-variants';
thekp marked this conversation as resolved.
Show resolved Hide resolved

it('should correctly configure the default story book dropdown', () => {
const storyFn = () => {};
Expand All @@ -12,7 +12,7 @@ it('should correctly configure the default story book dropdown', () => {

expect(knobs.select).toHaveBeenCalledWith(
'Select a service',
Object.keys(LANGUAGE_VARIANTS),
Object.keys(EXAMPLES),
thekp marked this conversation as resolved.
Show resolved Hide resolved
'news',
);
});
Expand Down Expand Up @@ -87,3 +87,21 @@ it('should pass the correct chosen service props to the story function', () => {

expect(mockStoryFn).toHaveBeenCalledWith(expected);
});

it('should pass the correct chosen service props to the story function', () => {
const mockStoryFn = jest.fn();
knobs.select = () => 'ukChinaSimp';

withServicesKnob()(mockStoryFn);

const expected = {
script: scripts.chinese,
service: 'ukchina',
text: '该计划的批评者说,这个政策不能解决住房短缺的问题(Credit: Alamy)',
dir: 'ltr',
locale: 'zh-cn',
variant: 'simp',
};

expect(mockStoryFn).toHaveBeenCalledWith(expected);
});