Skip to content

Commit

Permalink
test: fix and cleanup specs (swimlane#305)
Browse files Browse the repository at this point in the history
  • Loading branch information
clydin authored and marjan-georgiev committed Mar 30, 2017
1 parent c7f1c64 commit 4d135f3
Show file tree
Hide file tree
Showing 14 changed files with 166 additions and 269 deletions.
1 change: 1 addition & 0 deletions config/spec-bundle.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ Error.stackTraceLimit = Infinity;

require('core-js/es6');
require('core-js/es7/reflect');
require('core-js/es7/array');

// Typescript emit helpers polyfill
require('ts-helpers');
Expand Down
46 changes: 0 additions & 46 deletions config/testing-utils.ts

This file was deleted.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,7 @@
"@types/d3-time-format": "2.0.4",
"@types/d3-transition": "1.0.7",
"@types/jasmine": "2.5.41",
"@types/node": "^7.0.12",
"angular2-template-loader": "^0.6.0",
"autoprefixer": "^6.7.0",
"awesome-typescript-loader": "~3.1.2",
Expand Down
75 changes: 32 additions & 43 deletions src/bar-chart/bar-horizontal.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { TestBed } from '@angular/core/testing';
import { TestBed, async } from '@angular/core/testing';
import { Component } from '@angular/core';
import { By } from '@angular/platform-browser';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';

import '../../config/testing-utils';
import { single } from '../../demo/data';
import { APP_BASE_HREF } from '@angular/common';

Expand All @@ -27,7 +27,7 @@ describe('<ngx-charts-bar-horizontal>', () => {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [TestComponent],
imports: [BarChartModule],
imports: [NoopAnimationsModule, BarChartModule],
providers: [
{provide: APP_BASE_HREF, useValue: '/'}
]
Expand All @@ -36,7 +36,7 @@ describe('<ngx-charts-bar-horizontal>', () => {

describe('basic setup', () => {

beforeEach(() => {
beforeEach(async(() => {
TestBed.overrideComponent(TestComponent, {
set: {
template: `
Expand All @@ -46,51 +46,41 @@ describe('<ngx-charts-bar-horizontal>', () => {
[results]="single">
</ngx-charts-bar-horizontal>`
}
});
});
}).compileComponents();
}));

it('should set the svg width and height', (done) => {
TestBed.compileComponents().then(() => {
const fixture = TestBed.createComponent(TestComponent);
fixture.detectChanges();
it('should set the svg width and height', async(() => {
const fixture = TestBed.createComponent(TestComponent);
fixture.detectChanges();

const svg = fixture.debugElement.nativeElement.querySelector('svg');
const svg = fixture.debugElement.nativeElement.querySelector('svg');

expect(svg.getAttribute('width')).toBe('400');
expect(svg.getAttribute('height')).toBe('800');
expect(svg.getAttribute('width')).toBe('400');
expect(svg.getAttribute('height')).toBe('800');
}));

done();
});
});
it('should render 12 cell elements', async(() => {
const fixture = TestBed.createComponent(TestComponent);
fixture.detectChanges();

it('should render 12 cell elements', (done) => {
TestBed.compileComponents().then(() => {
const fixture = TestBed.createComponent(TestComponent);
fixture.detectChanges();
const compiled = fixture.debugElement.nativeElement;

const compiled = fixture.debugElement.nativeElement;
expect(compiled.querySelectorAll('path.bar').length).toEqual(6);
}));

expect(compiled.querySelectorAll('path.bar').length).toEqual(6);
done();
});
});

it('should render correct cell size', (done) => {
TestBed.compileComponents().then(() => {
const fixture = TestBed.createComponent(TestComponent);
fixture.detectChanges();
it('should render correct cell size', async(() => {
const fixture = TestBed.createComponent(TestComponent);
fixture.detectChanges();

const bar = fixture.debugElement.query(By.directive(BarComponent));
const bar = fixture.debugElement.query(By.directive(BarComponent));

expect(bar.componentInstance.height).toEqual(123); // ~(780 - 5 * barPadding) / 6
done();
});
});
expect(bar.componentInstance.height).toEqual(123); // ~(780 - 5 * barPadding) / 6
}));
});

describe('padding', () => {

it('should render correct cell size, with zero padding', (done) => {
it('should render correct cell size, with zero padding', async(() => {
TestBed.overrideComponent(TestComponent, {
set: {
template: `
Expand All @@ -109,12 +99,11 @@ describe('<ngx-charts-bar-horizontal>', () => {

const bar = fixture.debugElement.query(By.directive(BarComponent));

expect(bar.componentInstance.height).toEqual(130); // ~(780 - 5 * barPadding) / 6
done();
expect(bar.componentInstance.height).toEqual(130); // ~(780 - 5 * barPadding) / 6
});
});
}));

it('should render correct cell size, with padding', (done) => {
it('should render correct cell size, with padding', async(() => {
TestBed.overrideComponent(TestComponent, {
set: {
template: `
Expand All @@ -133,9 +122,9 @@ describe('<ngx-charts-bar-horizontal>', () => {

const bar = fixture.debugElement.query(By.directive(BarComponent));

expect(bar.componentInstance.height).toEqual(113); // ~(780 - 5 * barPadding) / 6
done();
expect(bar.componentInstance.height).toEqual(113); // ~(780 - 5 * barPadding) / 6
});
});
}));

});
});
71 changes: 30 additions & 41 deletions src/bar-chart/bar-vertical.component.spec.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { TestBed } from '@angular/core/testing';
import { TestBed, async } from '@angular/core/testing';
import { Component } from '@angular/core';
import { By } from '@angular/platform-browser';
import { NoopAnimationsModule } from '@angular/platform-browser/animations';

import '../../config/testing-utils';
import { single } from '../../demo/data';
import { APP_BASE_HREF } from '@angular/common';

Expand All @@ -27,7 +27,7 @@ describe('<ngx-charts-bar-vertical>', () => {
beforeEach(() => {
TestBed.configureTestingModule({
declarations: [TestComponent],
imports: [BarChartModule],
imports: [NoopAnimationsModule, BarChartModule],
providers: [
{provide: APP_BASE_HREF, useValue: '/'}
]
Expand All @@ -36,7 +36,7 @@ describe('<ngx-charts-bar-vertical>', () => {

describe('basic setup', () => {

beforeEach(() => {
beforeEach(async(() => {
TestBed.overrideComponent(TestComponent, {
set: {
template: `
Expand All @@ -47,49 +47,40 @@ describe('<ngx-charts-bar-vertical>', () => {
</ngx-charts-bar-vertical>`
}
});
});
}));

it('should set the svg width and height', (done) => {
TestBed.compileComponents().then(() => {
const fixture = TestBed.createComponent(TestComponent);
fixture.detectChanges();
it('should set the svg width and height', async(() => {
const fixture = TestBed.createComponent(TestComponent);
fixture.detectChanges();

const svg = fixture.debugElement.nativeElement.querySelector('svg');
const svg = fixture.debugElement.nativeElement.querySelector('svg');

expect(svg.getAttribute('width')).toBe('400');
expect(svg.getAttribute('height')).toBe('800');
done();
});
});
expect(svg.getAttribute('width')).toBe('400');
expect(svg.getAttribute('height')).toBe('800');
}));

it('should render 12 cell elements', (done) => {
TestBed.compileComponents().then(() => {
const fixture = TestBed.createComponent(TestComponent);
fixture.detectChanges();
it('should render 12 cell elements', async(() => {
const fixture = TestBed.createComponent(TestComponent);
fixture.detectChanges();

const compiled = fixture.debugElement.nativeElement;
const compiled = fixture.debugElement.nativeElement;

expect(compiled.querySelectorAll('path.bar').length).toEqual(6);
done();
});
});
expect(compiled.querySelectorAll('path.bar').length).toEqual(6);
}));

it('should render correct cell size', (done) => {
TestBed.compileComponents().then(() => {
const fixture = TestBed.createComponent(TestComponent);
fixture.detectChanges();
it('should render correct cell size', async(() => {
const fixture = TestBed.createComponent(TestComponent);
fixture.detectChanges();

const bar = fixture.debugElement.query(By.directive(BarComponent));
const bar = fixture.debugElement.query(By.directive(BarComponent));

expect(bar.componentInstance.width).toEqual(53); // ~(360 - 5 * barPadding) / 6
done();
});
});
expect(bar.componentInstance.width).toEqual(53); // ~(360 - 5 * barPadding) / 6
}));
});

describe('padding', () => {

it('should render correct cell size, with zero padding', (done) => {
it('should render correct cell size, with zero padding', async(() => {
TestBed.overrideComponent(TestComponent, {
set: {
template: `
Expand All @@ -108,12 +99,11 @@ describe('<ngx-charts-bar-vertical>', () => {

const bar = fixture.debugElement.query(By.directive(BarComponent));

expect(bar.componentInstance.width).toEqual(60); // ~(360 - 5 * barPadding) / 6
done();
expect(bar.componentInstance.width).toEqual(60); // ~(360 - 5 * barPadding) / 6
});
});
}));

it('should render correct cell size, with padding', (done) => {
it('should render correct cell size, with padding', async(() => {
TestBed.overrideComponent(TestComponent, {
set: {
template: `
Expand All @@ -132,9 +122,8 @@ describe('<ngx-charts-bar-vertical>', () => {

const bar = fixture.debugElement.query(By.directive(BarComponent));

expect(bar.componentInstance.width).toEqual(43); // ~(360 - 5 * barPadding) / 6
done();
expect(bar.componentInstance.width).toEqual(43); // ~(360 - 5 * barPadding) / 6
});
});
}));
});
});
Loading

0 comments on commit 4d135f3

Please sign in to comment.