angular/adev/shared-docs/pipeline/guides/testing/docs-step/docs-step.spec.ts
Joey Perrott 2d8635d29d refactor(docs-infra): migrate @angular/docs from dev-infra into adev directory (#57132)
To increase the ease of development we are moving @angular/docs into the adev directory within this repo. While
we are doing this to improve our development experience in the short term, efforts are also in place
to maintain a division between this @angular/docs (shared) code and adev itself, so that it can be extracted
back out in the future when components is ready to leverage it as well.

PR Close #57132
2024-07-30 15:51:26 +00:00

53 lines
2.1 KiB
TypeScript

import {parseMarkdown} from '../../../guides/parse';
import {runfiles} from '@bazel/runfiles';
import {readFile} from 'fs/promises';
import {JSDOM} from 'jsdom';
describe('markdown to html', () => {
let markdownDocument: DocumentFragment;
beforeAll(async () => {
const markdownContent = await readFile(
runfiles.resolvePackageRelative('docs-step/docs-step.md'),
{encoding: 'utf-8'},
);
markdownDocument = JSDOM.fragment(await parseMarkdown(markdownContent, {}));
});
it('should create a list item for each step', () => {
const stepEls = markdownDocument.querySelectorAll('li')!;
expect(stepEls.length).toBe(2);
});
it('should render each step with the provided information', () => {
const [firstStepEl, secondStepEl] = markdownDocument.querySelectorAll('li');
const firstStepAEl = firstStepEl.querySelector('a')!;
const firstStepTextContentEl = firstStepEl.querySelector('p')!;
const firstStepHeadingEl = firstStepEl.querySelector('h3')!;
expect(firstStepHeadingEl.textContent?.trim()).toBe('Step 1');
expect(firstStepTextContentEl.textContent).toContain('first thing');
expect(firstStepAEl.getAttribute('href')).toBe(`#${firstStepHeadingEl.getAttribute('id')}`);
expect(firstStepAEl.getAttribute('tabindex')).toBe('-1');
expect(secondStepEl.querySelector('h3')?.textContent?.trim()).toBe('Step B');
expect(secondStepEl.querySelector('p')?.textContent).toContain('another thing');
});
it('should create a self referencial anchor for the step', () => {
const firstStepEl = markdownDocument.querySelector('li')!;
const firstStepAEl = firstStepEl.querySelector('a')!;
const firstStepHeadingEl = firstStepEl.querySelector('h3')!;
expect(firstStepAEl.getAttribute('href')).toBe(`#${firstStepHeadingEl.getAttribute('id')}`);
expect(firstStepAEl.getAttribute('tabindex')).toBe('-1');
});
it('should create a a link that is not reachable via tab', () => {
const firstStepEl = markdownDocument.querySelector('li')!;
const firstStepAEl = firstStepEl.querySelector('a')!;
expect(firstStepAEl.getAttribute('tabindex')).toBe('-1');
});
});