From 96ba26392b156e7b4b73667a91a071da7e8b3fd1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CLilyL0u=E2=80=9D?= Date: Thu, 28 Nov 2024 15:05:44 +0000 Subject: [PATCH 1/2] remove uzbek conditional and change tests to cover the new scenario --- src/app/legacy/containers/Brand/index.jsx | 5 +- .../legacy/containers/Brand/index.test.jsx | 52 +++++++++---------- 2 files changed, 25 insertions(+), 32 deletions(-) diff --git a/src/app/legacy/containers/Brand/index.jsx b/src/app/legacy/containers/Brand/index.jsx index a1884bb9a5d..0059c9267d8 100644 --- a/src/app/legacy/containers/Brand/index.jsx +++ b/src/app/legacy/containers/Brand/index.jsx @@ -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; @@ -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)} diff --git a/src/app/legacy/containers/Brand/index.test.jsx b/src/app/legacy/containers/Brand/index.test.jsx index a1c35696979..bc62fd3e76e 100644 --- a/src/app/legacy/containers/Brand/index.test.jsx +++ b/src/app/legacy/containers/Brand/index.test.jsx @@ -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); + }, + ); }); }); From a806793ae267b0b6b851abce9bcecc8d9505124f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CLilyL0u=E2=80=9D?= Date: Thu, 28 Nov 2024 15:17:50 +0000 Subject: [PATCH 2/2] allow topic page to support script switch for uzbek --- src/app/legacy/containers/Header/index.jsx | 11 +++++++++-- src/app/legacy/containers/Header/index.test.jsx | 2 +- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/src/app/legacy/containers/Header/index.jsx b/src/app/legacy/containers/Header/index.jsx index e3641a7750a..bdbbe9de6eb 100644 --- a/src/app/legacy/containers/Header/index.jsx +++ b/src/app/legacy/containers/Header/index.jsx @@ -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'; @@ -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; diff --git a/src/app/legacy/containers/Header/index.test.jsx b/src/app/legacy/containers/Header/index.test.jsx index 3a0c4d0aeab..c092cefaa7e 100644 --- a/src/app/legacy/containers/Header/index.test.jsx +++ b/src/app/legacy/containers/Header/index.test.jsx @@ -139,7 +139,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), );