diff --git a/marketplace-ui/src/app/modules/product/product-detail/product-detail.component.spec.ts b/marketplace-ui/src/app/modules/product/product-detail/product-detail.component.spec.ts index b3e14d5a..821f4b5e 100644 --- a/marketplace-ui/src/app/modules/product/product-detail/product-detail.component.spec.ts +++ b/marketplace-ui/src/app/modules/product/product-detail/product-detail.component.spec.ts @@ -9,7 +9,7 @@ import { TestBed, tick } from '@angular/core/testing'; -import { By, Title } from '@angular/platform-browser'; +import { By, DomSanitizer, Title } from '@angular/platform-browser'; import { ActivatedRoute } from '@angular/router'; import { TranslateModule } from '@ngx-translate/core'; import { Viewport } from 'karma-viewport/dist/adapter/viewport'; @@ -31,6 +31,9 @@ import { ProductDetailActionType } from '../../../shared/enums/product-detail-ac import { LanguageService } from '../../../core/services/language/language.service'; import { Language } from '../../../shared/enums/language.enum'; import { MatomoTestingModule } from 'ngx-matomo-client/testing'; +import * as MarkdownIt from 'markdown-it'; +import * as MarkdownItGitHubAlerts from 'markdown-it-github-alerts'; +import { SafeHtml } from '@angular/platform-browser'; const products = MOCK_PRODUCTS._embedded.products; declare const viewport: Viewport; @@ -41,8 +44,10 @@ describe('ProductDetailComponent', () => { let routingQueryParamService: jasmine.SpyObj; let languageService: jasmine.SpyObj; let titleService: Title; + let sanitizerSpy: jasmine.SpyObj; beforeEach(async () => { + const spy = jasmine.createSpyObj('DomSanitizer', ['bypassSecurityTrustHtml']); const routingQueryParamServiceSpy = jasmine.createSpyObj( 'RoutingQueryParamService', ['getDesignerVersionFromSessionStorage', 'isDesignerEnv'] @@ -81,7 +86,8 @@ describe('ProductDetailComponent', () => { provide: LanguageService, useValue: languageServiceSpy }, - Title + Title, + { provide: DomSanitizer, useValue: spy } ] }) .overrideComponent(ProductDetailComponent, { @@ -99,6 +105,8 @@ describe('ProductDetailComponent', () => { LanguageService ) as jasmine.SpyObj; + sanitizerSpy = TestBed.inject(DomSanitizer) as jasmine.SpyObj; + titleService = TestBed.inject(Title); }); @@ -824,4 +832,15 @@ describe('ProductDetailComponent', () => { ); expect(mavenTab).toBeFalsy(); }); + + it('should render GitHub alert as safe HTML', () => { + // Arrange + const value = '**This is a test**'; + const mockedRenderedHtml = 'This is a test'; + sanitizerSpy.bypassSecurityTrustHtml.and.returnValue(mockedRenderedHtml); + + const result = component.renderGithubAlert(value); + + expect(result).toBe(mockedRenderedHtml); + }); }); diff --git a/marketplace-ui/src/app/modules/product/product-detail/product-detail.component.ts b/marketplace-ui/src/app/modules/product/product-detail/product-detail.component.ts index 98e586f6..2dc57ce7 100644 --- a/marketplace-ui/src/app/modules/product/product-detail/product-detail.component.ts +++ b/marketplace-ui/src/app/modules/product/product-detail/product-detail.component.ts @@ -420,10 +420,10 @@ export class ProductDetailComponent { return productDetail; } - renderGithubAlert(value : string ): SafeHtml { + renderGithubAlert(value: string): SafeHtml { const md = MarkdownIt(); md.use(MarkdownItGitHubAlerts); - const result = md.render(value) + const result = md.render(value); return this.sanitizer.bypassSecurityTrustHtml(result); } }