forked from hazza/dspace-angular
80 lines
1.7 KiB
TypeScript
80 lines
1.7 KiB
TypeScript
import { TestBed } from '@angular/core/testing';
|
|
|
|
import { APP_CONFIG } from '../../../config/app-config.interface';
|
|
import { environment } from '../../../environments/environment';
|
|
import { MarkdownPipe } from './markdown.pipe';
|
|
|
|
describe('Markdown Pipe', () => {
|
|
|
|
let markdownPipe: MarkdownPipe;
|
|
|
|
beforeEach(() => {
|
|
TestBed.configureTestingModule({
|
|
providers: [
|
|
MarkdownPipe,
|
|
{
|
|
provide: APP_CONFIG,
|
|
useValue: Object.assign(environment, {
|
|
markdown: {
|
|
enabled: true,
|
|
mathjax: 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(
|
|
'<a href="https://www.dspace.com">DSpace</a>',
|
|
'<a href="https://www.dspace.com">DSpace</a>',
|
|
);
|
|
});
|
|
|
|
it('should not render javascript links', async () => {
|
|
await testTransform(
|
|
'<a href="javascript:window.alert(\'bingo!\');">exploit</a>',
|
|
'<a>exploit</a>',
|
|
);
|
|
});
|
|
|
|
it('should render undefined value', async () => {
|
|
await testTransform(
|
|
undefined,
|
|
undefined,
|
|
);
|
|
});
|
|
|
|
it('should render null value', async () => {
|
|
await testTransform(
|
|
null,
|
|
null,
|
|
);
|
|
});
|
|
|
|
async function testTransform(input: string, output: string) {
|
|
expect(
|
|
await markdownPipe.transform(input),
|
|
).toMatch(
|
|
new RegExp('.*' + output + '.*'),
|
|
);
|
|
}
|
|
});
|