Disabled search button on lookup field on edit mode

This commit is contained in:
Giuseppe Digilio
2019-07-25 10:03:49 +02:00
parent f1efe21df6
commit ec105b35a9
2 changed files with 41 additions and 1 deletions

View File

@@ -237,6 +237,12 @@ describe('Dynamic Lookup component', () => {
it('should init component properly', () => { it('should init component properly', () => {
expect(lookupComp.firstInputValue).toBe(''); expect(lookupComp.firstInputValue).toBe('');
const de = lookupFixture.debugElement.queryAll(By.css('button'));
const searchBtnEl = de[0].nativeElement;
const editBtnEl = de[1].nativeElement;
expect(searchBtnEl.disabled).toBe(true);
expect(editBtnEl.disabled).toBe(true);
expect(editBtnEl.textContent.trim()).toBe('form.edit');
}); });
it('should return search results', fakeAsync(() => { it('should return search results', fakeAsync(() => {
@@ -297,6 +303,7 @@ describe('Dynamic Lookup component', () => {
expect(lookupComp.model.value).not.toBeDefined(); expect(lookupComp.model.value).not.toBeDefined();
}); });
}); });
describe('and init model value is not empty', () => { describe('and init model value is not empty', () => {
@@ -318,6 +325,19 @@ describe('Dynamic Lookup component', () => {
it('should init component properly', () => { it('should init component properly', () => {
expect(lookupComp.firstInputValue).toBe('test'); expect(lookupComp.firstInputValue).toBe('test');
}); });
it('should have search button disabled on edit mode', () => {
lookupComp.editMode = true;
lookupFixture.detectChanges();
const de = lookupFixture.debugElement.queryAll(By.css('button'));
const searchBtnEl = de[0].nativeElement;
const saveBtnEl = de[1].nativeElement;
expect(searchBtnEl.disabled).toBe(true);
expect(saveBtnEl.disabled).toBe(false);
expect(saveBtnEl.textContent.trim()).toBe('form.save');
});
}); });
}); });
@@ -340,7 +360,14 @@ describe('Dynamic Lookup component', () => {
}); });
it('should render two input element', () => { it('should render two input element', () => {
const de = lookupFixture.debugElement.queryAll(By.css('input.form-control')); const de = lookupFixture.debugElement.queryAll(By.css('input.form-control'));
const deBtn = lookupFixture.debugElement.queryAll(By.css('button'));
const searchBtnEl = deBtn[0].nativeElement;
const editBtnEl = deBtn[1].nativeElement;
expect(de.length).toBe(2); expect(de.length).toBe(2);
expect(searchBtnEl.disabled).toBe(true);
expect(editBtnEl.disabled).toBe(true);
expect(editBtnEl.textContent.trim()).toBe('form.edit');
}); });
}); });
@@ -418,6 +445,19 @@ describe('Dynamic Lookup component', () => {
expect(lookupComp.firstInputValue).toBe('Name'); expect(lookupComp.firstInputValue).toBe('Name');
expect(lookupComp.secondInputValue).toBe('Lastname'); expect(lookupComp.secondInputValue).toBe('Lastname');
}); });
it('should have search button disabled on edit mode', () => {
lookupComp.editMode = true;
lookupFixture.detectChanges();
const de = lookupFixture.debugElement.queryAll(By.css('button'));
const searchBtnEl = de[0].nativeElement;
const saveBtnEl = de[1].nativeElement;
expect(searchBtnEl.disabled).toBe(true);
expect(saveBtnEl.disabled).toBe(false);
expect(saveBtnEl.textContent.trim()).toBe('form.save');
});
}); });
}); });
}); });

View File

@@ -159,7 +159,7 @@ export class DsDynamicLookupComponent extends DynamicFormControlComponent implem
} }
public isSearchDisabled() { public isSearchDisabled() {
return isEmpty(this.firstInputValue); return isEmpty(this.firstInputValue) || this.editMode;
} }
public onBlurEvent(event: Event) { public onBlurEvent(event: Event) {