@@ -171,6 +171,48 @@ describe('service', function () {
171171 expect ( attemptToEmbed ) . toThrowError ( ) ;
172172 } ) ;
173173
174+ it ( 'should get uqiqueId from config first' , function ( ) {
175+ // Arrange
176+ const testUniqueId = 'fakeUniqueId' ;
177+ const embedUrl = `https://embedded.powerbi.com/appTokenReportEmbed` ;
178+ const $reportContainer = $ ( `<div powerbi-embed-url="${ embedUrl } " powerbi-type="report" powerbi-report-id="abc123" powerbi-name="differentUniqueId"></div>` )
179+ . appendTo ( '#powerbi-fixture' ) ;
180+
181+ // Act
182+ const report = powerbi . embed ( $reportContainer [ 0 ] , { uniqueId : testUniqueId } ) ;
183+
184+ // Assert
185+ expect ( report . config . uniqueId ) . toEqual ( testUniqueId ) ;
186+ } ) ;
187+
188+ it ( 'should get uqiqueId from name attribute if uniqueId is not specified in config' , function ( ) {
189+ // Arrange
190+ const testUniqueId = 'fakeUniqueId' ;
191+ const embedUrl = `https://embedded.powerbi.com/appTokenReportEmbed` ;
192+ const $reportContainer = $ ( `<div powerbi-embed-url="${ embedUrl } " powerbi-type="report" powerbi-report-id="abc123" powerbi-name="${ testUniqueId } "></div>` )
193+ . appendTo ( '#powerbi-fixture' ) ;
194+
195+ // Act
196+ const report = powerbi . embed ( $reportContainer [ 0 ] ) ;
197+
198+ // Assert
199+ expect ( report . config . uniqueId ) . toEqual ( testUniqueId ) ;
200+ } ) ;
201+
202+ it ( 'should generate uqiqueId if uniqueId is not specified in config or attribute' , function ( ) {
203+ // Arrange
204+ const testUniqueId = 'fakeUniqueId' ;
205+ const embedUrl = `https://embedded.powerbi.com/appTokenReportEmbed` ;
206+ const $reportContainer = $ ( `<div powerbi-embed-url="${ embedUrl } " powerbi-type="report" powerbi-report-id="abc123"></div>` )
207+ . appendTo ( '#powerbi-fixture' ) ;
208+
209+ // Act
210+ const report = powerbi . embed ( $reportContainer [ 0 ] ) ;
211+
212+ // Assert
213+ expect ( report . config . uniqueId ) . toEqual ( jasmine . any ( String ) ) ;
214+ } ) ;
215+
174216 it ( 'if component is already embedded in element re-use the existing component by calling load with the new information' , function ( ) {
175217 // Arrange
176218 const $element = $ ( '<div powerbi-embed-url="https://app.powerbi.com/reportEmbed?reportId=ABC123" powerbi-type="report"></div>' )
@@ -388,6 +430,29 @@ describe('service', function () {
388430 // Assert
389431 expect ( $element . html ( ) ) . toEqual ( '' ) ;
390432 } ) ;
433+
434+ it ( 'removes the powerbi instance from the list of embeds' , function ( ) {
435+ // Arrange
436+ const $element = $ ( '<div></div>' ) ;
437+ const testEmbedConfig = {
438+ type : 'report' ,
439+ embedUrl : 'fakeUrl' ,
440+ id : 'fakeReportId' ,
441+ accessToken : 'fakeToken' ,
442+ uniqueId : 'fakeUniqeId'
443+ } ;
444+ powerbi . embed ( $element . get ( 0 ) , testEmbedConfig ) ;
445+
446+ // Act
447+ const report = powerbi . find ( testEmbedConfig . uniqueId ) ;
448+ expect ( report ) . toBeDefined ( ) ;
449+
450+ powerbi . reset ( $element . get ( 0 ) ) ;
451+
452+ // Assert
453+ const report2 = powerbi . find ( testEmbedConfig . uniqueId ) ;
454+ expect ( report2 ) . toBeUndefined ( ) ;
455+ } ) ;
391456 } ) ;
392457} ) ;
393458
0 commit comments