-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathutils.test.js
109 lines (92 loc) · 3.89 KB
/
utils.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
const path = require('path');
const assert = require('assert');
const vscode = require('vscode');
const mermaid = require('mermaid');
const findDiagram = require('../lib/find-diagram');
const usesFontawesome = require('../lib/uses-fontawesome');
suite('Utilities Tests', () => {
const startFenced = '```mermaid';
const startFencedAzureDevOps = '::: mermaid';
const startDived = '<div class="mermaid">';
const startHugo = '{{<mermaid align="left">}}';
const getAbsoluteFilePath = filename =>
path.join(__dirname, 'fixtures', filename);
const openTextDocument = filename =>
vscode.workspace.openTextDocument(
vscode.Uri.file(getAbsoluteFilePath(filename))
);
suite('findDiagram', () => {
suite('markdown fenced code', () => {
test('Detects fenced diagram if cursor inside fence', () =>
openTextDocument('sequence.md').then(document => {
assert.ok(findDiagram(document.getText(), startFenced.length));
}));
test('Does not detect fenced diagram if cursor outside fence', () =>
openTextDocument('sequence.md').then(document => {
assert.equal(findDiagram(document.getText(), 0), undefined);
}));
});
suite('markdown fenced code AzureDevOps Wiki', () => {
test('Detects fenced diagram if cursor inside fence', () =>
openTextDocument('azure-devops.md').then(document => {
assert.ok(
findDiagram(document.getText(), startFencedAzureDevOps.length)
);
}));
test('Does not detect fenced diagram if cursor outside fence', () =>
openTextDocument('azure-devops.md').then(document => {
assert.equal(findDiagram(document.getText(), 0), undefined);
}));
});
suite('html', () => {
test('Detects <div> diagram if cursor inside tag', () =>
openTextDocument('sequence.html').then(document => {
assert.ok(findDiagram(document.getText(), startDived.length));
}));
test('Does not detect <div> diagram if cursor outside tag', () =>
openTextDocument('sequence.html').then(document => {
assert.equal(findDiagram(document.getText(), 0), undefined);
}));
});
suite('hugo shortcodes', () => {
test('Detects hugo diagram if cursor inside tag', () =>
openTextDocument('hugo.html').then(document => {
assert.ok(findDiagram(document.getText(), startHugo.length));
}));
test('Does not detect hugo diagram if cursor outside tag', () =>
openTextDocument('hugo.html').then(document => {
assert.equal(findDiagram(document.getText(), 0), undefined);
}));
});
suite('sphinx directive', () => {
test('Detects diagram', () =>
openTextDocument('example.sphinx').then(document => {
assert.doesNotThrow(() =>
mermaid.parse(findDiagram(document.getText(), 25))
);
}));
test('Detects diagram with parameters', () =>
openTextDocument('example.sphinx').then(document => {
assert.doesNotThrow(() =>
mermaid.parse(findDiagram(document.getText(), 625))
);
}));
test('Does not detect diagram defined in externl file', () =>
openTextDocument('example.sphinx').then(document => {
assert.equal(findDiagram(document.getText(), 1113), undefined);
}));
});
});
suite('usesFontawesome', () => {
test('Detects if diagram uses Fontawesome', () =>
openTextDocument('font-awesome.md').then(document => {
const diagram = findDiagram(document.getText(), startFenced.length);
assert.equal(usesFontawesome(diagram), true);
}));
test('Does not detect if diagram does not uses Fontawesome', () =>
openTextDocument('sequence.md').then(document => {
const diagram = findDiagram(document.getText(), startFenced.length);
assert.equal(usesFontawesome(diagram), false);
}));
});
});