From aa23f5c7e115f5f36de0b1cab1c9cc1c70b4e60d Mon Sep 17 00:00:00 2001 From: siriwatknp Date: Mon, 20 Dec 2021 17:19:43 +0700 Subject: [PATCH] redirect old urls to /material/* --- docs/src/modules/components/AppSearch.js | 3 ++- test/e2e-website/material-docs.spec.ts | 16 ++++++++++++---- 2 files changed, 14 insertions(+), 5 deletions(-) diff --git a/docs/src/modules/components/AppSearch.js b/docs/src/modules/components/AppSearch.js index fc0464df07f0f2..b1773509ed71b7 100644 --- a/docs/src/modules/components/AppSearch.js +++ b/docs/src/modules/components/AppSearch.js @@ -18,6 +18,7 @@ import Link from 'docs/src/modules/components/Link'; import { useTranslate, useUserLanguage } from 'docs/src/modules/utils/i18n'; import useLazyCSS from 'docs/src/modules/utils/useLazyCSS'; import { useRouter } from 'next/router'; +import FEATURE_TOGGLE from 'docs/src/featureToggle'; const SearchButton = styled('button')(({ theme }) => { return { @@ -298,7 +299,7 @@ export default function AppSearch() { } // TODO: remove this logic once the migration to new structure is done. - if (router.asPath.startsWith('/material')) { + if (FEATURE_TOGGLE.enable_product_scope) { parseUrl.href = parseUrl.href.replace( /(? { const anchor = await page.locator('.DocSearch-Hits a:has-text("Card")'); - await expect(anchor.first()).toHaveAttribute( - 'href', - `${materialUrlPrefix}/components/cards/#main-content`, - ); + if (FEATURE_TOGGLE.enable_product_scope && !materialUrlPrefix) { + // the old url doc should point to the new location + await expect(anchor.first()).toHaveAttribute( + 'href', + `/material/components/cards/#main-content`, + ); + } else { + await expect(anchor.first()).toHaveAttribute( + 'href', + `${materialUrlPrefix}/components/cards/#main-content`, + ); + } }); test('should have correct link when searching API', async ({ page, materialUrlPrefix }) => {