mirror of
https://github.com/nasa/openmct.git
synced 2025-01-02 19:36:41 +00:00
parent
487ec7907c
commit
bb34528a86
@ -32,10 +32,13 @@ define(
|
|||||||
mockTimeout,
|
mockTimeout,
|
||||||
mockLog,
|
mockLog,
|
||||||
mockHtml2Canvas,
|
mockHtml2Canvas,
|
||||||
|
mockCanvas,
|
||||||
mockJsPDF,
|
mockJsPDF,
|
||||||
mockJsPDFSave,
|
mockJsPDFSave,
|
||||||
mockSaveAs,
|
mockSaveAs,
|
||||||
|
mockFileReader,
|
||||||
mockExportTimeoutConstant,
|
mockExportTimeoutConstant,
|
||||||
|
testElement,
|
||||||
exportImageService;
|
exportImageService;
|
||||||
|
|
||||||
describe("ExportImageService", function () {
|
describe("ExportImageService", function () {
|
||||||
@ -69,7 +72,13 @@ define(
|
|||||||
"$log",
|
"$log",
|
||||||
["warn"]
|
["warn"]
|
||||||
);
|
);
|
||||||
mockHtml2Canvas = jasmine.createSpy("html2canvas");
|
mockHtml2Canvas = jasmine.createSpy("html2canvas").andCallFake(function (element, opts) {
|
||||||
|
opts.onrendered(mockCanvas);
|
||||||
|
});
|
||||||
|
mockCanvas = jasmine.createSpyObj(
|
||||||
|
"canvas",
|
||||||
|
["toBlob"]
|
||||||
|
);
|
||||||
mockJsPDFSave = jasmine.createSpy("jsPDFSave");
|
mockJsPDFSave = jasmine.createSpy("jsPDFSave");
|
||||||
mockJsPDF = function () {
|
mockJsPDF = function () {
|
||||||
return {
|
return {
|
||||||
@ -78,7 +87,12 @@ define(
|
|||||||
};
|
};
|
||||||
};
|
};
|
||||||
mockSaveAs = jasmine.createSpy("saveAs");
|
mockSaveAs = jasmine.createSpy("saveAs");
|
||||||
|
mockFileReader = jasmine.createSpyObj(
|
||||||
|
"FileReader",
|
||||||
|
["readAsDataURL", "onloadend"]
|
||||||
|
);
|
||||||
mockExportTimeoutConstant = 0;
|
mockExportTimeoutConstant = 0;
|
||||||
|
testElement = {};
|
||||||
|
|
||||||
exportImageService = new ExportImageService(
|
exportImageService = new ExportImageService(
|
||||||
mockQ,
|
mockQ,
|
||||||
@ -87,32 +101,37 @@ define(
|
|||||||
mockExportTimeoutConstant,
|
mockExportTimeoutConstant,
|
||||||
mockHtml2Canvas,
|
mockHtml2Canvas,
|
||||||
mockJsPDF,
|
mockJsPDF,
|
||||||
mockSaveAs
|
mockSaveAs,
|
||||||
|
mockFileReader
|
||||||
);
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
it("runs html2canvas and tries to save a pdf", function () {
|
it("runs html2canvas and tries to save a pdf", function () {
|
||||||
exportImageService.exportPDF("", "plot.pdf");
|
exportImageService.exportPDF(testElement, "plot.pdf");
|
||||||
|
mockFileReader.onloadend();
|
||||||
|
|
||||||
expect(mockHtml2Canvas).toHaveBeenCalled();
|
expect(mockHtml2Canvas).toHaveBeenCalledWith(testElement, { onrendered: jasmine.any(Function) });
|
||||||
|
expect(mockCanvas.toBlob).toHaveBeenCalledWith(mockDeferred.resolve, "image/jpeg");
|
||||||
expect(mockDeferred.reject).not.toHaveBeenCalled();
|
expect(mockDeferred.reject).not.toHaveBeenCalled();
|
||||||
expect(mockJsPDFSave).toHaveBeenCalled();
|
expect(mockJsPDFSave).toHaveBeenCalled();
|
||||||
expect(mockPromise.finally).toHaveBeenCalled();
|
expect(mockPromise.finally).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("runs html2canvas and tries to save a png", function () {
|
it("runs html2canvas and tries to save a png", function () {
|
||||||
exportImageService.exportPNG("", "plot.png");
|
exportImageService.exportPNG(testElement, "plot.png");
|
||||||
|
|
||||||
expect(mockHtml2Canvas).toHaveBeenCalled();
|
expect(mockHtml2Canvas).toHaveBeenCalledWith(testElement, { onrendered: jasmine.any(Function) });
|
||||||
|
expect(mockCanvas.toBlob).toHaveBeenCalledWith(mockDeferred.resolve, "image/png");
|
||||||
expect(mockDeferred.reject).not.toHaveBeenCalled();
|
expect(mockDeferred.reject).not.toHaveBeenCalled();
|
||||||
expect(mockSaveAs).toHaveBeenCalled();
|
expect(mockSaveAs).toHaveBeenCalled();
|
||||||
expect(mockPromise.finally).toHaveBeenCalled();
|
expect(mockPromise.finally).toHaveBeenCalled();
|
||||||
});
|
});
|
||||||
|
|
||||||
it("runs html2canvas and tries to save a jpg", function () {
|
it("runs html2canvas and tries to save a jpg", function () {
|
||||||
exportImageService.exportJPG("", "plot.png");
|
exportImageService.exportJPG(testElement, "plot.png");
|
||||||
|
|
||||||
expect(mockHtml2Canvas).toHaveBeenCalled();
|
expect(mockHtml2Canvas).toHaveBeenCalledWith(testElement, { onrendered: jasmine.any(Function) });
|
||||||
|
expect(mockCanvas.toBlob).toHaveBeenCalledWith(mockDeferred.resolve, "image/jpeg");
|
||||||
expect(mockDeferred.reject).not.toHaveBeenCalled();
|
expect(mockDeferred.reject).not.toHaveBeenCalled();
|
||||||
expect(mockSaveAs).toHaveBeenCalled();
|
expect(mockSaveAs).toHaveBeenCalled();
|
||||||
expect(mockPromise.finally).toHaveBeenCalled();
|
expect(mockPromise.finally).toHaveBeenCalled();
|
||||||
|
Loading…
Reference in New Issue
Block a user