Merged in fix/3697-prettier-configs (pull request #3396)
fix(SW-3691): Setup one prettier config for whole repo * Setup prettierrc in root and remove other configs Approved-by: Joakim Jäderberg Approved-by: Linus Flood
This commit is contained in:
@@ -1,56 +1,56 @@
|
||||
import { describe, expect, it, vi, beforeEach } from 'vitest'
|
||||
import { renderHook } from '@testing-library/react'
|
||||
import { useInputHasValue, clearInput } from './utils'
|
||||
import { describe, expect, it, vi, beforeEach } from "vitest"
|
||||
import { renderHook } from "@testing-library/react"
|
||||
import { useInputHasValue, clearInput } from "./utils"
|
||||
|
||||
describe('useInputHasValue', () => {
|
||||
const createMockRef = (value = '') => ({
|
||||
describe("useInputHasValue", () => {
|
||||
const createMockRef = (value = "") => ({
|
||||
current: { value } as HTMLInputElement,
|
||||
})
|
||||
|
||||
describe('controlled input (value prop)', () => {
|
||||
it('returns true when value has content', () => {
|
||||
describe("controlled input (value prop)", () => {
|
||||
it("returns true when value has content", () => {
|
||||
const ref = createMockRef()
|
||||
const { result } = renderHook(() => useInputHasValue('hello', ref))
|
||||
const { result } = renderHook(() => useInputHasValue("hello", ref))
|
||||
expect(result.current).toBe(true)
|
||||
})
|
||||
|
||||
it('returns false when value is empty string', () => {
|
||||
it("returns false when value is empty string", () => {
|
||||
const ref = createMockRef()
|
||||
const { result } = renderHook(() => useInputHasValue('', ref))
|
||||
const { result } = renderHook(() => useInputHasValue("", ref))
|
||||
expect(result.current).toBe(false)
|
||||
})
|
||||
|
||||
it('returns false when value is only whitespace', () => {
|
||||
it("returns false when value is only whitespace", () => {
|
||||
const ref = createMockRef()
|
||||
const { result } = renderHook(() => useInputHasValue(' ', ref))
|
||||
const { result } = renderHook(() => useInputHasValue(" ", ref))
|
||||
expect(result.current).toBe(false)
|
||||
})
|
||||
|
||||
it('updates when value prop changes', () => {
|
||||
it("updates when value prop changes", () => {
|
||||
const ref = createMockRef()
|
||||
const { result, rerender } = renderHook(
|
||||
({ value }) => useInputHasValue(value, ref),
|
||||
{ initialProps: { value: '' } }
|
||||
{ initialProps: { value: "" } }
|
||||
)
|
||||
|
||||
expect(result.current).toBe(false)
|
||||
|
||||
rerender({ value: 'new value' })
|
||||
rerender({ value: "new value" })
|
||||
expect(result.current).toBe(true)
|
||||
})
|
||||
})
|
||||
})
|
||||
|
||||
describe('clearInput', () => {
|
||||
describe("clearInput", () => {
|
||||
beforeEach(() => {
|
||||
vi.restoreAllMocks()
|
||||
})
|
||||
|
||||
it('calls onChange with empty value for controlled input', () => {
|
||||
it("calls onChange with empty value for controlled input", () => {
|
||||
const onChange = vi.fn()
|
||||
const inputRef = {
|
||||
current: {
|
||||
value: 'test',
|
||||
value: "test",
|
||||
focus: vi.fn(),
|
||||
} as unknown as HTMLInputElement,
|
||||
}
|
||||
@@ -58,22 +58,22 @@ describe('clearInput', () => {
|
||||
clearInput({
|
||||
inputRef,
|
||||
onChange,
|
||||
value: 'test',
|
||||
value: "test",
|
||||
})
|
||||
|
||||
expect(onChange).toHaveBeenCalledWith(
|
||||
expect.objectContaining({
|
||||
target: { value: '' },
|
||||
target: { value: "" },
|
||||
})
|
||||
)
|
||||
expect(inputRef.current.focus).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('sets input value directly for uncontrolled input', () => {
|
||||
const input = document.createElement('input')
|
||||
input.value = 'test'
|
||||
const focusSpy = vi.spyOn(input, 'focus')
|
||||
const dispatchSpy = vi.spyOn(input, 'dispatchEvent')
|
||||
it("sets input value directly for uncontrolled input", () => {
|
||||
const input = document.createElement("input")
|
||||
input.value = "test"
|
||||
const focusSpy = vi.spyOn(input, "focus")
|
||||
const dispatchSpy = vi.spyOn(input, "dispatchEvent")
|
||||
|
||||
const inputRef = { current: input }
|
||||
|
||||
@@ -83,19 +83,19 @@ describe('clearInput', () => {
|
||||
value: undefined,
|
||||
})
|
||||
|
||||
expect(input.value).toBe('')
|
||||
expect(input.value).toBe("")
|
||||
expect(dispatchSpy).toHaveBeenCalled()
|
||||
expect(focusSpy).toHaveBeenCalled()
|
||||
})
|
||||
|
||||
it('does nothing when ref is null', () => {
|
||||
it("does nothing when ref is null", () => {
|
||||
const onChange = vi.fn()
|
||||
const inputRef = { current: null }
|
||||
|
||||
clearInput({
|
||||
inputRef,
|
||||
onChange,
|
||||
value: 'test',
|
||||
value: "test",
|
||||
})
|
||||
|
||||
expect(onChange).not.toHaveBeenCalled()
|
||||
|
||||
Reference in New Issue
Block a user