Skip to content

Commit dc1b715

Browse files
committed
Add pageView to loadDashboardConfiguration
1 parent ab07b53 commit dc1b715

File tree

9 files changed

+88
-9
lines changed

9 files changed

+88
-9
lines changed

dist/dashboard.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,4 +55,8 @@ export declare class Dashboard extends embed.Embed implements IDashboardNode {
5555
* Validate load configuration.
5656
*/
5757
validate(config: models.IDashboardLoadConfiguration): models.IError[];
58+
/**
59+
* Validate that pageView has a legal value: if page view is defined it must have one of the values defined in models.PageView
60+
*/
61+
private ValidatePageView(pageView);
5862
}

dist/embed.d.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ export interface IEmbedConfiguration {
2626
settings?: models.ISettings;
2727
pageName?: string;
2828
filters?: models.IFilter[];
29+
pageView?: models.PageView;
2930
}
3031
export interface IInternalEmbedConfiguration extends models.IReportLoadConfiguration {
3132
uniqueId: string;

dist/powerbi.js

Lines changed: 17 additions & 2 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: 4 additions & 4 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
},
7575
"dependencies": {
7676
"http-post-message": "^0.2.3",
77-
"powerbi-models": "^0.10.0",
77+
"powerbi-models": "^0.10.1",
7878
"powerbi-router": "^0.1.4",
7979
"window-post-message-proxy": "^0.2.4"
8080
},

src/dashboard.ts

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,16 @@ export class Dashboard extends embed.Embed implements IDashboardNode {
8585
* Validate load configuration.
8686
*/
8787
validate(config: models.IDashboardLoadConfiguration): models.IError[] {
88-
return models.validateDashboardLoad(config);
88+
let error = models.validateDashboardLoad(config);
89+
return error ? error : this.ValidatePageView(config.pageView);
90+
}
91+
92+
/**
93+
* Validate that pageView has a legal value: if page view is defined it must have one of the values defined in models.PageView
94+
*/
95+
private ValidatePageView(pageView: models.PageView): models.IError[] {
96+
if (pageView && pageView !== "fitToWidth" && pageView !== "oneColumn" && pageView !== "actualSize") {
97+
return [{message: "pageView must be one of the followings: fitToWidth, oneColumn, actualSize"}];
98+
}
8999
}
90100
}

src/embed.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ export interface IEmbedConfiguration {
3838
settings?: models.ISettings;
3939
pageName?: string;
4040
filters?: models.IFilter[];
41+
pageView?: models.PageView;
4142
}
4243

4344
export interface IInternalEmbedConfiguration extends models.IReportLoadConfiguration {

test/test.spec.ts

Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,34 @@ declare global {
2020
}
2121
}
2222

23+
function ValidateDashboardConfigurationWorksAsExpected(pageView: string, exceptionExpected: boolean, powerbi: service.Service) {
24+
const embedUrl = `https://app.powerbi.com/dashboardEmbed`;
25+
const component = $(`<div powerbi-embed-url="${embedUrl}" powerbi-type="report"></div>`)
26+
.appendTo('#powerbi-fixture');
27+
28+
const dashboardEmbedConfig = {
29+
type: "dashboard",
30+
id: "fakeReportId",
31+
accessToken: "fakeAccessToken",
32+
embedUrl: "fakeEmbedUrl",
33+
pageView: pageView
34+
};
35+
36+
powerbi.embed(component[0], <any>dashboardEmbedConfig);
37+
38+
var exceptionThrown = false;
39+
// Act
40+
try {
41+
powerbi.embed(component[0], <any>dashboardEmbedConfig);
42+
}
43+
catch(e) {
44+
exceptionThrown = true;
45+
}
46+
47+
// Assert
48+
expect(exceptionThrown).toBe(exceptionExpected);
49+
}
50+
2351
let logMessages = (window.__karma__.config.args[0] === 'logMessages');
2452

2553
describe('service', function () {
@@ -218,6 +246,26 @@ describe('service', function () {
218246
expect(attemptToEmbed).toThrowError();
219247
});
220248

249+
it('if attempting to embed a dashboard with an invalid pageView, throw error', function () {
250+
ValidateDashboardConfigurationWorksAsExpected("notValid", true, powerbi);
251+
});
252+
253+
it('if attempting to embed a dashboard with a pageView equals fitToWidth, don\'t throw error', function () {
254+
ValidateDashboardConfigurationWorksAsExpected("fitToWidth", false, powerbi);
255+
});
256+
257+
it('if attempting to embed a dashboard with a pageView equals oneColumn, don\'t throw error', function () {
258+
ValidateDashboardConfigurationWorksAsExpected("oneColumn", false, powerbi);
259+
});
260+
261+
it('if attempting to embed a dashboard with a pageView equals actualSize, don\'t throw error', function () {
262+
ValidateDashboardConfigurationWorksAsExpected("actualSize", false, powerbi);
263+
});
264+
265+
it('if attempting to embed a dashboard with an undefined pageView, don\'t throw error', function () {
266+
ValidateDashboardConfigurationWorksAsExpected(undefined, false, powerbi);
267+
});
268+
221269
it('should get uqiqueId from config first', function () {
222270
// Arrange
223271
const testUniqueId = 'fakeUniqueId';

0 commit comments

Comments
 (0)