Skip to content

Commit 4b855f2

Browse files
ali-hamudt-naabus
authored andcommitted
refresh report - initial
1 parent 3279068 commit 4b855f2

File tree

8 files changed

+119
-2
lines changed

8 files changed

+119
-2
lines changed

dist/powerbi.js

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/powerbi.js.map

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/powerbi.min.js

Lines changed: 1 addition & 1 deletion
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

dist/report.d.ts

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,4 +173,12 @@ export declare class Report extends embed.Embed implements IReportNode, IFiltera
173173
* @returns {Promise<void>}
174174
*/
175175
switchMode(viewMode: models.ViewMode): Promise<void>;
176+
/**
177+
* Refreshes data sources for the report.
178+
*
179+
* ```javascript
180+
* report.refresh();
181+
* ```
182+
*/
183+
refresh(): Promise<void>;
176184
}

src/report.ts

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -279,4 +279,21 @@ export class Report extends embed.Embed implements IReportNode, IFilterable {
279279
throw response.body;
280280
});
281281
}
282+
283+
/**
284+
* Refreshes data sources for the report.
285+
*
286+
* ```javascript
287+
* report.refresh();
288+
* ```
289+
*/
290+
refresh(): Promise<void> {
291+
return this.service.hpm.post<models.IError[]>('/report/refresh', null, { uid: this.config.uniqueId }, this.iframe.contentWindow)
292+
.then(response => {
293+
return response.body;
294+
})
295+
.catch(response => {
296+
throw response.body;
297+
});
298+
}
282299
}

test/test.spec.ts

Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1390,6 +1390,26 @@ describe('Protocol', function () {
13901390
});
13911391
});
13921392

1393+
describe('refresh', function () {
1394+
it('POST /report/refresh returns 202 if the request is valid', function (done) {
1395+
// Arrange
1396+
iframeLoaded
1397+
.then(() => {
1398+
spyApp.refreshData.and.returnValue(Promise.resolve(null));
1399+
// Act
1400+
hpm.post<void>('/report/refresh', null)
1401+
.then(response => {
1402+
// Assert
1403+
expect(spyApp.refreshData).toHaveBeenCalled();
1404+
expect(response.statusCode).toEqual(202);
1405+
// Cleanup
1406+
spyApp.refreshData.calls.reset();
1407+
done();
1408+
});
1409+
});
1410+
});
1411+
});
1412+
13931413
describe('print', function () {
13941414
it('POST /report/print returns 202 if the request is valid', function (done) {
13951415
// Arrange
@@ -2704,6 +2724,36 @@ describe('SDK-to-HPM', function () {
27042724
});
27052725
});
27062726

2727+
describe('refresh', function () {
2728+
it('report.refresh() sends POST /report/refresh', function () {
2729+
// Arrange
2730+
spyHpm.post.and.returnValue(Promise.resolve({
2731+
body: {}
2732+
}));
2733+
2734+
// Act
2735+
report.refresh();
2736+
2737+
// Assert
2738+
expect(spyHpm.post).toHaveBeenCalledWith('/report/refresh', null, { uid: uniqueId }, iframe.contentWindow);
2739+
});
2740+
2741+
it('report.refresh() returns promise that resolves if the request is accepted', function (done) {
2742+
// Arrange
2743+
spyHpm.post.and.returnValue(Promise.resolve({
2744+
body: {}
2745+
}));
2746+
2747+
// Act
2748+
report.refresh()
2749+
.then(() => {
2750+
// Assert
2751+
expect(spyHpm.post).toHaveBeenCalledWith('/report/refresh', null, { uid: uniqueId }, iframe.contentWindow);
2752+
done();
2753+
});
2754+
});
2755+
});
2756+
27072757
describe('settings', function () {
27082758
it('report.updateSettings(settings) sends PATCH /report/settings with settings object', function () {
27092759
// Arrange
@@ -3633,6 +3683,24 @@ describe('SDK-to-MockApp', function () {
36333683
});
36343684
});
36353685

3686+
describe('refresh', function () {
3687+
it('report.refresh() returns promise that resolves with null if the report refresh command was accepted', function (done) {
3688+
// Arrange
3689+
iframeLoaded
3690+
.then(() => {
3691+
spyApp.refreshData.and.returnValue(Promise.resolve(null));
3692+
// Act
3693+
report.refresh()
3694+
.then(response => {
3695+
// Assert
3696+
expect(spyApp.refreshData).toHaveBeenCalled();
3697+
expect(response).toEqual(undefined);
3698+
done();
3699+
});
3700+
});
3701+
});
3702+
});
3703+
36363704
describe('settings', function () {
36373705
it('report.updateSettings(setting) returns promise that rejects with validation error if object is invalid', function (done) {
36383706
// Arrange

test/utility/mockApp.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ export interface IApp {
1919
validateFilter(filter: models.IFilter): Promise<models.IError[]>;
2020
// Other
2121
print(): Promise<void>;
22+
refreshData(): Promise<void>;
2223
exportData(): Promise<void>;
2324
validateCreateReport(config: models.IReportCreateConfiguration): Promise<models.IError[]>;
2425
switchMode(): Promise<void>;
@@ -46,6 +47,7 @@ export const mockAppSpyObj = {
4647
validateFilter: jasmine.createSpy("validateFilter").and.callFake(models.validateFilter),
4748
// Other
4849
print: jasmine.createSpy("print").and.returnValue(Promise.resolve(null)),
50+
refreshData: jasmine.createSpy("refreshData").and.returnValue(Promise.resolve(null)),
4951
exportData: jasmine.createSpy("exportData").and.returnValue(Promise.resolve(null)),
5052
validateCreateReport: jasmine.createSpy("validateCreateReport").and.callFake(models.validateCreateReport),
5153
switchMode: jasmine.createSpy("switchMode").and.returnValue(Promise.resolve(null)),
@@ -67,6 +69,7 @@ export const mockAppSpyObj = {
6769
mockAppSpyObj.setFilters.calls.reset();
6870
mockAppSpyObj.validateFilter.calls.reset();
6971
mockAppSpyObj.print.calls.reset();
72+
mockAppSpyObj.refreshData.calls.reset();
7073
mockAppSpyObj.exportData.calls.reset();
7174
mockAppSpyObj.validateCreateReport.calls.reset();
7275
mockAppSpyObj.switchMode.calls.reset();

test/utility/mockEmbed.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,11 @@ export function setupEmbedMockApp(iframeContentWindow: Window, parentWindow: Win
263263
});
264264
});
265265

266+
router.post('/report/refresh', (req, res) => {
267+
app.refreshData();
268+
res.send(202);
269+
});
270+
266271
router.post('/report/print', (req, res) => {
267272
app.print();
268273
res.send(202);

0 commit comments

Comments
 (0)