From 23298fcad463cc2e760182ea2aef550c903f1383 Mon Sep 17 00:00:00 2001 From: shani-terminus Date: Tue, 19 Mar 2019 15:52:47 -0400 Subject: [PATCH] chore(Link): tests converted to integration ISSUES CLOSED: #1285 --- terminus-ui/link/src/link.component.html | 1 + terminus-ui/link/src/link.component.spec.ts | 81 +++++++++++++++++++-- 2 files changed, 76 insertions(+), 6 deletions(-) diff --git a/terminus-ui/link/src/link.component.html b/terminus-ui/link/src/link.component.html index f6c47ebe8..3bafcbaf5 100644 --- a/terminus-ui/link/src/link.component.html +++ b/terminus-ui/link/src/link.component.html @@ -1,6 +1,7 @@ diff --git a/terminus-ui/link/src/link.component.spec.ts b/terminus-ui/link/src/link.component.spec.ts index eb42386bf..df5891177 100644 --- a/terminus-ui/link/src/link.component.spec.ts +++ b/terminus-ui/link/src/link.component.spec.ts @@ -1,23 +1,92 @@ +import { APP_BASE_HREF } from '@angular/common'; +import { Component, ViewChild } from '@angular/core'; +import { ComponentFixture, tick } from '@angular/core/testing'; +import { By } from '@angular/platform-browser'; +import { RouterModule } from '@angular/router'; + +import { createComponent } from '@terminus/ngx-tools/testing'; + import { TsLinkComponent } from './link.component'; +import { TsLinkModule } from './link.module'; + +@Component({ + template: ` + + My Link Text + + `, +}) +class TestHostComponent { + destination!: any; + isExternal!: boolean; + tabIndex!: number | undefined; + + @ViewChild(TsLinkComponent) + linkComponent!: TsLinkComponent; +} describe(`TsLinkComponent`, function() { - let component: TsLinkComponent; + let component: TestHostComponent; + let fixture: ComponentFixture; + let link: HTMLElement; + let linkComponent: TsLinkComponent; beforeEach(() => { - component = new TsLinkComponent(); + fixture = createComponent(TestHostComponent, [{provide: APP_BASE_HREF, useValue: '/my/app'}], [TsLinkModule, RouterModule.forRoot([])]); + component = fixture.componentInstance; + linkComponent = component.linkComponent; + fixture.detectChanges(); }); - it(`should exist`, () => { - expect(component).toBeTruthy(); + test(`should exist`, () => { + expect(linkComponent).toBeTruthy(); + }); + + describe(`isInternal`, () => { + test(`should default and retrieve`, () => { + link = fixture.debugElement.query(By.css('.c-link')).nativeElement as HTMLElement; + component.isExternal = false; + component.destination = ['/#']; + + expect(link.classList).toContain('qa-link-internal'); + }); }); describe(`isExternal`, () => { - it(`should set and retrieve`, () => { + test(`should set and retrieve`, () => { + component.destination = 'www.google.com'; component.isExternal = true; - expect(component.isExternal).toEqual(true); + fixture.detectChanges(); + link = fixture.debugElement.query(By.css('.c-link')).nativeElement as HTMLElement; + + expect(link.classList).toContain('qa-link-external'); + expect(link.children[0].textContent).toContain('open_in_new'); + }); + + test(`should throw error if invalid value is passed`, () => { + window.console.warn = jest.fn(); + component.isExternal = 'foo' as any; + fixture.detectChanges(); + + expect(window.console.warn).toHaveBeenCalled(); }); }); + describe(`tabIndex`, () => { + test(`should default to 0 and be set`, () => { + expect(link.tabIndex).toEqual(0); + + component.tabIndex = 9; + fixture.detectChanges(); + link = fixture.debugElement.query(By.css('.c-link')).nativeElement as HTMLElement; + + expect(link.tabIndex).toEqual(9); + }); + }); });