Files
gui/pkgs/ui/components-test/Checkbox.web.test.tsx
zeekay ba9f436467 chore: drop 'hanzo' prefix from file/identifier names, use 'gui'/'Gui'
Internal renames so source matches the published @hanzogui/[email protected] dist
(Gui.ts, createGui.ts, views/GuiProvider.mjs, views/GuiRoot.mjs).

Renames applied:
- Files: Hanzogui.ts -> Gui.ts, createHanzogui.ts -> createGui.ts,
  HanzoguiProvider.tsx -> GuiProvider.tsx, HanzoguiRoot[.native].tsx ->
  GuiRoot[.native].tsx, HanzoguiPlugin.ts -> GuiPlugin.ts,
  withHanzogui.ts -> withGui.ts, loadHanzogui.ts -> loadGui.ts,
  v4-hanzogui.ts -> v4-gui.ts, *.d.ts mirrors, hanzogui.config.ts ->
  gui.config.ts, hanzogui.build.ts -> gui.build.ts, hanzogui.css ->
  gui.css, hanzogui-build.js -> gui-build.js, etc.
- Directories: pkgs/core/create-hanzogui -> pkgs/core/create-gui,
  apps/sandbox/config/hanzogui -> apps/sandbox/config/gui.
- Identifiers: Hanzogui* -> Gui*, createHanzogui -> createGui, withHanzogui
  -> withGui, loadHanzogui -> loadGui, HANZOGUI_* env -> GUI_*,
  __hanzogui* globals -> __gui*, hanzoguiOptions/hanzoguiConfig/
  hanzoguiPlugin etc. -> guiOptions/guiConfig/guiPlugin, CSS vars
  --hanzogui-* -> --gui-*, data-hanzogui-* -> data-gui-*, [hanzogui]
  log prefix -> [gui].
- Removed duplicate pkgs/packages/hanzogui-dev-config; the canonical
  pkgs/packages/gui-dev-config (@hanzogui/dev-config) already existed
  with the correct shape. apps/demos now consumes @hanzogui/dev-config.

Preserved (public npm names):
- "hanzogui" umbrella package (pkgs/ui/hanzogui/package.json)
- "@hanzogui/*" namespace
- "hanzogui-loader" package name (pkgs/compiler/loader)
- "hanzogui-build-test-*" test fixture names
- "hanzogui-publish-smoke" workflow id
- pkgs/core/helpers-hanzogui dir (not on rename list)
- apps/gui.hanzo.ai/ marketing site directory
- AGENTS.md symlink restored after perl -i clobbered it

Smoke build (turbo run build): 169/169 workspaces successful.
Sample tests: pkgs/core/core-test getSplitStyles.android* + createGui.web
all green.
2026-05-26 18:25:52 -07:00

148 lines
4.0 KiB
TypeScript

import '@testing-library/jest-dom'
import 'vitest-axe/extend-expect'
import { Checkbox } from '@hanzogui/checkbox'
import { getDefaultGuiConfig } from '@hanzogui/config-default'
import { View, GuiProvider, createGui, getTokenValue } from '@hanzogui/core'
import type { RenderResult } from '@testing-library/react'
import { fireEvent, render } from '@testing-library/react'
import { beforeEach, describe, expect, it, vitest } from 'vitest'
import { axe } from 'vitest-axe'
const conf = createGui(getDefaultGuiConfig())
function CheckboxTest(props: React.ComponentProps<typeof Checkbox>) {
return (
<GuiProvider config={conf} defaultTheme="light">
<View>
<Checkbox {...props} aria-label="basic checkbox">
<Checkbox.Indicator data-testid={INDICATOR_TEST_ID} />
</Checkbox>
</View>
</GuiProvider>
)
}
const CHECKBOX_ROLE = 'checkbox'
const INDICATOR_TEST_ID = 'checkbox-indicator'
global.ResizeObserver = class ResizeObserver {
cb: any
constructor(cb: any) {
this.cb = cb
}
observe() {
this.cb([{ borderBoxSize: { inlineSize: 0, blockSize: 0 } }])
}
unobserve() {}
disconnect() {}
}
describe('given a default Checkbox', () => {
let rendered: RenderResult
let checkbox: HTMLElement
let indicator: HTMLElement | null
beforeEach(() => {
rendered = render(<CheckboxTest scaleSize={0} size="$true" />)
checkbox = rendered.getByRole(CHECKBOX_ROLE)
indicator = rendered.queryByTestId(INDICATOR_TEST_ID)
})
it('should have the correct width and height depending on the theme', async () => {
expect(checkbox).toHaveStyle({
width: `${getTokenValue('$true', 'size')}px`,
height: `${getTokenValue('$true', 'size')}px`,
})
})
it('should have no accessibility violations', async () => {
expect(await axe(rendered.container)).toHaveNoViolations()
})
describe('when clicking the checkbox', () => {
beforeEach(async () => {
fireEvent.click(checkbox)
indicator = rendered.queryByTestId(INDICATOR_TEST_ID)
})
it('should render a visible indicator', () => {
expect(indicator).toBeVisible()
})
describe('and clicking the checkbox again', () => {
beforeEach(async () => {
fireEvent.click(checkbox)
})
it('should remove the indicator', () => {
expect(indicator).not.toBeInTheDocument()
})
})
})
})
describe('given a disabled Checkbox', () => {
let rendered: RenderResult
beforeEach(() => {
rendered = render(<CheckboxTest disabled />)
})
it('should have no accessibility violations', async () => {
expect(await axe(rendered.container)).toHaveNoViolations()
})
})
describe('given an uncontrolled `checked` Checkbox', () => {
let rendered: RenderResult
let checkbox: HTMLElement
let indicator: HTMLElement | null
const onCheckedChange = vitest.fn()
beforeEach(() => {
rendered = render(<CheckboxTest defaultChecked onCheckedChange={onCheckedChange} />)
checkbox = rendered.getByRole(CHECKBOX_ROLE)
indicator = rendered.queryByTestId(INDICATOR_TEST_ID)
})
it('should have no accessibility violations', async () => {
expect(await axe(rendered.container)).toHaveNoViolations()
})
describe('when clicking the checkbox', () => {
beforeEach(async () => {
fireEvent.click(checkbox)
})
it('should remove the indicator', () => {
expect(indicator).not.toBeInTheDocument()
})
it('should call `onCheckedChange` prop', () => {
expect(onCheckedChange).toHaveBeenCalled()
})
})
})
describe('given a controlled `checked` Checkbox', () => {
let rendered: RenderResult
let checkbox: HTMLElement
const onCheckedChange = vitest.fn()
beforeEach(() => {
rendered = render(<CheckboxTest checked onCheckedChange={onCheckedChange} />)
checkbox = rendered.getByRole(CHECKBOX_ROLE)
})
describe('when clicking the checkbox', () => {
beforeEach(() => {
fireEvent.click(checkbox)
})
it('should call `onCheckedChange` prop', () => {
expect(onCheckedChange).toHaveBeenCalled()
})
})
})