Skip to content

Commit

Permalink
MARP-1689 Update UT
Browse files Browse the repository at this point in the history
  • Loading branch information
tvtphuc-axonivy committed Dec 20, 2024
1 parent 675309e commit 58fb66d
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -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;
Expand All @@ -41,8 +44,10 @@ describe('ProductDetailComponent', () => {
let routingQueryParamService: jasmine.SpyObj<RoutingQueryParamService>;
let languageService: jasmine.SpyObj<LanguageService>;
let titleService: Title;
let sanitizerSpy: jasmine.SpyObj<DomSanitizer>;

beforeEach(async () => {
const spy = jasmine.createSpyObj('DomSanitizer', ['bypassSecurityTrustHtml']);
const routingQueryParamServiceSpy = jasmine.createSpyObj(
'RoutingQueryParamService',
['getDesignerVersionFromSessionStorage', 'isDesignerEnv']
Expand Down Expand Up @@ -81,7 +86,8 @@ describe('ProductDetailComponent', () => {
provide: LanguageService,
useValue: languageServiceSpy
},
Title
Title,
{ provide: DomSanitizer, useValue: spy }
]
})
.overrideComponent(ProductDetailComponent, {
Expand All @@ -99,6 +105,8 @@ describe('ProductDetailComponent', () => {
LanguageService
) as jasmine.SpyObj<LanguageService>;

sanitizerSpy = TestBed.inject(DomSanitizer) as jasmine.SpyObj<DomSanitizer>;

titleService = TestBed.inject(Title);
});

Expand Down Expand Up @@ -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 = '<strong>This is a test</strong>';
sanitizerSpy.bypassSecurityTrustHtml.and.returnValue(mockedRenderedHtml);

const result = component.renderGithubAlert(value);

expect(result).toBe(mockedRenderedHtml);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}

0 comments on commit 58fb66d

Please sign in to comment.