Skip to content
Snippets Groups Projects
Commit bc52d30e authored by Xiao Gui's avatar Xiao Gui
Browse files

bugfix: screenshot of allen mouse and waxholm

bugfix: publications on separate lines
bugfix: doi parsed incorrectly
feat: added tests for doiParser pipe
parent 7bc21174
No related branches found
No related tags found
No related merge requests found
Showing
with 24 additions and 4 deletions
......@@ -14,12 +14,15 @@
<!-- publications -->
<mat-card-content>
<div class="d-inline-block mb-2"
<div class="d-block mb-2"
*ngFor="let publication of publications">
<a [href]="publication.doi | doiParserPipe"
<a *ngIf="publication.doi; else plainText" [href]="publication.doi | doiParserPipe"
target="_blank">
{{ publication.cite }}
</a>
<ng-template #plainText>
{{ publication.cite }}
</ng-template>
</div>
</mat-card-content>
......
import {} from 'jasmine'
import { DoiParserPipe } from './doiPipe.pipe'
describe('doiPipe.pipe.ts', () => {
const pipe = new DoiParserPipe()
describe('DoiParsePIpe' , () => {
it('should parse string without prefix by appending doi prefix', () => {
const result = pipe.transform('123.456')
expect(result).toBe(`https://doi.org/123.456`)
})
it('should not append doi prefix if the first argument leads by http or https', () => {
expect(pipe.transform('http://google.com')).toBe('http://google.com')
expect(pipe.transform('https://google.com')).toBe('https://google.com')
})
})
})
\ No newline at end of file
......@@ -6,7 +6,7 @@ import { Pipe, PipeTransform } from "@angular/core";
export class DoiParserPipe implements PipeTransform{
public transform(s: string, prefix: string = 'https://doi.org/'){
const prependFlag = /^https?:\.\./.test(s)
return `${prependFlag ? prefix : ''}${s}`
const hasProtocol = /^https?\:\/\//.test(s)
return `${hasProtocol ? '' : prefix}${s}`
}
}
\ No newline at end of file
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment