mirror of
https://github.com/DSpace/dspace-angular.git
synced 2025-10-11 03:53:02 +00:00
This commit is contained in:
66
src/app/shared/utils/markdown.pipe.spec.ts
Normal file
66
src/app/shared/utils/markdown.pipe.spec.ts
Normal file
@@ -0,0 +1,66 @@
|
||||
import { MarkdownPipe } from './markdown.pipe';
|
||||
import { TestBed } from '@angular/core/testing';
|
||||
import { APP_CONFIG } from '../../../config/app-config.interface';
|
||||
import { environment } from '../../../environments/environment';
|
||||
|
||||
describe('Markdown Pipe', () => {
|
||||
|
||||
let markdownPipe: MarkdownPipe;
|
||||
|
||||
beforeEach(() => {
|
||||
TestBed.configureTestingModule({
|
||||
providers: [
|
||||
MarkdownPipe,
|
||||
{
|
||||
provide: APP_CONFIG,
|
||||
useValue: Object.assign(environment, {
|
||||
enableMarkdown: true,
|
||||
enableMathjax: true,
|
||||
})
|
||||
},
|
||||
],
|
||||
}).compileComponents();
|
||||
|
||||
markdownPipe = TestBed.inject(MarkdownPipe);
|
||||
});
|
||||
|
||||
it('should render markdown', async () => {
|
||||
await testTransform(
|
||||
'# Header',
|
||||
'<h1>Header</h1>'
|
||||
);
|
||||
});
|
||||
|
||||
it('should render mathjax', async () => {
|
||||
await testTransform(
|
||||
'$\\sqrt{2}^2$',
|
||||
'<svg.*?>.*</svg>'
|
||||
);
|
||||
});
|
||||
|
||||
it('should render regular links', async () => {
|
||||
await testTransform(
|
||||
/*eslint-disable quotemark*/
|
||||
'<a href="https://www.dspace.com">DSpace</a>',
|
||||
'<a href="https://www.dspace.com">DSpace</a>'
|
||||
/* eslint-enable quotemark */
|
||||
);
|
||||
});
|
||||
|
||||
it('should not render javascript links', async () => {
|
||||
await testTransform(
|
||||
/*eslint-disable quotemark*/
|
||||
'<a href="javascript:window.alert(\'bingo!\');">exploit</a>',
|
||||
'<a>exploit</a>'
|
||||
/* eslint-enable quotemark */
|
||||
);
|
||||
});
|
||||
|
||||
async function testTransform(input: string, output: string) {
|
||||
expect(
|
||||
await markdownPipe.transform(input)
|
||||
).toMatch(
|
||||
new RegExp('.*' + output + '.*')
|
||||
);
|
||||
}
|
||||
});
|
Reference in New Issue
Block a user