Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 17 additions & 4 deletions src/app/static-page/static-page.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ describe('StaticPageComponent', () => {

it('should rewrite OAI link with rest.baseUrl', async () => {
const oaiHtml = '<a href="/server/oai/request?verb=ListSets">OAI</a>';
const { fixture, component } = await setupTest(oaiHtml, 'https://api.example.org/rest');
const { fixture, component } = await setupTest(oaiHtml, 'https://api.example.org/server');

await component.ngOnInit();
fixture.detectChanges();
Expand All @@ -83,18 +83,31 @@ describe('StaticPageComponent', () => {

it('should avoid double slashes when rest.baseUrl ends with slash', async () => {
const oaiHtml = '<a href="/server/oai/request?verb=ListRecords">OAI</a>';
const { fixture, component } = await setupTest(oaiHtml, 'https://api.example.org/rest/');
const { fixture, component } = await setupTest(oaiHtml, 'https://api.example.org/server/');

await component.ngOnInit();
fixture.detectChanges();

expect(component.htmlContent.value).toContain('https://api.example.org/server/oai/request?verb=ListRecords');
expect(component.htmlContent.value).not.toContain('//server');
expect(component.htmlContent.value).not.toContain('//oai');
});

it('should include namespace in OAI link when rest.baseUrl has namespace prefix', async () => {
const oaiHtml = '<a href="/server/oai/request?verb=ListMetadataFormats">full list</a>';
const { fixture, component } = await setupTest(oaiHtml, 'https://api.example.org/repository/server');

await component.ngOnInit();
fixture.detectChanges();

const rewritten = 'https://api.example.org/repository/server/oai/request?verb=ListMetadataFormats';
expect(component.htmlContent.value).toContain(rewritten);
const anchor = fixture.nativeElement.querySelector('a');
expect(anchor.getAttribute('href')).toBe(rewritten);
});

it('should leave content unchanged when no OAI link is present', async () => {
const otherHtml = '<a href="/server/other">Other</a>';
const { fixture, component } = await setupTest(otherHtml, 'https://api.example.org/rest');
const { fixture, component } = await setupTest(otherHtml, 'https://api.example.org/server');

await component.ngOnInit();
fixture.detectChanges();
Expand Down
2 changes: 1 addition & 1 deletion src/app/static-page/static-page.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ export class StaticPageComponent implements OnInit {
let htmlContent = await this.htmlContentService.getHmtlContentByPathAndLocale(this.htmlFileName);
if (isNotEmpty(htmlContent)) {
const restBase = this.appConfig?.rest?.baseUrl;
const oaiUrl = restBase ? new URL('/server/oai', restBase).href : '/server/oai';
const oaiUrl = restBase ? restBase.replace(/\/+$/, '') + '/oai' : '/server/oai';
htmlContent = htmlContent.replace(/href="\/server\/oai/gi, 'href="' + oaiUrl);

this.htmlContent.next(htmlContent);
Expand Down
Loading