Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(bootstrap): update multicheckbox aria attr in input tag (#3793)
Co-authored-by: Ryan Williams <ryanw@knowledgeservices.com>
- Loading branch information
Showing
3 changed files
with
85 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
77 changes: 77 additions & 0 deletions
77
src/ui/bootstrap/multicheckbox/src/multicheckbox.type.spec.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
import { FormlyFieldConfig } from '@ngx-formly/core'; | ||
import { createFieldComponent, ɵCustomEvent } from '@ngx-formly/core/testing'; | ||
import { FormlyBootstrapMultiCheckboxModule } from '@ngx-formly/bootstrap/multicheckbox'; | ||
|
||
const renderComponent = (field: FormlyFieldConfig) => { | ||
return createFieldComponent(field, { | ||
imports: [FormlyBootstrapMultiCheckboxModule], | ||
}); | ||
}; | ||
|
||
describe('ui-bootstrap: MultiCheckbox Type', () => { | ||
it('should render multicheckbox type', () => { | ||
const { query, queryAll } = renderComponent({ | ||
key: 'name', | ||
type: 'multicheckbox', | ||
props: { | ||
options: [ | ||
{ value: 1, label: 'label 1' }, | ||
{ value: 2, label: 'label 2' }, | ||
{ value: 3, label: 'label 3' }, | ||
], | ||
}, | ||
}); | ||
|
||
expect(query('formly-wrapper-form-field')).not.toBeNull(); | ||
expect(queryAll('input[type="checkbox"]')).toHaveLength(3); | ||
}); | ||
|
||
it('should add "is-invalid" class and set aria-invalid to be true on invalid', () => { | ||
const { query } = renderComponent({ | ||
key: 'name', | ||
type: 'multicheckbox', | ||
validation: { show: true }, | ||
props: { | ||
options: [{ value: 1, label: 'label 1' }], | ||
required: true, | ||
}, | ||
}); | ||
|
||
expect(query('input[type="checkbox"]').classes['is-invalid']).toBeTrue(); | ||
expect(query('input[type="checkbox"]').nativeElement.getAttribute('aria-invalid')).toBe('true'); | ||
}); | ||
|
||
it('should bind control value on change', () => { | ||
const changeSpy = jest.fn(); | ||
const { query, queryAll, field, detectChanges } = renderComponent({ | ||
key: 'name', | ||
type: 'multicheckbox', | ||
props: { | ||
options: [ | ||
{ value: 1, label: 'label 1' }, | ||
{ value: 2, label: 'label 2' }, | ||
{ value: 3, label: 'label 3' }, | ||
], | ||
change: changeSpy, | ||
}, | ||
}); | ||
query('input[type="checkbox"]').triggerEventHandler('change', ɵCustomEvent({ checked: true })); | ||
detectChanges(); | ||
expect(field.formControl.value).toEqual({ '1': true }); | ||
expect(changeSpy).toHaveBeenCalledOnce; | ||
|
||
queryAll('input[type="checkbox"]').forEach((x) => { | ||
x.triggerEventHandler('change', ɵCustomEvent({ checked: true })); | ||
detectChanges(); | ||
console.log(field.form); | ||
}); | ||
|
||
expect(field.formControl.value).toEqual({ '1': true, '2': true, '3': true }); | ||
expect(changeSpy).toHaveBeenCalledTimes(4); | ||
|
||
query('input[type="checkbox"]').triggerEventHandler('change', ɵCustomEvent({ checked: false })); | ||
detectChanges(); | ||
expect(field.formControl.value).toEqual({ '1': false, '2': true, '3': true }); | ||
expect(changeSpy).toHaveBeenCalledOnce; | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters