From 8462dce39510d44a4c5f54197e5c0fc184eeaf88 Mon Sep 17 00:00:00 2001 From: Nicolas Constant Date: Sun, 28 Oct 2018 19:08:54 -0400 Subject: [PATCH] added tests --- .../databinded-text.component.spec.ts | 87 +++++++++++++++---- .../databinded-text.component.ts | 1 - 2 files changed, 70 insertions(+), 18 deletions(-) diff --git a/src/app/components/stream/status/databinded-text/databinded-text.component.spec.ts b/src/app/components/stream/status/databinded-text/databinded-text.component.spec.ts index 33fe54f9..bc0c0122 100644 --- a/src/app/components/stream/status/databinded-text/databinded-text.component.spec.ts +++ b/src/app/components/stream/status/databinded-text/databinded-text.component.spec.ts @@ -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; +describe('DatabindedTextComponent', () => { + let component: DatabindedTextComponent; + let fixture: ComponentFixture; - 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 = '

sample text

'; + 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 = `

bla1 #${hashtag} bla2

`; + component.text = sample; + expect(component.processedText).toContain('#programmers'); + 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 = `

bla1 @${mention} bla2

`; + component.text = sample; + expect(component.processedText).toContain(''); + expect(component.processedText).toContain('bla1'); + expect(component.processedText).toContain('bla2'); + }); + + 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 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(''); + 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'); + }); }); diff --git a/src/app/components/stream/status/databinded-text/databinded-text.component.ts b/src/app/components/stream/status/databinded-text/databinded-text.component.ts index f3d50b64..e8a2e23d 100644 --- a/src/app/components/stream/status/databinded-text/databinded-text.component.ts +++ b/src/app/components/stream/status/databinded-text/databinded-text.component.ts @@ -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',