Skip to content
This repository has been archived by the owner on Nov 6, 2024. It is now read-only.

Commit

Permalink
Fix view tests and add unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
scote committed Sep 15, 2017
1 parent 0cd0d45 commit 15f629b
Show file tree
Hide file tree
Showing 5 changed files with 94 additions and 31 deletions.
27 changes: 0 additions & 27 deletions src/app/tab/tab-item/tab-item.component.view.spec.ts

This file was deleted.

2 changes: 1 addition & 1 deletion src/app/tab/tab.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
href="{{ tabItem.href ? tabItem.href : '#' + tabItem.link }}" target="{{ tabItem.target }}">
{{ tabItem.label }}
</a>
</li>
</li>
</ul>
<div>
<ng-content select="mz-tab-item"></ng-content>
Expand Down
2 changes: 1 addition & 1 deletion src/app/tab/tab.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export class MzTabComponent implements AfterViewInit {
@ContentChildren(MzTabItemComponent) tabItems: QueryList<MzTabItemComponent>;

constructor(
private renderer: Renderer,
public renderer: Renderer,
) { }

ngAfterViewInit(): void {
Expand Down
90 changes: 90 additions & 0 deletions src/app/tab/tab.component.unit.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { async, ComponentFixture, fakeAsync, TestBed, tick } from '@angular/core/testing';

import { MzTabComponent } from './tab.component';

describe('MzTabComponent:unit', () => {
let component: MzTabComponent;
let fixture: ComponentFixture<MzTabComponent>;

beforeEach(async(() => {
TestBed.configureTestingModule({
declarations: [ MzTabComponent ],
})
.compileComponents();
}));

beforeEach(() => {
fixture = TestBed.createComponent(MzTabComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should create', () => {
expect(component).toBeTruthy();
});

describe('initTab', () => {

function forceSetTimeoutEnd() {
tick(1); // force setTimeout execution
}

it('should initialize tab using jquery', fakeAsync(() => {

component.onShow = () => {};
component.responsiveThreshold = 300;
component.swipeable = true;

const mockJQueryTabNativeElement = { tab: true };

spyOn(component.renderer, 'invokeElementMethod');

spyOn(window, '$').and.callFake((selector: any) => {
return selector === component.tabs.nativeElement
? mockJQueryTabNativeElement
: {};
});

component.initTabs();

forceSetTimeoutEnd();

expect(component.renderer.invokeElementMethod)
.toHaveBeenCalledWith(
mockJQueryTabNativeElement,
'tabs', [{
onShow: component.onShow,
responsiveThreshold: 300,
swipeable: true,
}],
);
}));

describe('initTab', () => {
it('should initialize tab using jquery', fakeAsync(() => {

const mockJQueryTabNativeElement = { tab: true };

spyOn(component.renderer, 'invokeElementMethod');

spyOn(window, '$').and.callFake((selector: any) => {
return selector === component.tabs.nativeElement
? mockJQueryTabNativeElement
: {};
});

component.selectTab('tab1');

expect(component.renderer.invokeElementMethod)
.toHaveBeenCalledWith(
mockJQueryTabNativeElement,
'tabs',
[
'select_tab',
'tab1',
],
);
}));
});
});
});
4 changes: 2 additions & 2 deletions src/app/tab/tab.component.view.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import {
MzTabItemComponent,
} from './';

fdescribe('MzCollapsibleComponent:view', () => {
describe('MzTabComponent:view', () => {

beforeEach(async(() => {
TestBed.configureTestingModule({
Expand Down Expand Up @@ -74,7 +74,7 @@ fdescribe('MzCollapsibleComponent:view', () => {

buildComponent<MzTabComponent>(`
<mz-tab>
<mz-tab-item [active]="'true"' [label]="'label'">content</mz-tab-item>
<mz-tab-item [active]="'true'" [label]="'label'">content</mz-tab-item>
</mz-tab>
`).then((fixture) => {

Expand Down

0 comments on commit 15f629b

Please sign in to comment.