11import { beforeEach , describe , expect , it } from 'vitest'
2- import { handleCommentEvent , states } from '../src/entrypoints/background'
2+ import { handleCommentEvent , openSpots } from '../src/entrypoints/background'
33import type { CommentEvent , CommentSpot } from '../src/lib/enhancer'
44
55const mockSender = {
@@ -14,7 +14,7 @@ const mockSpot = {
1414}
1515describe ( 'Background Event Handler' , ( ) => {
1616 beforeEach ( ( ) => {
17- states . clear ( )
17+ openSpots . clear ( )
1818 } )
1919 describe ( 'ENHANCED Event' , ( ) => {
2020 it ( 'should create new comment state when textarea is enhanced' , ( ) => {
@@ -25,7 +25,7 @@ describe('Background Event Handler', () => {
2525 } ,
2626 mockSender ,
2727 )
28- expect ( Array . from ( states ) ) . toMatchInlineSnapshot ( `
28+ expect ( Array . from ( openSpots ) ) . toMatchInlineSnapshot ( `
2929 [
3030 [
3131 "{"spot":{"type":"TEST_SPOT","unique_key":"test-key"},"tab":{"tabId":123,"windowId":456}}",
@@ -53,7 +53,7 @@ describe('Background Event Handler', () => {
5353 } ,
5454 senderWithoutTab ,
5555 )
56- expect ( states . size ) . toBe ( 0 )
56+ expect ( openSpots . size ) . toBe ( 0 )
5757 } )
5858 } )
5959
@@ -65,15 +65,15 @@ describe('Background Event Handler', () => {
6565 type : 'ENHANCED' ,
6666 }
6767 handleCommentEvent ( enhanceMessage , mockSender )
68- expect ( states . size ) . toBe ( 1 )
68+ expect ( openSpots . size ) . toBe ( 1 )
6969
7070 // Then destroy it
7171 const destroyMessage : CommentEvent = {
7272 spot : mockSpot ,
7373 type : 'DESTROYED' ,
7474 }
7575 handleCommentEvent ( destroyMessage , mockSender )
76- expect ( states . size ) . toBe ( 0 )
76+ expect ( openSpots . size ) . toBe ( 0 )
7777 } )
7878
7979 it ( 'should handle DESTROYED event for non-existent state gracefully' , ( ) => {
@@ -83,7 +83,7 @@ describe('Background Event Handler', () => {
8383 }
8484 // Should not throw error
8585 handleCommentEvent ( message , mockSender )
86- expect ( states . size ) . toBe ( 0 )
86+ expect ( openSpots . size ) . toBe ( 0 )
8787 } )
8888 } )
8989
@@ -94,7 +94,7 @@ describe('Background Event Handler', () => {
9494 type : 'LOST_FOCUS' ,
9595 }
9696 handleCommentEvent ( message , mockSender )
97- expect ( states . size ) . toBe ( 0 )
97+ expect ( openSpots . size ) . toBe ( 0 )
9898 } )
9999 } )
100100
@@ -106,7 +106,7 @@ describe('Background Event Handler', () => {
106106 const sender2 = { tab : { id : 789 , windowId : 456 } }
107107 handleCommentEvent ( { spot : spot1 , type : 'ENHANCED' } , sender1 )
108108 handleCommentEvent ( { spot : spot2 , type : 'ENHANCED' } , sender2 )
109- expect ( states . size ) . toBe ( 2 )
109+ expect ( openSpots . size ) . toBe ( 2 )
110110 } )
111111
112112 it ( 'should handle same spot from same tab (overwrite)' , ( ) => {
@@ -120,7 +120,7 @@ describe('Background Event Handler', () => {
120120 handleCommentEvent ( message , mockSender )
121121
122122 // Should still be 1 entry (overwritten)
123- expect ( states . size ) . toBe ( 1 )
123+ expect ( openSpots . size ) . toBe ( 1 )
124124 } )
125125 } )
126126} )
0 commit comments