Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 14 additions & 0 deletions src/report.ts
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,20 @@ export class Report extends embed.Embed implements IReportNode, IFilterable {
return new Page(this, name, displayName);
}

/**
* Print the active page of the report.
* (Invokes window.print() on embed iframe)
*/
print(): Promise<void> {
return this.service.hpm.post<models.IError[]>('/report/print', null, { uid: this.config.uniqueId }, this.iframe.contentWindow)
.then(response => {
return response.body;
})
.catch(response => {
throw response.body;
});
}

/**
* Remove all filters at report level
*
Expand Down
68 changes: 68 additions & 0 deletions test/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1017,6 +1017,26 @@ describe('Protocol', function () {
});
});

describe('print', function () {
it('POST /report/print returns 202 if the request is valid', function (done) {
// Arrange
iframeLoaded
.then(() => {
spyApp.print.and.returnValue(Promise.resolve(null));
// Act
hpm.post<void>('/report/print', null)
.then(response => {
// Assert
expect(spyApp.print).toHaveBeenCalled();
expect(response.statusCode).toEqual(202);
// Cleanup
spyApp.print.calls.reset();
done();
});
});
});
});

describe('filters (report level)', function () {
it('GET /report/filters returns 200 with body as array of filters', function (done) {
// Arrange
Expand Down Expand Up @@ -2026,6 +2046,36 @@ describe('SDK-to-HPM', function () {
});
});

describe('print', function () {
it('report.print() sends POST /report/print', function () {
// Arrange
spyHpm.post.and.returnValue(Promise.resolve({
body: {}
}));

// Act
report.print();

// Assert
expect(spyHpm.post).toHaveBeenCalledWith('/report/print', null, { uid: uniqueId }, iframe.contentWindow);
});

it('report.print() returns promise that resolves if the request is accepted', function (done) {
// Arrange
spyHpm.post.and.returnValue(Promise.resolve({
body: {}
}));

// Act
report.print()
.then(() => {
// Assert
expect(spyHpm.post).toHaveBeenCalledWith('/report/print', null, { uid: uniqueId }, iframe.contentWindow);
done();
});
});
});

describe('settings', function () {
it('report.updateSettings(settings) sends PATCH /report/settings with settings object', function () {
// Arrange
Expand Down Expand Up @@ -3064,6 +3114,24 @@ describe('SDK-to-MockApp', function () {
});
});

describe('print', function () {
it('report.print() returns promise that resolves with null if the report print command was accepted', function (done) {
// Arrange
iframeLoaded
.then(() => {
spyApp.print.and.returnValue(Promise.resolve(null));
// Act
report.print()
.then(response => {
// Assert
expect(spyApp.print).toHaveBeenCalled();
expect(response).toEqual(undefined);
done();
});
});
});
});

describe('settings', function () {
it('report.updateSettings(setting) returns promise that rejects with validation error if object is invalid', function (done) {
// Arrange
Expand Down
5 changes: 4 additions & 1 deletion test/utility/mockApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ export interface IApp {
setFilters(filters: (models.IBasicFilter | models.IAdvancedFilter)[]): Promise<void>;
validateFilter(filter: models.IFilter): Promise<models.IError[]>;
// Other
print(): Promise<void>;
exportData(): Promise<void>;
}

Expand All @@ -41,6 +42,7 @@ export const mockAppSpyObj = {
setFilters: jasmine.createSpy("setFilters").and.returnValue(Promise.resolve(null)),
validateFilter: jasmine.createSpy("validateFilter").and.callFake(models.validateFilter),
// Other
print: jasmine.createSpy("print").and.returnValue(Promise.resolve(null)),
exportData: jasmine.createSpy("exportData").and.returnValue(Promise.resolve(null)),

reset() {
Expand All @@ -56,7 +58,8 @@ export const mockAppSpyObj = {
mockAppSpyObj.getFilters.calls.reset();
mockAppSpyObj.setFilters.calls.reset();
mockAppSpyObj.validateFilter.calls.reset();

mockAppSpyObj.print.calls.reset();
mockAppSpyObj.exportData.calls.reset();
}
};

Expand Down
5 changes: 5 additions & 0 deletions test/utility/mockReportEmbed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -296,5 +296,10 @@ export function setupMockApp(iframeContentWindow: Window, parentWindow: Window,
});
});

router.post('/report/print', (req, res) => {
app.print();
res.send(202);
});

return hpm;
}