Skip to content

Commit

Permalink
chore(chip-field): removed an unessecary case statement and added sev…
Browse files Browse the repository at this point in the history
…eral more tests
  • Loading branch information
nickonometry committed Oct 26, 2023
1 parent e3e9435 commit 46a581c
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 9 deletions.
8 changes: 0 additions & 8 deletions src/lib/chip-field/chip-field-foundation.ts
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,6 @@ export class ChipFieldFoundation extends FieldFoundation implements IChipFieldFo
case 'Escape':
input.value = '';
break;
case 'Tab':
if (this.addMemberOnBlur) {
this._addMember(input);
break;
} else {
input.value = '';
break;
}
default:
break;
}
Expand Down
29 changes: 28 additions & 1 deletion src/test/spec/chip-field/chip-field.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1215,8 +1215,30 @@ describe('ChipFieldComponent', function(this: ITestContext) {
this.context.component.setAttribute(CHIP_FIELD_CONSTANTS.attributes.ADD_MEMBER_ON_BLUR, 'false');
expect(this.context.component.addMemberOnBlur).toBe(false);
});
});

it('chips should not be added when addMemberOnBlur is set to false and the "Tab" key is pressed', function(this: ITestContext) {
this.context = setupTestContext();
this.context.component.setAttribute(CHIP_FIELD_CONSTANTS.attributes.ADD_MEMBER_ON_BLUR, 'false');
const listener = jasmine.createSpy('add member listener');
this.context.component.addEventListener(CHIP_FIELD_CONSTANTS.events.MEMBER_ADDED, listener);
getNativeInput(this.context.component).value = 'test';
dispatchKeydownEvent(getNativeInput(this.context.component), 'Tab');
expect(listener).toHaveBeenCalledTimes(0)
expect(getNativeInput(this.context.component).value).withContext('the input value should have been cleared').toBe('');
});


it('chips should be added when addMemberOnBlur is set to true and the mouse is clicked outside of the input', function(this: ITestContext) {
this.context = setupTestContext();
this.context.component.setAttribute(CHIP_FIELD_CONSTANTS.attributes.ADD_MEMBER_ON_BLUR, 'true');
const listener = jasmine.createSpy('add member listener');
this.context.component.addEventListener(CHIP_FIELD_CONSTANTS.events.MEMBER_ADDED, listener);
getNativeInput(this.context.component).value = 'test';
getNativeInput(this.context.component).focus();
getNativeInput(this.context.component).blur();
expect(listener).toHaveBeenCalledTimes(1)
});
});
});

describe('With no label', function(this: ITestContext) {
Expand Down Expand Up @@ -1295,4 +1317,9 @@ describe('ChipFieldComponent', function(this: ITestContext) {
component.append(chip);
return chip;
}

function checkIfAChipWasAdded(component: IChipFieldComponent): number {
let test = component.querySelectorAll('forge-chip');
return test.length;
}
});

0 comments on commit 46a581c

Please sign in to comment.