From 16113fd23a484f50120f3f979afcf7dafdf8e3db Mon Sep 17 00:00:00 2001 From: Peter Bengtsson Date: Thu, 24 Feb 2022 08:05:35 -0500 Subject: [PATCH] don't check the productMap for translations (#25589) * don't check the productMap for translations * fix breaking test --- lib/page.js | 29 +++++++++++++++++------------ tests/unit/page.js | 14 -------------- 2 files changed, 17 insertions(+), 26 deletions(-) diff --git a/lib/page.js b/lib/page.js index f35e2dd46d6a..75312ca33d52 100644 --- a/lib/page.js +++ b/lib/page.js @@ -97,18 +97,23 @@ class Page { // Get array of versions that the page is available in for fast lookup this.applicableVersions = getApplicableVersions(this.versions, this.fullPath) - // a page should only be available in versions that its parent product is available in - const versionsParentProductIsNotAvailableIn = this.applicableVersions - // only the homepage will not have this.parentProduct - .filter( - (availableVersion) => - this.parentProduct && !this.parentProduct.versions.includes(availableVersion) - ) - - if (versionsParentProductIsNotAvailableIn.length) { - throw new Error( - `\`versions\` frontmatter in ${this.fullPath} contains ${versionsParentProductIsNotAvailableIn}, which ${this.parentProduct.id} product is not available in!` - ) + // Only check the parent product ID for English because if a top-level + // product is edited in English, it will fail for translations until + // the next translation pipeline PR gets a chance to catch up. + if (this.languageCode === 'en') { + // a page should only be available in versions that its parent product is available in + const versionsParentProductIsNotAvailableIn = this.applicableVersions + // only the homepage will not have this.parentProduct + .filter( + (availableVersion) => + this.parentProduct && !this.parentProduct.versions.includes(availableVersion) + ) + + if (versionsParentProductIsNotAvailableIn.length) { + throw new Error( + `\`versions\` frontmatter in ${this.fullPath} contains ${versionsParentProductIsNotAvailableIn}, which ${this.parentProduct.id} product is not available in!` + ) + } } // derive array of Permalink objects diff --git a/tests/unit/page.js b/tests/unit/page.js index 5a397e4148a0..481da6f2d60b 100644 --- a/tests/unit/page.js +++ b/tests/unit/page.js @@ -781,20 +781,6 @@ describe('catches errors thrown in Page class', () => { expect(getPage).rejects.toThrowError(/`versions` frontmatter.*? product is not available in/) }) - test('non-English page with a version in frontmatter that its parent product is not available in', async () => { - async function getPage() { - return await Page.init({ - relativePath: 'admin/some-category/some-article-with-mismatched-versions-frontmatter.md', - basePath: path.join(__dirname, '../fixtures/products'), - languageCode: 'es', - }) - } - - await expect(getPage).rejects.toThrowError( - /`versions` frontmatter.*? product is not available in/ - ) - }) - describe('versionining optional attributes', () => { test("re-rendering set appropriate 'product', 'permissions', 'learningTracks'", async () => { const page = await Page.init({