Skip to content

Commit

Permalink
Merge pull request #12217 from bbc/WSTEAMA-1469-remove-conditional-lo…
Browse files Browse the repository at this point in the history
…gic-for-uzbek-single-variant-workarounds

WSTEAMA-1469 Remove conditional logic for uzbek single variant workarounds
  • Loading branch information
LilyL0u authored Dec 10, 2024
2 parents e09e7fc + 38512fb commit 033a7c0
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 35 deletions.
5 changes: 1 addition & 4 deletions src/app/legacy/containers/Brand/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,6 @@ const BrandContainer = ({
const { product, serviceLocalizedName, service } = useContext(ServiceContext);
const { variant } = useContext(RequestContext);

// TODO: Remove the check for 'uzbek' when the service has variant homepages
const appendVariant = service !== 'uzbek' && variant ? `/${variant}` : '';

const { brandSVG } = useTheme();
const svgMaxHeight = 24;
const svgMinHeight = 16;
Expand All @@ -43,7 +40,7 @@ const BrandContainer = ({
minWidth={minWidth}
maxWidth={maxWidth}
svg={brandSVG}
url={`/${service}${appendVariant ? `/${variant}` : ''}`}
url={`/${service}${variant ? `/${variant}` : ''}`}
skipLink={skipLink}
scriptLink={scriptLink}
isLongBrand={longBrands.includes(service)}
Expand Down
52 changes: 24 additions & 28 deletions src/app/legacy/containers/Brand/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -62,33 +62,29 @@ describe(`BrandContainer`, () => {
);
});

it('should render correctly with link provided for variant service', () => {
const { container } = render(
BrandContainerWithContext(mockSkipLink, mockScriptLink, 'brandLink'),
{
service: 'serbian',
variant: 'lat',
},
);

const brandLink = container.querySelector('a');

expect(brandLink.getAttribute('href')).toEqual('/serbian/lat');
});

it('should render correctly with link provided for Uzbek service', () => {
const { container } = render(
BrandContainerWithContext(mockSkipLink, mockScriptLink, 'brandLink'),
{
service: 'uzbek',
variant: 'cyr',
},
);

const brandLink = container.querySelector('a');

// Uzbek is not yet publishing variant homepages
expect(brandLink.getAttribute('href')).toEqual('/uzbek');
});
it.each`
service | variant | expectedHref
${'serbian'} | ${'lat'} | ${'/serbian/lat'}
${'serbian'} | ${'cyr'} | ${'/serbian/cyr'}
${'zhongwen'} | ${'trad'} | ${'/zhongwen/trad'}
${'zhongwen'} | ${'simp'} | ${'/zhongwen/simp'}
${'uzbek'} | ${'lat'} | ${'/uzbek/lat'}
${'uzbek'} | ${'cyr'} | ${'/uzbek/cyr'}
`(
'should render correctly with link provided for $service $variant',
({ service, variant, expectedHref }) => {
const { container } = render(
BrandContainerWithContext(mockSkipLink, mockScriptLink, 'brandLink'),
{
service,
variant,
},
);

const brandLink = container.querySelector('a');

expect(brandLink.getAttribute('href')).toEqual(expectedHref);
},
);
});
});
11 changes: 9 additions & 2 deletions src/app/legacy/containers/Header/index.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,11 @@ import SkipLink from '#psammead/psammead-brand/src/SkipLink';
import { RequestContext } from '#contexts/RequestContext';
import useOperaMiniDetection from '#hooks/useOperaMiniDetection';
import ScriptLink from '#app/components/Header/ScriptLink';
import { ARTICLE_PAGE, HOME_PAGE } from '#app/routes/utils/pageTypes';
import {
ARTICLE_PAGE,
HOME_PAGE,
TOPIC_PAGE,
} from '#app/routes/utils/pageTypes';
import LiteSiteCta from '#app/components/LiteSiteCta';
import { liteEnabledServices } from '#app/components/LiteSiteCta/liteSiteConfig';
import { ServiceContext } from '../../../contexts/ServiceContext';
Expand Down Expand Up @@ -74,7 +78,10 @@ const HeaderContainer = ({
let shouldRenderScriptSwitch = false;

if (scriptLink && renderScriptSwitch) {
if (service === 'uzbek' && ![ARTICLE_PAGE, HOME_PAGE].includes(pageType)) {
if (
service === 'uzbek' &&
![ARTICLE_PAGE, HOME_PAGE, TOPIC_PAGE].includes(pageType)
) {
shouldRenderScriptSwitch = false;
} else {
shouldRenderScriptSwitch = true;
Expand Down
2 changes: 1 addition & 1 deletion src/app/legacy/containers/Header/index.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,7 @@ describe(`Header`, () => {

describe('when service is uzbek', () => {
describe.each(['cyr', 'lat'])('and variant is %s', variant => {
const supportedUzbekPageTypes = [ARTICLE_PAGE, HOME_PAGE];
const supportedUzbekPageTypes = [ARTICLE_PAGE, HOME_PAGE, TOPIC_PAGE];
const unsupportedUzbekPageTypes = Object.values(PAGE_TYPES).filter(
pageType => !supportedUzbekPageTypes.includes(pageType),
);
Expand Down

0 comments on commit 033a7c0

Please sign in to comment.