Repository navigation
Expand file tree
/
Copy pathexportManager.test.ts
More file actions
97 lines (93 loc) · 4.96 KB
/
Copy pathexportManager.test.ts
File metadata and controls
97 lines (93 loc) · 4.96 KB
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
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
'use strict';
import { anything, instance, mock, verify, when } from 'ts-mockito';
import { Uri } from 'vscode';
import { IApplicationShell } from '../../../client/common/application/types';
import { IDisposable } from '../../../client/common/types';
import { ExportDependencyChecker } from '../../../client/datascience/export/exportDependencyChecker';
import { ExportFileOpener } from '../../../client/datascience/export/exportFileOpener';
import { ExportManager } from '../../../client/datascience/export/exportManager';
import { ExportUtil } from '../../../client/datascience/export/exportUtil';
import { ExportFormat, IExport, IExportManagerFilePicker } from '../../../client/datascience/export/types';
import { ProgressReporter } from '../../../client/datascience/progress/progressReporter';
import { IDataScienceFileSystem, INotebookModel } from '../../../client/datascience/types';
suite('DataScience - Export Manager', () => {
let exporter: ExportManager;
let exportPython: IExport;
let exportHtml: IExport;
let exportPdf: IExport;
let fileSystem: IDataScienceFileSystem;
let exportUtil: ExportUtil;
let filePicker: IExportManagerFilePicker;
let appShell: IApplicationShell;
let exportFileOpener: ExportFileOpener;
let exportDependencyChecker: ExportDependencyChecker;
const model = mock<INotebookModel>();
setup(async () => {
exportUtil = mock<ExportUtil>();
const reporter = mock(ProgressReporter);
filePicker = mock<IExportManagerFilePicker>();
fileSystem = mock<IDataScienceFileSystem>();
exportPython = mock<IExport>();
exportHtml = mock<IExport>();
exportPdf = mock<IExport>();
appShell = mock<IApplicationShell>();
exportFileOpener = mock<ExportFileOpener>();
exportDependencyChecker = mock<ExportDependencyChecker>();
// tslint:disable-next-line: no-any
when(filePicker.getExportFileLocation(anything(), anything(), anything())).thenReturn(
Promise.resolve(Uri.file('test.pdf'))
);
// tslint:disable-next-line: no-empty
when(appShell.showErrorMessage(anything())).thenResolve();
// tslint:disable-next-line: no-empty
when(exportUtil.generateTempDir()).thenResolve({ path: 'test', dispose: () => {} });
when(exportUtil.makeFileInDirectory(anything(), anything(), anything())).thenResolve('foo');
// tslint:disable-next-line: no-empty
when(fileSystem.createTemporaryLocalFile(anything())).thenResolve({ filePath: 'test', dispose: () => {} });
when(exportPdf.export(anything(), anything(), anything())).thenResolve();
when(filePicker.getExportFileLocation(anything(), anything())).thenResolve(Uri.file('foo'));
when(exportDependencyChecker.checkDependencies(anything())).thenResolve();
when(exportFileOpener.openFile(anything(), anything())).thenResolve();
// tslint:disable-next-line: no-any
when(reporter.createProgressIndicator(anything(), anything())).thenReturn(instance(mock<IDisposable>()) as any);
exporter = new ExportManager(
instance(exportPdf),
instance(exportHtml),
instance(exportPython),
instance(fileSystem),
instance(filePicker),
instance(reporter),
instance(exportUtil),
instance(appShell),
instance(exportFileOpener),
instance(exportDependencyChecker)
);
});
test('Remove svg is called when exporting to PDF', async () => {
await exporter.export(ExportFormat.pdf, model);
verify(exportUtil.removeSvgs(anything())).once();
});
test('Erorr message is shown if export fails', async () => {
when(exportHtml.export(anything(), anything(), anything())).thenThrow(new Error('failed...'));
await exporter.export(ExportFormat.html, model);
verify(appShell.showErrorMessage(anything())).once();
verify(exportFileOpener.openFile(anything(), anything())).never();
});
test('Export to PDF is called when export method is PDF', async () => {
await exporter.export(ExportFormat.pdf, model);
verify(exportPdf.export(anything(), anything(), anything())).once();
verify(exportFileOpener.openFile(ExportFormat.pdf, anything())).once();
});
test('Export to HTML is called when export method is HTML', async () => {
await exporter.export(ExportFormat.html, model);
verify(exportHtml.export(anything(), anything(), anything())).once();
verify(exportFileOpener.openFile(ExportFormat.html, anything())).once();
});
test('Export to Python is called when export method is Python', async () => {
await exporter.export(ExportFormat.python, model);
verify(exportPython.export(anything(), anything(), anything())).once();
verify(exportFileOpener.openFile(ExportFormat.python, anything())).once();
});
});