|
1 | | -import fs from 'fs' |
2 | | -import path from 'path' |
3 | 1 | import { jest } from '@jest/globals' |
4 | 2 | import { oldestSupported } from '../../lib/enterprise-server-releases.js' |
5 | 3 |
|
6 | | -import { getDOM } from '../helpers/e2etest.js' |
7 | | -import frontmatter from '../../lib/read-frontmatter.js' |
8 | | -import getApplicableVersions from '../../lib/get-applicable-versions.js' |
9 | | -import { allVersions } from '../../lib/all-versions.js' |
10 | | -import renderContent from '../../lib/render-content/index.js' |
11 | | -import shortVersionsMiddleware from '../../middleware/contextualizers/short-versions.js' |
12 | | - |
13 | 4 | jest.useFakeTimers({ legacyFakeTimers: true }) |
14 | | -const req = {} |
| 5 | + |
15 | 6 | /* global page, browser */ |
16 | 7 | describe('homepage', () => { |
17 | 8 | jest.setTimeout(60 * 1000) |
@@ -175,126 +166,3 @@ describe('iframe pages', () => { |
175 | 166 | ).toBeTruthy() |
176 | 167 | }) |
177 | 168 | }) |
178 | | - |
179 | | -describe('REST sidebar', () => { |
180 | | - req.context = { |
181 | | - allVersions, |
182 | | - currentLanguage: 'en', |
183 | | - } |
184 | | - |
185 | | - it('Check REST categories and subcategories are rendering', async () => { |
186 | | - // Get the titles from the content/rest directory to match the titles on the page |
187 | | - const contentFiles = getCatAndSubCat('content/rest') |
188 | | - const contentCheck = await createContentCheckDirectory(contentFiles) |
189 | | - |
190 | | - for (const version in allVersions) { |
191 | | - // Get MapTopic level categories/subcategories for each version on /rest page |
192 | | - const url = `/en/${version}/rest` |
193 | | - const $ = await getDOM(url) |
194 | | - |
195 | | - const categories = [] |
196 | | - $('[data-testid=sidebar] [data-testid=rest-category]').each((i, el) => { |
197 | | - categories[i] = $(el).text() |
198 | | - }) |
199 | | - const browserUrl = `http://localhost:4000${url}` |
200 | | - await page.goto(browserUrl) |
201 | | - await page.setViewport({ width: 1024, height: 768 }) |
202 | | - await page.waitForSelector('[data-testid=rest-category] li div div span') |
203 | | - |
204 | | - await page.evaluate(() => { |
205 | | - Array.from( |
206 | | - document.querySelectorAll('[data-testid=rest-category] li div div span') |
207 | | - ).forEach(async (element) => { |
208 | | - if (element) element.click() |
209 | | - }) |
210 | | - }) |
211 | | - |
212 | | - const subcategories = await page.evaluate(() => |
213 | | - Array.from(document.querySelectorAll('[data-testid=rest-subcategory] li div div span')).map( |
214 | | - (subCategory) => subCategory.textContent |
215 | | - ) |
216 | | - ) |
217 | | - expect(contentCheck[version].cat.length).toBe(categories.length) |
218 | | - expect(contentCheck[version].subcat.length).toBe(subcategories.length) |
219 | | - |
220 | | - categories.forEach((category) => { |
221 | | - expect(contentCheck[version].cat).toContain(category) |
222 | | - }) |
223 | | - |
224 | | - subcategories.forEach((subcategory) => { |
225 | | - expect(contentCheck[version].subcat).toContain(subcategory) |
226 | | - }) |
227 | | - } |
228 | | - }) |
229 | | -}) |
230 | | - |
231 | | -// Recursively go through the content/rest directory and get all the absolute file names |
232 | | -function getCatAndSubCat(root) { |
233 | | - const files = [] |
234 | | - for (const dirent of fs.readdirSync(root, { withFileTypes: true })) { |
235 | | - const { name } = dirent |
236 | | - const file = path.join(root, name) |
237 | | - if (dirent.isDirectory()) { |
238 | | - if (!(name === 'guides' || name === 'overview')) { |
239 | | - files.push(...getCatAndSubCat(file)) |
240 | | - } |
241 | | - } else if ( |
242 | | - !( |
243 | | - name === 'README.md' || |
244 | | - file.includes('rest/index.md') || |
245 | | - file.includes('rest/quickstart.md') |
246 | | - ) |
247 | | - ) { |
248 | | - files.push(file) |
249 | | - } |
250 | | - } |
251 | | - return files |
252 | | -} |
253 | | - |
254 | | -// Create a ContentCheck object that has all the categories/subcategories and get the title from frontmatter |
255 | | -async function createContentCheckDirectory(contentFiles) { |
256 | | - const contentCheck = Object.keys(allVersions).reduce((acc, val) => { |
257 | | - return { ...acc, [val]: { cat: [], subcat: [] } } |
258 | | - }, {}) |
259 | | - |
260 | | - const renderOpts = { textOnly: true } |
261 | | - |
262 | | - for (const filename of contentFiles) { |
263 | | - const { data } = frontmatter(await fs.promises.readFile(filename, 'utf8')) |
264 | | - const applicableVersions = getApplicableVersions(data.versions, filename) |
265 | | - const splitPath = filename.split('/') |
266 | | - let category = '' |
267 | | - let subCategory = '' |
268 | | - |
269 | | - if (splitPath[splitPath.length - 2] === 'rest') { |
270 | | - category = data.title |
271 | | - } else if (splitPath[splitPath.length - 3] === 'rest') { |
272 | | - filename.includes('index.md') |
273 | | - ? (category = data.shortTitle || data.title) |
274 | | - : (subCategory = data.shortTitle || data.title) |
275 | | - } |
276 | | - for (const version of applicableVersions) { |
277 | | - req.context.currentVersion = version |
278 | | - |
279 | | - if (category !== '') |
280 | | - if (category.includes('{')) { |
281 | | - await shortVersionsMiddleware(req, null, () => {}) |
282 | | - contentCheck[version].cat.push( |
283 | | - await renderContent.liquid.parseAndRender(category, req.context, renderOpts) |
284 | | - ) |
285 | | - } else { |
286 | | - contentCheck[version].cat.push(category) |
287 | | - } |
288 | | - if (subCategory !== '') |
289 | | - if (subCategory.includes('{')) { |
290 | | - await shortVersionsMiddleware(req, null, () => {}) |
291 | | - contentCheck[version].subcat.push( |
292 | | - await renderContent.liquid.parseAndRender(subCategory, req.context, renderOpts) |
293 | | - ) |
294 | | - } else { |
295 | | - contentCheck[version].subcat.push(subCategory) |
296 | | - } |
297 | | - } |
298 | | - } |
299 | | - return contentCheck |
300 | | -} |
0 commit comments