From ce2b6480fb9651d2793971656ad550e61144a4d1 Mon Sep 17 00:00:00 2001 From: Ryan Mathis Date: Tue, 10 Sep 2019 09:54:07 -0700 Subject: [PATCH] SHIBUI-1407 Added unit tests --- .../component/property/array-property.component.html | 2 +- .../property/array-property.component.spec.ts | 11 +++++++++++ .../component/property/array-property.component.ts | 3 +-- 3 files changed, 13 insertions(+), 3 deletions(-) diff --git a/ui/src/app/metadata/configuration/component/property/array-property.component.html b/ui/src/app/metadata/configuration/component/property/array-property.component.html index 28777731d..9a5d1648e 100644 --- a/ui/src/app/metadata/configuration/component/property/array-property.component.html +++ b/ui/src/app/metadata/configuration/component/property/array-property.component.html @@ -36,7 +36,7 @@
+ [ngClass]="{'bg-diff': isDifferent(attr.key, property.value || [])}"> {{ attr.label }}
{ 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) => { diff --git a/ui/src/app/metadata/configuration/component/property/array-property.component.ts b/ui/src/app/metadata/configuration/component/property/array-property.component.ts index f166aa155..7a042fa46 100644 --- a/ui/src/app/metadata/configuration/component/property/array-property.component.ts +++ b/ui/src/app/metadata/configuration/component/property/array-property.component.ts @@ -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);