Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(string-literal-input): updates input on label changes (DSP-1295) #269

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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;
}
kilchenmann marked this conversation as resolved.
Show resolved Hide resolved
this.form.controls.text.setValue(value);
}

Expand Down