Skip to content

Commit

Permalink
SHIBUI-1407 Added unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
rmathis committed Sep 10, 2019
1 parent f36f573 commit ce2b648
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@
<div *ngIf="property.widget && property.widget.dataUrl">
<div *ngFor="let attr of attributeList$ | async"
class="d-flex justify-content-start border-bottom border-light"
[ngClass]="{'bg-diff': isDifferent(attr.key)}">
[ngClass]="{'bg-diff': isDifferent(attr.key, property.value || [])}">
<span class="p-2" role="term" [translate]="attr.label" [ngStyle]="{'width': width}">{{ attr.label }}</span>
<div *ngFor="let v of property.value"
class="py-2"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,17 @@ describe('Array Property Component', () => {
expect(app).toBeTruthy();
}));

describe('isDifferent method', () => {
it('should return true if the value is different between any of the lists', () => {
expect(app.isDifferent('foo', [['foo', 'bar', 'baz'], ['bar', 'baz']])).toBe(true);
expect(app.isDifferent('bar', [['bar'], null])).toBe(true);
});

it('should return false if the list of values is the same', () => {
expect(app.isDifferent('foo', [['foo', 'baz'], ['foo', 'bar']])).toBe(false);
});
});

describe('attributeList$ getter', () => {
it('should return an empty list when no data or dataUrl is set', () => {
app.attributeList$.subscribe((list) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,7 @@ export class ArrayPropertyComponent extends ConfigurationPropertyComponent imple
return UriValidator.isUri(str);
}

isDifferent(key: string): boolean {
const model = this.property.value || [];
isDifferent(key: string, model: any): boolean {
return model
.map((value) => value ? value.indexOf(key) > -1 : false)
.reduce((current, val) => current !== val ? true : false, false);
Expand Down

0 comments on commit ce2b648

Please sign in to comment.