|
| 1 | +import { describe, it, beforeEach, mock } from 'node:test' |
| 2 | +import assert from 'node:assert' |
| 3 | +import '../../../../../../tools/__mocks__/ResizeObserver.js' |
| 4 | +import TextAreaControl from './textarea.js' |
| 5 | +import Field from '../../fields/field.js' |
| 6 | +import controls from '../index.js' |
| 7 | + |
| 8 | +describe('TextAreaControl', () => { |
| 9 | + let controlInstance |
| 10 | + |
| 11 | + beforeEach(() => { |
| 12 | + controlInstance = new TextAreaControl() |
| 13 | + }) |
| 14 | + |
| 15 | + it('should create a TextAreaControl instance', () => { |
| 16 | + assert.strictEqual(controlInstance instanceof TextAreaControl, true) |
| 17 | + }) |
| 18 | + |
| 19 | + it('should have correct tag and actions', () => { |
| 20 | + assert.strictEqual(controlInstance.controlData.tag, 'textarea') |
| 21 | + assert.strictEqual(typeof controlInstance.controlData.action.input, 'function') |
| 22 | + }) |
| 23 | + |
| 24 | + it('should have correct meta information', () => { |
| 25 | + assert.strictEqual(controlInstance.controlData.meta.group, 'common') |
| 26 | + assert.strictEqual(controlInstance.controlData.meta.icon, 'textarea') |
| 27 | + assert.strictEqual(controlInstance.controlData.meta.id, 'textarea') |
| 28 | + }) |
| 29 | + |
| 30 | + it('should have required attribute set to false', () => { |
| 31 | + assert.strictEqual(controlInstance.controlData.attrs.required, false) |
| 32 | + }) |
| 33 | + |
| 34 | + it('should set data on input', () => { |
| 35 | + controls.add(controlInstance) |
| 36 | + const controlData = controlInstance.controlData |
| 37 | + const fieldData = { ...controlData, config: { controlId: controlData.meta.id } } |
| 38 | + const fieldInstance = new Field(fieldData) |
| 39 | + const mockSetData = mock.fn() |
| 40 | + fieldInstance.setData = mockSetData |
| 41 | + |
| 42 | + fieldInstance.updatePreview() |
| 43 | + const textarea = fieldInstance.preview.querySelector('textarea') |
| 44 | + textarea.value = 'test value' |
| 45 | + textarea.dispatchEvent(new window.Event('input', { bubbles: true })) |
| 46 | + |
| 47 | + assert.strictEqual(mockSetData.mock.calls.length, 1) |
| 48 | + assert.deepStrictEqual(mockSetData.mock.calls[0].arguments, ['value', 'test value']) |
| 49 | + }) |
| 50 | +}) |
0 commit comments