From 7b16a7817646117fc6fd0ad3832d58435510f23d Mon Sep 17 00:00:00 2001
From: Barbara Valdez <34872381+barbaravaldez@users.noreply.github.com>
Date: Mon, 20 Jun 2022 09:29:33 -0700
Subject: [PATCH] add tests for anchor links (#19659)
---
.../test/browser/notebookMarkdown.test.ts | 7 ++++++
.../calloutDialog/linkCalloutDialog.test.ts | 22 +++++++++++++++++++
2 files changed, 29 insertions(+)
diff --git a/src/sql/workbench/contrib/notebook/test/browser/notebookMarkdown.test.ts b/src/sql/workbench/contrib/notebook/test/browser/notebookMarkdown.test.ts
index 0c6c31feef..0e559fb6e9 100644
--- a/src/sql/workbench/contrib/notebook/test/browser/notebookMarkdown.test.ts
+++ b/src/sql/workbench/contrib/notebook/test/browser/notebookMarkdown.test.ts
@@ -85,6 +85,13 @@ suite('NotebookMarkdownRenderer', () => {
assert.strictEqual(result.innerHTML, `
test
`);
});
+ test('link to section in the same file', () => {
+ let result: HTMLElement = notebookMarkdownRenderer.renderMarkdown({ value: `[#section](#section)`, isTrusted: true });
+ assert.strictEqual(result.innerHTML, `#section
`);
+ result = notebookMarkdownRenderer.renderMarkdown({ value: `section`, isTrusted: true });
+ assert.strictEqual(result.innerHTML, `section
`);
+ });
+
test('cell attachment image', () => {
let result: HTMLElement = notebookMarkdownRenderer.renderMarkdown({ value: ``, isTrusted: true }, { cellAttachments: JSON.parse('{"ads.png":{"image/png":"iVBORw0KGgoAAAANSUhEUgAAAggg=="}}') });
assert.strictEqual(result.innerHTML, `
`, 'Cell attachment basic test failed when trusted');
diff --git a/src/sql/workbench/contrib/notebook/test/calloutDialog/linkCalloutDialog.test.ts b/src/sql/workbench/contrib/notebook/test/calloutDialog/linkCalloutDialog.test.ts
index a908331977..a68f756bd0 100644
--- a/src/sql/workbench/contrib/notebook/test/calloutDialog/linkCalloutDialog.test.ts
+++ b/src/sql/workbench/contrib/notebook/test/calloutDialog/linkCalloutDialog.test.ts
@@ -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 {
+ 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();
+ // 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 {
const defaultLabel = 'defaultLabel';
const unquotedUrl = 'C:/Test/Test.ipynb';