Skip to content

Commit

Permalink
chore: add missing test
Browse files Browse the repository at this point in the history
  • Loading branch information
kevinchappell committed Dec 30, 2024
1 parent 80e0e8a commit 85de82b
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions src/lib/js/components/controls/form/textarea.test.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import { describe, it, beforeEach, mock } from 'node:test'
import assert from 'node:assert'
import '../../../../../../tools/__mocks__/ResizeObserver.js'
import TextAreaControl from './textarea.js'
import Field from '../../fields/field.js'
import controls from '../index.js'

describe('TextAreaControl', () => {
let controlInstance

beforeEach(() => {
controlInstance = new TextAreaControl()
})

it('should create a TextAreaControl instance', () => {
assert.strictEqual(controlInstance instanceof TextAreaControl, true)
})

it('should have correct tag and actions', () => {
assert.strictEqual(controlInstance.controlData.tag, 'textarea')
assert.strictEqual(typeof controlInstance.controlData.action.input, 'function')
})

it('should have correct meta information', () => {
assert.strictEqual(controlInstance.controlData.meta.group, 'common')
assert.strictEqual(controlInstance.controlData.meta.icon, 'textarea')
assert.strictEqual(controlInstance.controlData.meta.id, 'textarea')
})

it('should have required attribute set to false', () => {
assert.strictEqual(controlInstance.controlData.attrs.required, false)
})

it('should set data on input', () => {
controls.add(controlInstance)
const controlData = controlInstance.controlData
const fieldData = { ...controlData, config: { controlId: controlData.meta.id } }
const fieldInstance = new Field(fieldData)
const mockSetData = mock.fn()
fieldInstance.setData = mockSetData

fieldInstance.updatePreview()
const textarea = fieldInstance.preview.querySelector('textarea')
textarea.value = 'test value'
textarea.dispatchEvent(new window.Event('input', { bubbles: true }))

assert.strictEqual(mockSetData.mock.calls.length, 1)
assert.deepStrictEqual(mockSetData.mock.calls[0].arguments, ['value', 'test value'])
})
})

0 comments on commit 85de82b

Please sign in to comment.