added tests

This commit is contained in:
Nicolas Constant 2018-10-28 19:08:54 -04:00
parent 7cd05fd55c
commit 8462dce395
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
2 changed files with 70 additions and 18 deletions

View File

@ -1,25 +1,78 @@
import { async, ComponentFixture, TestBed } from '@angular/core/testing';
import { DatabindedTextComponent } from './databinded-text.component';
import { By } from '@angular/platform-browser';
xdescribe('DatabindedTextComponent', () => {
let component: DatabindedTextComponent;
let fixture: ComponentFixture<DatabindedTextComponent>;
describe('DatabindedTextComponent', () => {
let component: DatabindedTextComponent;
let fixture: ComponentFixture<DatabindedTextComponent>;
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ DatabindedTextComponent ]
})
.compileComponents();
}));
beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [DatabindedTextComponent]
}).compileComponents();
}));
beforeEach(() => {
fixture = TestBed.createComponent(DatabindedTextComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
beforeEach(() => {
fixture = TestBed.createComponent(DatabindedTextComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should create', () => {
expect(component).toBeTruthy();
});
it('should parse text', () => {
const sample = '<p>sample text<p>';
component.text = sample;
// fixture.detectChanges();
expect(component.processedText).toContain(sample);
});
it('should parse hashtag', () => {
const hashtag = 'programmers';
const url = 'https://test.social/tags/programmers';
const sample = `<p>bla1 <a href="${url}" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>${hashtag}</span></a> bla2</p>`;
component.text = sample;
expect(component.processedText).toContain('<a href class="programmers">#programmers</a>');
expect(component.processedText).toContain('bla1');
expect(component.processedText).toContain('bla2');
});
it('should parse mention', () => {
const mention = 'sengi_app';
const url = 'https://mastodon.social/@sengi_app';
const sample = `<p>bla1 <span class="h-card"><a href="${url}" class="u-url mention" rel="nofollow noopener" target="_blank">@<span>${mention}</span></a></span> bla2</p>`;
component.text = sample;
expect(component.processedText).toContain('<a href class="account--sengi_app-mastodon-social" title="@sengi_app@mastodon.social">@sengi_app</a>');
expect(component.processedText).toContain('bla1');
expect(component.processedText).toContain('bla2');
});
it('should parse link', () => {
const url = 'mydomain.co/test';
const sample = `<p>bla1 <a href="https://${url}" rel="nofollow noopener" target="_blank"><span class="invisible">https://</span><span class="">${url}</span><span class="invisible"></span></a> bla2</p>`;
component.text = sample;
expect(component.processedText).toContain('<a href class="link-httpsmydomaincotest" title="open link">mydomain.co/test</a>');
expect(component.processedText).toContain('bla1');
expect(component.processedText).toContain('bla2');
});
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 = `<p>bla1 <a href="${hashtagUrl}" class="mention hashtag" rel="nofollow noopener" target="_blank">#<span>${hashtag}</span></a> bla2 <span class="h-card"><a href="${mentionUrl}" class="u-url mention" rel="nofollow noopener" target="_blank">@<span>${mention}</span></a></span> bla3 <a href="https://${linkUrl}" rel="nofollow noopener" target="_blank"><span class="invisible">https://</span><span class="">${linkUrl}</span><span class="invisible"></span></a> bla4</p>`;
component.text = sample;
expect(component.processedText).toContain('<a href class="programmers">#programmers</a>');
expect(component.processedText).toContain('<a href class="account--sengi_app-mastodon-social" title="@sengi_app@mastodon.social">@sengi_app</a>');
expect(component.processedText).toContain('<a href class="link-httpsmydomaincotest" title="open link">mydomain.co/test</a>');
expect(component.processedText).toContain('bla1');
expect(component.processedText).toContain('bla2');
expect(component.processedText).toContain('bla3');
expect(component.processedText).toContain('bla4');
});
});

View File

@ -1,5 +1,4 @@
import { Component, OnInit, Input, EventEmitter, Output, Renderer2, ViewChild, ElementRef } from '@angular/core';
import { forEach } from '@angular/router/src/utils/collection';
@Component({
selector: 'app-databinded-text',