-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(Link): tests converted to integration
ISSUES CLOSED: #1285
- Loading branch information
1 parent
00ad6db
commit 23298fc
Showing
2 changed files
with
76 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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: ` | ||
<ts-link | ||
[destination]="destination" | ||
[isExternal]="isExternal" | ||
[tabIndex]="tabIndex" | ||
> | ||
My Link Text | ||
</ts-link> | ||
`, | ||
}) | ||
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<TestHostComponent>; | ||
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); | ||
}); | ||
}); | ||
}); |