import { async, ComponentFixture, TestBed } from '@angular/core/testing'; import { DatabindedTextComponent } from './databinded-text.component'; import { CUSTOM_ELEMENTS_SCHEMA } from '@angular/core'; describe('DatabindedTextComponent', () => { let component: DatabindedTextComponent; let fixture: ComponentFixture; beforeEach(async(() => { TestBed.configureTestingModule({ declarations: [DatabindedTextComponent], schemas: [CUSTOM_ELEMENTS_SCHEMA] }).compileComponents(); })); beforeEach(() => { fixture = TestBed.createComponent(DatabindedTextComponent); component = fixture.componentInstance; fixture.detectChanges(); }); it('should create', () => { expect(component).toBeTruthy(); }); it('should parse text', () => { const sample = '

sample text

'; component.text = sample; // fixture.detectChanges(); expect(component.processedText).toContain(sample); }); it('should parse href text', () => { const sample = '

href

'; component.text = sample; expect(component.processedText).toBe(sample); }); it('should parse hashtag', () => { const hashtag = 'programmers'; const url = 'https://test.social/tags/programmers'; const sample = `

bla1 #${hashtag} bla2

`; component.text = sample; expect(component.processedText).toContain(`#programmers`); expect(component.processedText).toContain('bla1'); expect(component.processedText).toContain('bla2'); }); it('should parse hashtag - Pleroma 2.0.2', () => { const sample = `Blabla #covid19 Blibli`; component.text = sample; expect(component.processedText).toContain(`#covid19`); expect(component.processedText).toContain('Blabla'); expect(component.processedText).toContain('Blibli'); }); it('should parse mention', () => { const mention = 'sengi_app'; const url = 'https://mastodon.social/@sengi_app'; const sample = `

bla1 @${mention} bla2

`; component.text = sample; expect(component.processedText).toContain(`@sengi_app`); expect(component.processedText).toContain('bla1'); expect(component.processedText).toContain('bla2'); }); it('should parse remote mention', () => { const sample = `

@username
Yes, indeed.

`; component.text = sample; expect(component.processedText).toBe('


Yes, indeed.

'); }); it('should parse link', () => { const url = 'mydomain.co/test'; const sample = `

bla1 ${url} bla2

`; component.text = sample; expect(component.processedText).toContain(`mydomain.co/test`); expect(component.processedText).toContain('bla1'); expect(component.processedText).toContain('bla2'); }); it('should parse https://www. link', () => { const url = 'bbc.com/news/magazine-34901704'; const sample = `

The rise of"
${url}

`; component.text = sample; expect(component.processedText).toContain(`bbc.com/news/magazine-34901704

`); }); it('should parse link - dual section', () => { const sample = `

Test.
peertube.fr/videos/watch/69bb6

`; component.text = sample; expect(component.processedText).toContain('

Test.
peertube.fr/videos/watch/69bb6

'); }); it('should parse link with special character', () => { const sample = `

Magnitude: 2.5 Depth: 3.4 km
Details: 2018/09/27 06:50:17 34.968N 120.685W
Location: 10 km (6 mi) W of Guadalupe, CA
Map: google.com/maps/place/34°58'4%
#EarthQuake #Quake #California

`; component.text = sample; expect(component.processedText).toContain(`google.com/maps/place/34°58\'4%`); }); it('should parse combined hashtag, mention and link', () => { const hashtag = 'programmers'; const hashtagUrl = 'https://test.social/tags/programmers'; const mention = 'sengi_app'; const mentionUrl = 'https://mastodon.social/@sengi_app'; const linkUrl = 'mydomain.co/test'; const sample = `

bla1 #${hashtag} bla2 @${mention} bla3 ${linkUrl} bla4

`; component.text = sample; expect(component.processedText).toContain(`#programmers`); expect(component.processedText).toContain(`@sengi_app`); expect(component.processedText).toContain(`mydomain.co/test`); expect(component.processedText).toContain('bla1'); expect(component.processedText).toContain('bla2'); expect(component.processedText).toContain('bla3'); expect(component.processedText).toContain('bla4'); }); it('should parse link - GNU social in Mastodon', () => { const sample = `bla1 https://social.bitcast.info/url/819438`; component.text = sample; expect(component.processedText).toContain('https://social.bitcast.info/url/819438'); expect(component.processedText).toContain('bla1'); }); it('should parse mention - Pleroma in Mastodon', () => { const sample = `
bla1
@user 
`; component.text = sample; expect(component.processedText).toContain('@user'); expect(component.processedText).toContain('bla1'); }); it('should parse mention - Pleroma in Mastodon - 2', () => { const sample = `
@kaniini @Gargron bla1?
`; component.text = sample; expect(component.processedText).toContain('
bla1?
'); }); it('should parse mention - Friendica in Mastodon', () => { const sample = `@me Blablabla.`; component.text = sample; expect(component.processedText).toContain(' Blablabla.'); }); it('should parse mention - Misskey in Mastodon', () => { const sample = `

@sengi_app@mastodon.social Blabla

`; component.text = sample; expect(component.processedText).toContain('

Blabla

'); //FIXME: dont let domain appear in name }); it('should parse mention - Misskey in Mastodon - 2', () => { const sample = `

Since @test@mastodon.technology mentioned

`; component.text = sample; expect(component.processedText).toContain('@test'); }); it('should parse mention - Zap in Mastodon', () => { const sample = `test @test bla"`; component.text = sample; expect(component.processedText).toContain('test '); }); it('should parse hastag - Pleroma', () => { const sample = `

Bla Bla

`; component.text = sample; expect(component.processedText).toContain('

Bla #KubeCon Bla

'); }); it('should parse link - Pleroma', () => { const sample = `

Bla https://cloudblogs.microsoft.com/opensource/2019/05/21/service-mesh-interface-smi-release/

`; component.text = sample; expect(component.processedText).toContain('

Bla cloudblogs.microsoft.com/opens

'); }); it('should parse link 2 - Pleroma', () => { const sample = `Bla

https://link/`; component.text = sample; expect(component.processedText).toContain('Bla

https://link/'); }); it('should sanitize link', () => { const sample = `https://domain.fr/public.php?op=rss&id=-2&key=60c63a21c2928546b4485017876fe850c6ebcebd#tag:domain.fr,2020-05-26:/49902061`; let result = (component).sanitizeLink(sample); expect(result).toBe('https://domain.fr/public.php?op=rss&id=-2&key=60c63a21c2928546b4485017876fe850c6ebcebd#tag:domain.fr,2020-05-26:/49902061'); }); });