Skip to content

Commit

Permalink
feat(progressbar): add config file for progressbar component
Browse files Browse the repository at this point in the history
* feat(karma config for saucelabs testing)

* revert changes

* feat(progressbar): add config file for progressbar component
  • Loading branch information
musienkoyuriy authored and valorkin committed Dec 14, 2016
1 parent 0838055 commit ec524fe
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 17 deletions.
1 change: 1 addition & 0 deletions src/progressbar/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,4 @@ export { BarComponent } from './bar.component';
export { ProgressDirective } from './progress.directive';
export { ProgressbarComponent } from './progressbar.component';
export { ProgressbarModule } from './progressbar.module';
export { ProgressbarConfig } from './progressbar.config';
14 changes: 2 additions & 12 deletions src/progressbar/progress.directive.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,11 @@
import { Directive, HostBinding, Input, OnInit } from '@angular/core';
import { Directive, HostBinding, Input } from '@angular/core';

import { BarComponent } from './bar.component';

const progressConfig = {
animate: true,
max: 100
};

// todo: progress element conflict with bootstrap.css
// todo: need hack: replace host element with div
@Directive({selector: 'bs-progress, [progress]'})
export class ProgressDirective implements OnInit {
export class ProgressDirective {
@Input() public animate:boolean;

@HostBinding('attr.max')
Expand All @@ -32,11 +27,6 @@ export class ProgressDirective implements OnInit {

protected _max:number;

public ngOnInit():void {
this.animate = this.animate !== false;
this.max = typeof this.max === 'number' ? this.max : progressConfig.max;
}

public addBar(bar:BarComponent):void {
if (!this.animate) {
bar.transition = 'none';
Expand Down
5 changes: 5 additions & 0 deletions src/progressbar/progressbar.component.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import { Component, Input } from '@angular/core';
import { ProgressbarConfig } from './progressbar.config';

@Component({
selector: 'progressbar',
Expand All @@ -15,4 +16,8 @@ export class ProgressbarComponent {
@Input() public max:number;
@Input() public type:string;
@Input() public value:number;

public constructor(config: ProgressbarConfig) {
Object.assign(this, config);
}
}
7 changes: 7 additions & 0 deletions src/progressbar/progressbar.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import { Injectable } from '@angular/core';

Injectable();
export class ProgressbarConfig {
public animate: Boolean = true;
public max: number = 100;
}
3 changes: 2 additions & 1 deletion src/progressbar/progressbar.module.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { NgModule, ModuleWithProviders } from '@angular/core';
import { BarComponent } from './bar.component';
import { ProgressDirective } from './progress.directive';
import { ProgressbarComponent } from './progressbar.component';
import { ProgressbarConfig } from './progressbar.config';

@NgModule({
imports: [CommonModule],
Expand All @@ -12,6 +13,6 @@ import { ProgressbarComponent } from './progressbar.component';
})
export class ProgressbarModule {
public static forRoot(): ModuleWithProviders {
return {ngModule: ProgressbarModule, providers: []};
return {ngModule: ProgressbarModule, providers: [ProgressbarConfig]};
}
}
8 changes: 4 additions & 4 deletions src/spec/progressbar.component.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ describe('Component: Progress Bar', () => {

it('should work correctly with default values', () => {
const tpl = `<progressbar></progressbar>`;
TestBed.configureTestingModule({declarations: [TestProgressbarComponent], imports: [ProgressbarModule]});
TestBed.configureTestingModule({declarations: [TestProgressbarComponent], imports: [ProgressbarModule.forRoot()]});
TestBed.overrideComponent(TestProgressbarComponent, {set: {template: tpl}});
fixture = TestBed.createComponent(TestProgressbarComponent);
element = fixture.nativeElement;
Expand All @@ -22,7 +22,7 @@ describe('Component: Progress Bar', () => {

it('checking appropriate styles after setting up of type', () => {
const tpl = `<progressbar [type]="'warning'"></progressbar>`;
TestBed.configureTestingModule({declarations: [TestProgressbarComponent], imports: [ProgressbarModule]});
TestBed.configureTestingModule({declarations: [TestProgressbarComponent], imports: [ProgressbarModule.forRoot()]});
TestBed.overrideComponent(TestProgressbarComponent, {set: {template: tpl}});
fixture = TestBed.createComponent(TestProgressbarComponent);
element = fixture.nativeElement;
Expand All @@ -33,7 +33,7 @@ describe('Component: Progress Bar', () => {

it('checking of correct calculation of percent value(bar length)', () => {
const tpl = `<progressbar [max]="100" [value]="60"></progressbar>`;
TestBed.configureTestingModule({declarations: [TestProgressbarComponent], imports: [ProgressbarModule]});
TestBed.configureTestingModule({declarations: [TestProgressbarComponent], imports: [ProgressbarModule.forRoot()]});
TestBed.overrideComponent(TestProgressbarComponent, {set: {template: tpl}});
fixture = TestBed.createComponent(TestProgressbarComponent);
element = fixture.nativeElement;
Expand Down Expand Up @@ -62,7 +62,7 @@ describe('Component: Progress Bar', () => {
</bar>
</div>
`;
TestBed.configureTestingModule({declarations: [TestProgressbarComponent], imports: [ProgressbarModule]});
TestBed.configureTestingModule({declarations: [TestProgressbarComponent], imports: [ProgressbarModule.forRoot()]});
TestBed.overrideComponent(TestProgressbarComponent, {set: {template: tpl}});
fixture = TestBed.createComponent(TestProgressbarComponent);
let context = fixture.debugElement.componentInstance;
Expand Down

0 comments on commit ec524fe

Please sign in to comment.