|
| 1 | +/* eslint-disable no-undef -- Until https://github.com/ember-cli/eslint-plugin-ember/issues/1747 is resolved... */ |
| 2 | +/* eslint-disable simple-import-sort/imports,padding-line-between-statements,decorator-position/decorator-position -- Can't fix these manually, without --fix working in .gts */ |
| 3 | +import { render } from '@ember/test-helpers'; |
| 4 | +import { module, test } from 'qunit'; |
| 5 | +import { setupRenderingTest } from 'test-app/tests/helpers'; |
| 6 | + |
| 7 | +import ToucanForm from '@crowdstrike/ember-toucan-form/components/toucan-form'; |
| 8 | + |
| 9 | +interface TestData { |
| 10 | + radio?: string; |
| 11 | +} |
| 12 | + |
| 13 | +module('Integration | Component | ToucanForm | RadioGroup', function (hooks) { |
| 14 | + setupRenderingTest(hooks); |
| 15 | + |
| 16 | + test('it sets the readonly attribute with `@isReadOnly` at the root', async function (assert) { |
| 17 | + const data: TestData = { |
| 18 | + radio: 'option-2', |
| 19 | + }; |
| 20 | + |
| 21 | + await render(<template> |
| 22 | + <ToucanForm @data={{data}} as |form|> |
| 23 | + <form.RadioGroup |
| 24 | + @label="Radios" |
| 25 | + @name="radio" |
| 26 | + @isReadOnly={{true}} |
| 27 | + as |group| |
| 28 | + > |
| 29 | + <group.RadioField @label="option-1" @value="option-1" data-radio-1 /> |
| 30 | + <group.RadioField @label="option-2" @value="option-2" data-radio-2 /> |
| 31 | + </form.RadioGroup> |
| 32 | + </ToucanForm> |
| 33 | + </template>); |
| 34 | + |
| 35 | + assert.dom('[data-radio-1]').hasAttribute('readonly'); |
| 36 | + assert.dom('[data-radio-2]').hasAttribute('readonly'); |
| 37 | + }); |
| 38 | + |
| 39 | + test('it sets the readonly attribute with `@isReadOnly` on individual radios', async function (assert) { |
| 40 | + const data: TestData = { |
| 41 | + radio: 'option-2', |
| 42 | + }; |
| 43 | + |
| 44 | + await render(<template> |
| 45 | + <ToucanForm @data={{data}} as |form|> |
| 46 | + <form.RadioGroup @label="Radios" @name="radio" as |group|> |
| 47 | + <group.RadioField @label="option-1" @value="option-1" data-radio-1 /> |
| 48 | + <group.RadioField |
| 49 | + @label="option-2" |
| 50 | + @value="option-2" |
| 51 | + @isReadOnly={{true}} |
| 52 | + data-radio-2 |
| 53 | + /> |
| 54 | + </form.RadioGroup> |
| 55 | + </ToucanForm> |
| 56 | + </template>); |
| 57 | + |
| 58 | + assert.dom('[data-radio-1]').hasNoAttribute('readonly'); |
| 59 | + assert.dom('[data-radio-2]').hasAttribute('readonly'); |
| 60 | + }); |
| 61 | +}); |
0 commit comments