Skip to content

Commit

Permalink
chore(IconButton): now with integration tests
Browse files Browse the repository at this point in the history
ISSUES CLOSED: #1284
  • Loading branch information
shani-terminus authored and benjamincharity committed Mar 28, 2019
1 parent 23298fc commit 1ab6e85
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 16 deletions.
48 changes: 33 additions & 15 deletions terminus-ui/icon-button/src/icon-button.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,32 +1,50 @@
import { ElementRef } from '@angular/core';
import { ElementRefMock } from '@terminus/ngx-tools/testing';
import { Component, ViewChild } from '@angular/core';
import { ComponentFixture } from '@angular/core/testing';
import { By } from '@angular/platform-browser';

import { createComponent } from '@terminus/ngx-tools/testing';

import { TsIconButtonComponent } from './icon-button.component';
import { TsIconButtonModule } from './icon-button.module';


@Component({
template: `
<ts-icon-button
actionName="Menu"
buttonType="button"
isDisabled="false"
(clickEvent)="clickEvent($event)"
>delete_forever</ts-icon-button>
`,
})
class TestHostComponent {

@ViewChild(TsIconButtonComponent)
iconButtonComponent: TsIconButtonComponent;
}


describe(`TsIconButtonComponent`, function() {
let elRefMock: ElementRef;
let component: TsIconButtonComponent;
let component: TestHostComponent;
let fixture: ComponentFixture<TestHostComponent>;
let iconButton: HTMLElement;

beforeEach(() => {
elRefMock = new ElementRefMock();
component = new TsIconButtonComponent(
elRefMock,
);
fixture = createComponent(TestHostComponent, [], [TsIconButtonModule]);
component = fixture.componentInstance;
fixture.detectChanges();
iconButton = fixture.debugElement.query(By.css('.c-icon-button ')).nativeElement as HTMLElement;
});


test(`should exist`, () => {
expect(component).toBeTruthy();
expect(iconButton).toBeTruthy();
});


describe(`get hostElement`, () => {

test(`should return the native element`, () => {
expect(component.hostElement).toEqual(elRefMock.nativeElement);
});

test(`should contain icon`, () => {
expect(iconButton.children[0].textContent).toContain('delete_forever');
});

});
2 changes: 1 addition & 1 deletion terminus-ui/icon-button/src/icon-button.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export class TsIconButtonComponent {


/**
* Getter to return the native elemetn
* Getter to return the native element
*/
public get hostElement(): ElementRef {
return this.elementRef.nativeElement;
Expand Down

0 comments on commit 1ab6e85

Please sign in to comment.