Skip to content

Commit

Permalink
feat(string-literal-input): updates input on label changes (#269)
Browse files Browse the repository at this point in the history
  • Loading branch information
mdelez committed Jan 27, 2021
1 parent 675431f commit 5659391
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 3 deletions.
Expand Up @@ -313,4 +313,34 @@ describe('StringLiteralInputComponent', () => {
expect(await inputElement.getValue()).toEqual('Brave New World');

});

it('should update values and assign them to the correct language when langauges object is changed', async () => {

const inputElement = await loader.getHarness(MatInputHarness.with({selector: '.inputValue'}));

expect(await inputElement.getValue()).toEqual('World');

testHostComponent.labels = [
{
value: 'Welt',
language: 'de'
},
{
value: 'Brave New World',
language: 'en'
},
{
value: 'Monde',
language: 'fr'
},
{
value: 'Mondo',
language: 'it'
},
];

testHostFixture.detectChanges();

expect(await inputElement.getValue()).toEqual('Brave New World');
});
});
@@ -1,4 +1,4 @@
import { Component, ElementRef, EventEmitter, Input, OnInit, Output, ViewChild } from '@angular/core';
import { Component, ElementRef, EventEmitter, Input, OnChanges, OnInit, Output, ViewChild } from '@angular/core';
import { FormBuilder, FormControl, FormGroup } from '@angular/forms';
import { MatMenuTrigger } from '@angular/material/menu';
import { StringLiteral } from '@dasch-swiss/dsp-js';
Expand All @@ -9,7 +9,7 @@ import { SessionService } from '../../../core/session.service';
templateUrl: './string-literal-input.component.html',
styleUrls: ['./string-literal-input.component.scss']
})
export class StringLiteralInputComponent implements OnInit {
export class StringLiteralInputComponent implements OnInit, OnChanges {

languages: string[] = ['de', 'fr', 'it', 'en'];

Expand Down Expand Up @@ -125,8 +125,12 @@ export class StringLiteralInputComponent implements OnInit {
// get value from stringLiterals
const val = this.getValueFromStringLiteral(this.language);
this.updateFormField(val);
}


ngOnChanges() {
// get value from stringLiterals
const val = this.getValueFromStringLiteral(this.language);
this.updateFormField(val);
}

/**
Expand Down Expand Up @@ -210,6 +214,9 @@ export class StringLiteralInputComponent implements OnInit {
if (!value) {
value = '';
}
if (!this.form) {
return;
}
this.form.controls.text.setValue(value);
}

Expand Down

0 comments on commit 5659391

Please sign in to comment.