admin/lib/isPlainPrimaryClick.test.ts
alisaza e1eaf5eff5 feat: initial ghabilee-admin backoffice app
Extract admin dashboard from ghabilee-frontend2 into a dedicated Next.js
app for backoffice.ghabilee.ir (no SEO indexing / Clarity).
2026-09-05 13:12:59 +03:30

30 lines
964 B
TypeScript

import { describe, expect, it } from 'vitest'
import { isPlainPrimaryClick } from '@/lib/isPlainPrimaryClick'
const click = (overrides: Partial<MouseEvent> = {}) =>
({
button: 0,
metaKey: false,
ctrlKey: false,
shiftKey: false,
altKey: false,
defaultPrevented: false,
...overrides,
}) as MouseEvent
describe('isPlainPrimaryClick', () => {
it('accepts a normal left click', () => {
expect(isPlainPrimaryClick(click())).toBe(true)
})
it('rejects modified or non-primary clicks', () => {
expect(isPlainPrimaryClick(click({ metaKey: true }))).toBe(false)
expect(isPlainPrimaryClick(click({ ctrlKey: true }))).toBe(false)
expect(isPlainPrimaryClick(click({ shiftKey: true }))).toBe(false)
expect(isPlainPrimaryClick(click({ altKey: true }))).toBe(false)
expect(isPlainPrimaryClick(click({ button: 1 }))).toBe(false)
expect(isPlainPrimaryClick(click({ defaultPrevented: true }))).toBe(false)
})
})