Skip to content
This repository has been archived by the owner on May 7, 2021. It is now read-only.

Commit

Permalink
fix(icon): default icon bug fixed (#137)
Browse files Browse the repository at this point in the history
* fix(icon): default icon bug fixed

* fix(alm-icon-test): added unit test for alm icon directive
  • Loading branch information
sanbornsen authored and joshuawilson committed Mar 26, 2018
1 parent f25de7d commit 93847e3
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 5 deletions.
8 changes: 8 additions & 0 deletions src/app/icon/almicon-test.component.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { Component } from '@angular/core';

@Component({
selector: 'alm-icon-test',
template: ''
})

export class AlmIconTest {}
60 changes: 60 additions & 0 deletions src/app/icon/almicon.directive.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
import { By } from '@angular/platform-browser';
import { ComponentFixture, TestBed } from '@angular/core/testing';
import { AlmIconTest } from './almicon-test.component';
import { AlmIconDirective } from './almicon.directive';

describe('AlmIcon directive - ', () => {
let comp: AlmIconTest;
let fixture: ComponentFixture<AlmIconTest>;

beforeEach(() => {
TestBed.configureTestingModule({
declarations: [
AlmIconTest,
AlmIconDirective
]
});
});

it('Canary test should pass', () => {
expect(true).toBeTruthy();
});

it('Should apply appropriate class and color', () => {
TestBed.overrideComponent(AlmIconTest, {
set: {
template: '<span almIcon iconType="new"></span>'
}
})
.compileComponents()
.then(() => {
fixture = TestBed.createComponent(AlmIconTest);
comp = fixture.componentInstance;
fixture.detectChanges();
let compiled = fixture.debugElement.nativeElement
.querySelector('span');
expect(compiled.className).toBe('fa fa-star');
expect(compiled.style.color).toBe('rgb(88, 47, 192)');
});
});

it('Should apply default class and color', () => {
TestBed.overrideComponent(AlmIconTest, {
set: {
template: '<span almIcon iconType="anything"></span>'
}
})
.compileComponents()
.then(() => {
fixture = TestBed.createComponent(AlmIconTest);
comp = fixture.componentInstance;
fixture.detectChanges();
let compiled = fixture.debugElement.nativeElement
.querySelector('span');
expect(compiled.className).toBe('fa fa-crosshairs');
expect(compiled.style.color).toBe('rgb(0, 0, 0)');
});
});

});

10 changes: 5 additions & 5 deletions src/app/icon/almicon.directive.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { IconMap } from './iconmap';

export class AlmIconDirective implements OnInit, OnChanges {
@Input() iconType: string = 'none';

constructor(private elementRef: ElementRef) {
}

Expand All @@ -35,7 +35,7 @@ export class AlmIconDirective implements OnInit, OnChanges {

existingClassNames.forEach((item: any) => {
if (allClassesInMap.indexOf(item) > -1) {
element.classList.remove(item);
element.classList.remove(item);
}
});

Expand All @@ -44,13 +44,13 @@ export class AlmIconDirective implements OnInit, OnChanges {
element.setAttribute("style", "color:" + iconColor);
IconMap[this.iconType].icon.forEach((item: any) => {
element.classList.add(item);
});
});
} else {
iconColor = IconMap[this.iconType].color;
iconColor = IconMap['default'].color;
element.setAttribute("style", "color:" + iconColor);
IconMap['default'].icon.forEach((item: any) => {
element.classList.add(item);
});
}
}
}
}

0 comments on commit 93847e3

Please sign in to comment.