feat: 重建 Sense 区域与警戒线配置 (#69)
This commit is contained in:
@@ -0,0 +1,25 @@
|
||||
import GeometryEditor from '@/components/sense/geometry-editor/index.vue'
|
||||
|
||||
describe('Sense geometry editor keyboard operations', () => {
|
||||
it('adds, moves and removes a point without a mouse', () => {
|
||||
const context = {
|
||||
disabled: false,
|
||||
kind: 'polygon',
|
||||
points: [],
|
||||
undoStack: [],
|
||||
canAdd: true,
|
||||
$emit(event, points) { this.points = points }
|
||||
}
|
||||
context.commit = GeometryEditor.methods.commit.bind(context)
|
||||
GeometryEditor.methods.addCenterPoint.call(context)
|
||||
expect(context.points).toEqual([{ x: 0.5, y: 0.5 }])
|
||||
|
||||
const moveEvent = { key: 'ArrowRight', preventDefault: jest.fn() }
|
||||
GeometryEditor.methods.movePointByKeyboard.call(context, 0, moveEvent)
|
||||
expect(context.points[0].x).toBeCloseTo(0.51)
|
||||
expect(moveEvent.preventDefault).toHaveBeenCalled()
|
||||
|
||||
GeometryEditor.methods.movePointByKeyboard.call(context, 0, { key: 'Delete', preventDefault: jest.fn() })
|
||||
expect(context.points).toEqual([])
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,16 @@
|
||||
import { DIRECTION_LINE, POLYGON, clamp, geometryError } from '@/components/sense/geometry-editor/geometry'
|
||||
|
||||
describe('Sense area geometry', () => {
|
||||
it('validates polygon and direction-line constraints', () => {
|
||||
expect(geometryError(POLYGON, [{ x: 0.1, y: 0.1 }, { x: 0.8, y: 0.1 }, { x: 0.5, y: 0.8 }])).toBe('')
|
||||
expect(geometryError(POLYGON, [{ x: 0.1, y: 0.1 }, { x: 0.8, y: 0.8 }, { x: 0.8, y: 0.1 }, { x: 0.1, y: 0.8 }])).toContain('不能交叉')
|
||||
expect(geometryError(DIRECTION_LINE, [{ x: 0.2, y: 0.5 }, { x: 0.8, y: 0.5 }], 'forward')).toBe('')
|
||||
expect(geometryError(DIRECTION_LINE, [{ x: 0.2, y: 0.5 }], 'forward')).toContain('恰好 2 个点')
|
||||
})
|
||||
|
||||
it('clamps pointer coordinates to the normalized frame', () => {
|
||||
expect(clamp(-0.2)).toBe(0)
|
||||
expect(clamp(0.4)).toBe(0.4)
|
||||
expect(clamp(1.2)).toBe(1)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,13 @@
|
||||
import { buildAreaPayload, validateAreaForm } from '@/views/sense/area/areaPayload'
|
||||
|
||||
describe('Sense area payload', () => {
|
||||
it('keeps the optimistic version and normalized geometry', () => {
|
||||
const form = { name: ' 东门警戒线 ', kind: 'direction_line', routeId: 'device-1:main', points: [{ x: '0.2', y: '0.5' }, { x: '0.8', y: '0.5' }], direction: 'reverse', enabled: true, version: 4 }
|
||||
expect(validateAreaForm(form)).toBe('')
|
||||
expect(buildAreaPayload(form)).toEqual({ name: '东门警戒线', kind: 'direction_line', routeId: 'device-1:main', points: [{ x: 0.2, y: 0.5 }, { x: 0.8, y: 0.5 }], direction: 'reverse', enabled: true, expectedVersion: 4 })
|
||||
})
|
||||
|
||||
it('rejects incomplete geometry before sending', () => {
|
||||
expect(validateAreaForm({ name: '危险区域', kind: 'polygon', routeId: 'route-1', points: [] })).toContain('3 到 64')
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user