|
29 | 29 |
|
30 | 30 | import * as assert from 'node:assert'; |
31 | 31 | import * as vscode from 'vscode'; |
32 | | -import { createStatusBar, IdentityStatusBar } from '../../ui/identityStatusBar'; |
| 32 | +import { createStatusBar, IdentityStatusBar, buildMismatchTooltip } from '../../ui/identityStatusBar'; |
33 | 33 | import { Identity } from '../../identity/identity'; |
| 34 | +import type { SyncCheckResult } from '../../core/syncChecker'; |
34 | 35 |
|
35 | 36 | const EXTENSION_ID = 'nullvariant.git-id-switcher'; |
36 | 37 |
|
@@ -336,6 +337,174 @@ describe('StatusBar E2E Test Suite', function () { |
336 | 337 | }); |
337 | 338 | }); |
338 | 339 |
|
| 340 | + describe('State Transitions: setSyncState', () => { |
| 341 | + it('should set synced state without error', () => { |
| 342 | + statusBar = createStatusBar(); |
| 343 | + statusBar.setIdentity(TEST_IDENTITIES.basic); |
| 344 | + |
| 345 | + const syncResult: SyncCheckResult = { state: 'synced', mismatches: [] }; |
| 346 | + assert.doesNotThrow(() => { |
| 347 | + statusBar!.setSyncState(syncResult); |
| 348 | + }, 'setSyncState(synced) should not throw'); |
| 349 | + |
| 350 | + const syncState = statusBar.getSyncState(); |
| 351 | + assert.ok(syncState, 'Sync state should be set'); |
| 352 | + assert.strictEqual(syncState.state, 'synced'); |
| 353 | + }); |
| 354 | + |
| 355 | + it('should set out_of_sync state without error', () => { |
| 356 | + statusBar = createStatusBar(); |
| 357 | + statusBar.setIdentity(TEST_IDENTITIES.basic); |
| 358 | + |
| 359 | + const syncResult: SyncCheckResult = { |
| 360 | + state: 'out_of_sync', |
| 361 | + mismatches: [ |
| 362 | + { field: 'name', expected: 'Test User', actual: 'Wrong Name' }, |
| 363 | + ], |
| 364 | + }; |
| 365 | + |
| 366 | + assert.doesNotThrow(() => { |
| 367 | + statusBar!.setSyncState(syncResult); |
| 368 | + }, 'setSyncState(out_of_sync) should not throw'); |
| 369 | + |
| 370 | + const syncState = statusBar.getSyncState(); |
| 371 | + assert.ok(syncState, 'Sync state should be set'); |
| 372 | + assert.strictEqual(syncState.state, 'out_of_sync'); |
| 373 | + assert.strictEqual(syncState.mismatches.length, 1); |
| 374 | + }); |
| 375 | + |
| 376 | + it('should handle unknown state without changing display', () => { |
| 377 | + statusBar = createStatusBar(); |
| 378 | + statusBar.setIdentity(TEST_IDENTITIES.basic); |
| 379 | + |
| 380 | + const syncResult: SyncCheckResult = { state: 'unknown', mismatches: [] }; |
| 381 | + assert.doesNotThrow(() => { |
| 382 | + statusBar!.setSyncState(syncResult); |
| 383 | + }, 'setSyncState(unknown) should not throw'); |
| 384 | + |
| 385 | + // Identity should be preserved |
| 386 | + const currentIdentity = statusBar.getCurrentIdentity(); |
| 387 | + assert.ok(currentIdentity, 'Current identity should still be set'); |
| 388 | + assert.strictEqual(currentIdentity.id, 'test-basic'); |
| 389 | + }); |
| 390 | + |
| 391 | + it('should be no-op when no identity is set', () => { |
| 392 | + statusBar = createStatusBar(); |
| 393 | + |
| 394 | + // No identity set, setSyncState should not throw |
| 395 | + const syncResult: SyncCheckResult = { |
| 396 | + state: 'out_of_sync', |
| 397 | + mismatches: [ |
| 398 | + { field: 'email', expected: 'a@b.com', actual: 'c@d.com' }, |
| 399 | + ], |
| 400 | + }; |
| 401 | + |
| 402 | + assert.doesNotThrow(() => { |
| 403 | + statusBar!.setSyncState(syncResult); |
| 404 | + }, 'setSyncState without identity should not throw'); |
| 405 | + }); |
| 406 | + |
| 407 | + it('should clear sync state when setIdentity is called', () => { |
| 408 | + statusBar = createStatusBar(); |
| 409 | + statusBar.setIdentity(TEST_IDENTITIES.basic); |
| 410 | + |
| 411 | + // Set out_of_sync |
| 412 | + statusBar.setSyncState({ |
| 413 | + state: 'out_of_sync', |
| 414 | + mismatches: [{ field: 'name', expected: 'A', actual: 'B' }], |
| 415 | + }); |
| 416 | + assert.strictEqual(statusBar.getSyncState()?.state, 'out_of_sync'); |
| 417 | + |
| 418 | + // Set a new identity - should clear sync state |
| 419 | + statusBar.setIdentity(TEST_IDENTITIES.withIcon); |
| 420 | + assert.strictEqual(statusBar.getSyncState(), undefined, 'Sync state should be cleared after setIdentity'); |
| 421 | + }); |
| 422 | + |
| 423 | + it('should handle out_of_sync with multiple mismatches', () => { |
| 424 | + statusBar = createStatusBar(); |
| 425 | + statusBar.setIdentity(TEST_IDENTITIES.withAllFields); |
| 426 | + |
| 427 | + const syncResult: SyncCheckResult = { |
| 428 | + state: 'out_of_sync', |
| 429 | + mismatches: [ |
| 430 | + { field: 'name', expected: 'Full Test User', actual: 'Wrong Name' }, |
| 431 | + { field: 'email', expected: 'full@example.com', actual: 'wrong@example.com' }, |
| 432 | + { field: 'signingKey', expected: 'ABCD1234', actual: 'EFGH5678' }, |
| 433 | + ], |
| 434 | + }; |
| 435 | + |
| 436 | + assert.doesNotThrow(() => { |
| 437 | + statusBar!.setSyncState(syncResult); |
| 438 | + }, 'setSyncState with multiple mismatches should not throw'); |
| 439 | + |
| 440 | + assert.strictEqual(statusBar.getSyncState()?.mismatches.length, 3); |
| 441 | + }); |
| 442 | + |
| 443 | + it('should handle identity with icon in out_of_sync state', () => { |
| 444 | + statusBar = createStatusBar(); |
| 445 | + statusBar.setIdentity(TEST_IDENTITIES.withIcon); |
| 446 | + |
| 447 | + const syncResult: SyncCheckResult = { |
| 448 | + state: 'out_of_sync', |
| 449 | + mismatches: [ |
| 450 | + { field: 'email', expected: 'test@example.com', actual: 'other@example.com' }, |
| 451 | + ], |
| 452 | + }; |
| 453 | + |
| 454 | + assert.doesNotThrow(() => { |
| 455 | + statusBar!.setSyncState(syncResult); |
| 456 | + }, 'setSyncState with icon identity should not throw'); |
| 457 | + }); |
| 458 | + |
| 459 | + it('should restore normal display when transitioning from out_of_sync to synced', () => { |
| 460 | + statusBar = createStatusBar(); |
| 461 | + statusBar.setIdentity(TEST_IDENTITIES.basic); |
| 462 | + |
| 463 | + // First set out_of_sync |
| 464 | + statusBar.setSyncState({ |
| 465 | + state: 'out_of_sync', |
| 466 | + mismatches: [{ field: 'name', expected: 'A', actual: 'B' }], |
| 467 | + }); |
| 468 | + |
| 469 | + // Then set synced |
| 470 | + statusBar.setSyncState({ state: 'synced', mismatches: [] }); |
| 471 | + |
| 472 | + assert.strictEqual(statusBar.getSyncState()?.state, 'synced'); |
| 473 | + assert.ok(statusBar.getCurrentIdentity(), 'Identity should be preserved'); |
| 474 | + }); |
| 475 | + }); |
| 476 | + |
| 477 | + describe('buildMismatchTooltip', () => { |
| 478 | + it('should generate markdown with single mismatch', () => { |
| 479 | + const tooltip = buildMismatchTooltip([ |
| 480 | + { field: 'name', expected: 'John', actual: 'Jane' }, |
| 481 | + ]); |
| 482 | + |
| 483 | + assert.ok(tooltip.includes('name'), 'Should contain field name'); |
| 484 | + assert.ok(tooltip.includes('John'), 'Should contain expected value'); |
| 485 | + assert.ok(tooltip.includes('Jane'), 'Should contain actual value'); |
| 486 | + assert.ok(tooltip.includes('|'), 'Should contain table markers'); |
| 487 | + }); |
| 488 | + |
| 489 | + it('should generate markdown with multiple mismatches', () => { |
| 490 | + const tooltip = buildMismatchTooltip([ |
| 491 | + { field: 'name', expected: 'John', actual: 'Jane' }, |
| 492 | + { field: 'email', expected: 'j@a.com', actual: 'j@b.com' }, |
| 493 | + ]); |
| 494 | + |
| 495 | + assert.ok(tooltip.includes('name'), 'Should contain name field'); |
| 496 | + assert.ok(tooltip.includes('email'), 'Should contain email field'); |
| 497 | + }); |
| 498 | + |
| 499 | + it('should include signingKey field label', () => { |
| 500 | + const tooltip = buildMismatchTooltip([ |
| 501 | + { field: 'signingKey', expected: 'KEY1', actual: 'KEY2' }, |
| 502 | + ]); |
| 503 | + |
| 504 | + assert.ok(tooltip.includes('signingKey'), 'Should contain signingKey field'); |
| 505 | + }); |
| 506 | + }); |
| 507 | + |
339 | 508 | describe('Resource Management', () => { |
340 | 509 | it('should dispose without error', () => { |
341 | 510 | statusBar = createStatusBar(); |
|
0 commit comments