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
9 changes: 9 additions & 0 deletions src/service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -247,6 +247,15 @@ export class Service implements IService {
throw new Error(`Attempted to embed using config ${JSON.stringify(config)} on element ${element.outerHTML} which already has embedded comopnent associated, but could not find the existing comopnent in the list of active components. This could indicate the embeds list is out of sync with the DOM, or the component is referencing the incorrect HTML element.`);
}

/**
* TODO: Dynamic embed type switching could be supported but there is work needed to prepare the service state and DOM cleanup.
* remove all event handlers from the DOM, then reset the element to initial state which removes iframe, and removes from list of embeds
* then we can call the embedNew function which would allow setting the proper embedUrl and construction of object based on the new type.
*/
if (typeof config.type === "string" && config.type !== component.config.type) {
throw new Error(`Embedding on an existing element with a different type than the previous embed object is not supported. Attempted to embed using config ${JSON.stringify(config)} on element ${element.outerHTML}, but the existing element contains an embed of type: ${this.config.type} which does not match the new type: ${config.type}`);
}

component.load(<embed.IInternalEmbedConfiguration>config);

return component;
Expand Down
30 changes: 30 additions & 0 deletions test/test.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,36 @@ describe('service', function () {
expect(attemptEmbed).toThrowError(Error);
});

it('if attempting to embed on existing element with different type than previous embed, throw error', function () {
// Arrange
const component = $('<div></div>')
.appendTo('#powerbi-fixture');

const reportEmbedConfig: embed.IEmbedConfiguration = {
type: "report",
id: "fakeReportId",
accessToken: "fakeAccessToken",
embedUrl: "fakeEmbedUrl"
};

const dashboardEmbedConfig: embed.IEmbedConfiguration = {
type: "dashboard",
id: "fakeDashboardId",
accessToken: "fakeAccessToken",
embedUrl: "fakeEmbedUrl"
};

powerbi.embed(component[0], reportEmbedConfig);

// Act
const attemptEmbed = () => {
powerbi.embed(component[0], dashboardEmbedConfig);
};

// Assert
expect(attemptEmbed).toThrowError(Error);
});

it('if attempting to embed without specifying an embed url, throw error', function () {
// Arrange
const component = $('<div></div>')
Expand Down