|
1 | 1 | import { beforeEach, expect, test, vi } from 'vitest' |
2 | | -import { ref } from 'vue' |
| 2 | +import { computed, ref } from 'vue' |
3 | 3 | import { INSPECTOR_ID } from './constants' |
4 | 4 | import { |
| 5 | + handleEditInspectorState, |
5 | 6 | handleGetInspectorState, |
6 | 7 | handleGetInspectorTree, |
7 | 8 | handleInspectComponent, |
@@ -169,7 +170,23 @@ test('getInspectorState for individual entry', () => { |
169 | 170 | { |
170 | 171 | "editable": true, |
171 | 172 | "key": "foo", |
172 | | - "value": "bar", |
| 173 | + "value": RefImpl { |
| 174 | + "__v_isRef": true, |
| 175 | + "__v_isShallow": false, |
| 176 | + "_rawValue": "bar", |
| 177 | + "_value": "bar", |
| 178 | + "dep": Dep { |
| 179 | + "__v_skip": true, |
| 180 | + "activeLink": undefined, |
| 181 | + "computed": undefined, |
| 182 | + "key": undefined, |
| 183 | + "map": undefined, |
| 184 | + "sc": 0, |
| 185 | + "subs": undefined, |
| 186 | + "subsHead": undefined, |
| 187 | + "version": 0, |
| 188 | + }, |
| 189 | + }, |
173 | 190 | }, |
174 | 191 | ], |
175 | 192 | } |
@@ -264,3 +281,68 @@ test('inspectComponent adds state to payload', () => { |
264 | 281 | ] |
265 | 282 | `) |
266 | 283 | }) |
| 284 | + |
| 285 | +test('editInspectorState for existent entry', () => { |
| 286 | + const debugState = { value: computed(() => 23) } |
| 287 | + upsert({ |
| 288 | + groupId: 'groupid', |
| 289 | + uid: 'uid', |
| 290 | + componentName: 'Foo', |
| 291 | + componentInstance: null, |
| 292 | + debugState, |
| 293 | + }) |
| 294 | + |
| 295 | + const setMock = vi.fn() |
| 296 | + |
| 297 | + const payload: DevtoolsApiHandlerPayload<'editInspectorState'> = |
| 298 | + { |
| 299 | + app: {}, |
| 300 | + inspectorId: INSPECTOR_ID, |
| 301 | + nodeId: 'uid', |
| 302 | + path: [], |
| 303 | + type: '', |
| 304 | + state: { |
| 305 | + value: 'yess', |
| 306 | + newKey: undefined, |
| 307 | + remove: undefined, |
| 308 | + }, |
| 309 | + set: setMock, |
| 310 | + } |
| 311 | + |
| 312 | + handleEditInspectorState(payload) |
| 313 | + |
| 314 | + expect(setMock).toHaveBeenCalledExactlyOnceWith( |
| 315 | + debugState, |
| 316 | + ) |
| 317 | +}) |
| 318 | + |
| 319 | +test('editInspectorState for non-existent entry', () => { |
| 320 | + upsert({ |
| 321 | + groupId: 'groupid', |
| 322 | + uid: 'uid', |
| 323 | + componentName: 'Foo', |
| 324 | + componentInstance: null, |
| 325 | + debugState: { value: computed(() => 23) }, |
| 326 | + }) |
| 327 | + |
| 328 | + const setMock = vi.fn() |
| 329 | + |
| 330 | + const payload: DevtoolsApiHandlerPayload<'editInspectorState'> = |
| 331 | + { |
| 332 | + app: {}, |
| 333 | + inspectorId: INSPECTOR_ID, |
| 334 | + nodeId: 'rando', |
| 335 | + path: [], |
| 336 | + type: '', |
| 337 | + state: { |
| 338 | + value: 'yess', |
| 339 | + newKey: undefined, |
| 340 | + remove: undefined, |
| 341 | + }, |
| 342 | + set: setMock, |
| 343 | + } |
| 344 | + |
| 345 | + handleEditInspectorState(payload) |
| 346 | + |
| 347 | + expect(setMock).not.toHaveBeenCalled() |
| 348 | +}) |
0 commit comments