Fix MetadataRepresentationListElementComponent no expectation tests

Also fixed incorrect regex in isLink()
This commit is contained in:
Alexandre Vryghem
2023-07-01 13:13:27 +02:00
parent 3640d75e10
commit abc8640b5e
2 changed files with 4 additions and 8 deletions

View File

@@ -19,7 +19,7 @@ describe('MetadataRepresentationListElementComponent', () => {
let fixture: ComponentFixture<MetadataRepresentationListElementComponent>; let fixture: ComponentFixture<MetadataRepresentationListElementComponent>;
beforeEach(waitForAsync(() => { beforeEach(waitForAsync(() => {
TestBed.configureTestingModule({ return TestBed.configureTestingModule({
imports: [], imports: [],
declarations: [MetadataRepresentationListElementComponent], declarations: [MetadataRepresentationListElementComponent],
schemas: [NO_ERRORS_SCHEMA] schemas: [NO_ERRORS_SCHEMA]
@@ -39,21 +39,17 @@ describe('MetadataRepresentationListElementComponent', () => {
comp.mdRepresentation = mockMetadataRepresentation; comp.mdRepresentation = mockMetadataRepresentation;
}); });
it('isLink correctly detects a non-URL string as false', () => { it('isLink correctly detects a non-URL string as false', () => {
waitForAsync(() => {
expect(comp.isLink()).toBe(false); expect(comp.isLink()).toBe(false);
}); });
}); });
});
describe('when the value is a URL', () => { describe('when the value is a URL', () => {
beforeEach(() => { beforeEach(() => {
comp.mdRepresentation = mockMetadataRepresentationUrl; comp.mdRepresentation = mockMetadataRepresentationUrl;
}); });
it('isLink correctly detects a URL string as true', () => { it('isLink correctly detects a URL string as true', () => {
waitForAsync(() => {
expect(comp.isLink()).toBe(true); expect(comp.isLink()).toBe(true);
}); });
}); });
});
}); });

View File

@@ -25,7 +25,7 @@ export class MetadataRepresentationListElementComponent {
*/ */
isLink(): boolean { isLink(): boolean {
// Match any string that begins with http:// or https:// // Match any string that begins with http:// or https://
const linkPattern = new RegExp(/^https?\/\/.*/); const linkPattern = new RegExp(/^https?:\/\/.*/);
return linkPattern.test(this.mdRepresentation.getValue()); return linkPattern.test(this.mdRepresentation.getValue());
} }