mirror of
https://github.com/angular/angular
synced 2026-05-24 09:28:37 +00:00
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
53 lines
2.1 KiB
TypeScript
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');
|
|
});
|
|
});
|