Skip to content

Commit 608fa8f

Browse files
Mattia VianelliMattia Vianelli
authored andcommitted
DSC-2668 Added tests for link rendering
(cherry picked from commit bf3df0b5cea3071dcec8267a2bd185afb4e3cab0)
1 parent 8a1ea05 commit 608fa8f

File tree

1 file changed

+74
-1
lines changed

1 file changed

+74
-1
lines changed

src/app/cris-layout/cris-layout-matrix/cris-layout-box-container/boxes/metadata/rendering-types/link/link.component.spec.ts

Lines changed: 74 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,5 +165,78 @@ describe('LinkComponent', () => {
165165
done();
166166
});
167167
});
168-
});
169168

169+
describe('URL validation and conditional rendering', () => {
170+
171+
describe('valid URLs', () => {
172+
it('should render link for URL with http protocol', () => {
173+
component.metadataValue = { value: 'http://test.com' } as MetadataValue;
174+
component.ngOnInit();
175+
fixture.detectChanges();
176+
177+
expect(component.isLink).toBe(true);
178+
const linkElement = fixture.debugElement.query(By.css('span.link-value a'));
179+
expect(linkElement).toBeTruthy();
180+
expect(linkElement.nativeElement.href).toBe('http://test.com/');
181+
});
182+
183+
it('should render link for URL with https protocol', () => {
184+
component.metadataValue = { value: 'https://test.com' } as MetadataValue;
185+
component.ngOnInit();
186+
fixture.detectChanges();
187+
188+
expect(component.isLink).toBe(true);
189+
const linkElement = fixture.debugElement.query(By.css('span.link-value a'));
190+
expect(linkElement).toBeTruthy();
191+
});
192+
193+
it('should render link for URL with www prefix', () => {
194+
component.metadataValue = { value: 'www.test.com' } as MetadataValue;
195+
component.ngOnInit();
196+
fixture.detectChanges();
197+
198+
expect(component.isLink).toBe(true);
199+
const linkElement = fixture.debugElement.query(By.css('span.link-value a'));
200+
expect(linkElement).toBeTruthy();
201+
expect(linkElement.nativeElement.href).toBe('http://www.test.com/');
202+
});
203+
204+
it('should render link for URL with path', () => {
205+
component.metadataValue = { value: 'https://test.com/path/to/page' } as MetadataValue;
206+
component.ngOnInit();
207+
fixture.detectChanges();
208+
209+
expect(component.isLink).toBe(true);
210+
const linkElement = fixture.debugElement.query(By.css('span.link-value a'));
211+
expect(linkElement).toBeTruthy();
212+
});
213+
214+
it('should render link for FTP URL', () => {
215+
component.metadataValue = { value: 'ftp://files.test.com' } as MetadataValue;
216+
component.ngOnInit();
217+
fixture.detectChanges();
218+
219+
expect(component.isLink).toBe(true);
220+
const linkElement = fixture.debugElement.query(By.css('span.link-value a'));
221+
expect(linkElement).toBeTruthy();
222+
expect(linkElement.nativeElement.href).toBe('ftp://files.test.com/');
223+
});
224+
});
225+
226+
describe('invalid URLs - plain text rendering', () => {
227+
it('should render plain text for random text without URL pattern', () => {
228+
component.metadataValue = { value: 'just some text' } as MetadataValue;
229+
component.ngOnInit();
230+
fixture.detectChanges();
231+
232+
expect(component.isLink).toBe(false);
233+
const plainText = fixture.debugElement.query(By.css('span.plain-text-value'));
234+
const link = fixture.debugElement.query(By.css('span.link-value a'));
235+
236+
expect(plainText).toBeTruthy();
237+
expect(link).toBeFalsy();
238+
expect(plainText.nativeElement.textContent).toContain('just some text');
239+
});
240+
});
241+
});
242+
});

0 commit comments

Comments
 (0)