add tests for anchor links (#19659)

This commit is contained in:
Barbara Valdez
2022-06-20 09:29:33 -07:00
committed by GitHub
parent 632c0ba0e8
commit 7b16a78176
2 changed files with 29 additions and 0 deletions

View File

@@ -85,6 +85,13 @@ suite('NotebookMarkdownRenderer', () => {
assert.strictEqual(result.innerHTML, `<p><a href="https://www.test.com?test=&amp;test2=" data-href="https://www.test.com?test=&amp;test2=" title="https://www.test.com?test=&amp;test2=" is-markdown="true" is-absolute="false">test</a></p>`);
});
test('link to section in the same file', () => {
let result: HTMLElement = notebookMarkdownRenderer.renderMarkdown({ value: `[#section](#section)`, isTrusted: true });
assert.strictEqual(result.innerHTML, `<p><a href="#section" data-href="#section" title="#section" is-markdown="true" is-absolute="false">#section</a></p>`);
result = notebookMarkdownRenderer.renderMarkdown({ value: `<a href="#section">section</a>`, isTrusted: true });
assert.strictEqual(result.innerHTML, `<p><a href="#section">section</a></p>`);
});
test('cell attachment image', () => {
let result: HTMLElement = notebookMarkdownRenderer.renderMarkdown({ value: `![altText](attachment:ads.png)`, isTrusted: true }, { cellAttachments: JSON.parse('{"ads.png":{"image/png":"iVBORw0KGgoAAAANSUhEUgAAAggg=="}}') });
assert.strictEqual(result.innerHTML, `<p><img src="data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAggg==" alt="altText"></p>`, 'Cell attachment basic test failed when trusted');

View File

@@ -173,6 +173,28 @@ suite('Link Callout Dialog', function (): void {
assert.strictEqual(result.insertEscapedMarkdown, `[${defaultLabel}](${sampleUrl})`, 'Markdown not returned correctly');
});
test('Should return anchor link properly', async function (): Promise<void> {
const defaultLabel = 'Link to section';
const sampleUrl = '#section';
let linkCalloutDialog = new LinkCalloutDialog('Title', 'below', defaultDialogProperties, defaultLabel, sampleUrl,
undefined, themeService, layoutService, telemetryService, contextKeyService, undefined, undefined, undefined);
linkCalloutDialog.render();
let deferred = new Deferred<ILinkCalloutDialogOptions>();
// When I first open the callout dialog
linkCalloutDialog.open().then(value => {
deferred.resolve(value);
});
linkCalloutDialog.url = sampleUrl;
// And insert the dialog
linkCalloutDialog.insert();
let result = await deferred.promise;
assert.strictEqual(result.insertUnescapedLinkLabel, defaultLabel, 'Label not returned correctly');
assert.strictEqual(result.insertUnescapedLinkUrl, sampleUrl, 'Anchor link not returned correctly');
assert.strictEqual(result.insertEscapedMarkdown, `[${defaultLabel}](${sampleUrl})`, 'Markdown not returned correctly');
});
test('Should handle quoted URLs properly', async function (): Promise<void> {
const defaultLabel = 'defaultLabel';
const unquotedUrl = 'C:/Test/Test.ipynb';