@@ -3,66 +3,148 @@ import { $createMentionNode, $isMentionNode, MentionNode } from "./MentionNode"
33
44describe ( "MentionNode" , ( ) => {
55 it ( "should create a mention node with correct properties" , ( ) => {
6- const mentionNode = $createMentionNode ( "test-file.ts" , "@ " )
6+ const mentionNode = $createMentionNode ( "@" , " test-file.ts", "test-file.ts " )
77
88 expect ( $isMentionNode ( mentionNode ) ) . toBe ( true )
9- expect ( mentionNode . getMentionName ( ) ) . toBe ( "test-file.ts" )
9+ expect ( mentionNode . getValue ( ) ) . toBe ( "test-file.ts" )
10+ expect ( mentionNode . getLabel ( ) ) . toBe ( "test-file.ts" )
1011 expect ( mentionNode . getTrigger ( ) ) . toBe ( "@" )
1112 expect ( mentionNode . getTextContent ( ) ) . toBe ( "@test-file.ts" )
1213 } )
1314
1415 it ( "should create a command mention node" , ( ) => {
15- const mentionNode = $createMentionNode ( "code" , "/ " )
16+ const mentionNode = $createMentionNode ( "/" , " code", "code " )
1617
1718 expect ( $isMentionNode ( mentionNode ) ) . toBe ( true )
18- expect ( mentionNode . getMentionName ( ) ) . toBe ( "code" )
19+ expect ( mentionNode . getValue ( ) ) . toBe ( "code" )
20+ expect ( mentionNode . getLabel ( ) ) . toBe ( "code" )
1921 expect ( mentionNode . getTrigger ( ) ) . toBe ( "/" )
2022 expect ( mentionNode . getTextContent ( ) ) . toBe ( "/code" )
2123 } )
2224
2325 it ( "should serialize and deserialize correctly" , ( ) => {
24- const mentionNode = $createMentionNode ( "test-file.ts" , "@ " , undefined , { id : "123" } )
26+ const mentionNode = $createMentionNode ( "@" , " test-file.ts", "test-file.ts " , undefined , { id : "123" } )
2527 const serialized = mentionNode . exportJSON ( )
2628
27- expect ( serialized . mentionName ) . toBe ( "test-file.ts" )
29+ expect ( serialized . value ) . toBe ( "test-file.ts" )
30+ expect ( serialized . label ) . toBe ( "test-file.ts" )
2831 expect ( serialized . trigger ) . toBe ( "@" )
2932 expect ( serialized . data ) . toEqual ( { id : "123" } )
3033 expect ( serialized . type ) . toBe ( "mention" )
3134
3235 const deserialized = MentionNode . importJSON ( serialized )
33- expect ( deserialized . getMentionName ( ) ) . toBe ( "test-file.ts" )
36+ expect ( deserialized . getValue ( ) ) . toBe ( "test-file.ts" )
37+ expect ( deserialized . getLabel ( ) ) . toBe ( "test-file.ts" )
3438 expect ( deserialized . getTrigger ( ) ) . toBe ( "@" )
3539 expect ( deserialized . getData ( ) ) . toEqual ( { id : "123" } )
3640 } )
3741
3842 it ( "should clone correctly" , ( ) => {
39- const original = $createMentionNode ( "test-file.ts" , "@ " , undefined , { id : "123" } )
43+ const original = $createMentionNode ( "@" , " test-file.ts", "test-file.ts " , undefined , { id : "123" } )
4044 const cloned = MentionNode . clone ( original )
4145
42- expect ( cloned . getMentionName ( ) ) . toBe ( original . getMentionName ( ) )
46+ expect ( cloned . getValue ( ) ) . toBe ( original . getValue ( ) )
47+ expect ( cloned . getLabel ( ) ) . toBe ( original . getLabel ( ) )
4348 expect ( cloned . getTrigger ( ) ) . toBe ( original . getTrigger ( ) )
4449 expect ( cloned . getData ( ) ) . toEqual ( original . getData ( ) )
4550 expect ( cloned . getTextContent ( ) ) . toBe ( original . getTextContent ( ) )
4651 } )
4752
48- it ( "should update mention name correctly" , ( ) => {
49- const mentionNode = $createMentionNode ( "old-file.ts" , "@" )
50- const updated = mentionNode . setMentionName ( "new-file.ts" )
53+ it ( "should update value and label correctly" , ( ) => {
54+ const mentionNode = $createMentionNode ( "@" , "old-file.ts" , "old-file.ts" )
5155
52- expect ( updated . getMentionName ( ) ) . toBe ( "new-file.ts" )
53- expect ( updated . getTextContent ( ) ) . toBe ( "@new-file.ts" )
56+ const withNewValue = mentionNode . setValue ( "new-file.ts" )
57+ expect ( withNewValue . getValue ( ) ) . toBe ( "new-file.ts" )
58+
59+ const withNewLabel = withNewValue . setLabel ( "new-file.ts" )
60+ expect ( withNewLabel . getLabel ( ) ) . toBe ( "new-file.ts" )
61+ expect ( withNewLabel . getTextContent ( ) ) . toBe ( "@new-file.ts" )
5462 } )
5563
5664 it ( "should not allow text insertion before or after" , ( ) => {
57- const mentionNode = $createMentionNode ( "test-file.ts" , "@ " )
65+ const mentionNode = $createMentionNode ( "@" , " test-file.ts", "test-file.ts " )
5866
5967 expect ( mentionNode . canInsertTextBefore ( ) ) . toBe ( false )
6068 expect ( mentionNode . canInsertTextAfter ( ) ) . toBe ( false )
6169 } )
6270
6371 it ( "should be a text entity" , ( ) => {
64- const mentionNode = $createMentionNode ( "test-file.ts" , "@ " )
72+ const mentionNode = $createMentionNode ( "@" , " test-file.ts", "test-file.ts " )
6573
6674 expect ( mentionNode . isTextEntity ( ) ) . toBe ( true )
6775 } )
76+
77+ it ( "should support value and label" , ( ) => {
78+ const mentionNode = $createMentionNode ( "@" , "/path/to/filename.ts" , "filename.ts" , undefined , { type : "file" } )
79+
80+ expect ( mentionNode . getValue ( ) ) . toBe ( "/path/to/filename.ts" )
81+ expect ( mentionNode . getLabel ( ) ) . toBe ( "filename.ts" )
82+ } )
83+
84+ it ( "should format file mentions with @file: prefix" , ( ) => {
85+ const mentionNode = $createMentionNode ( "@" , "/path/to/file.ts" , "file.ts" , undefined , { type : "file" } )
86+
87+ expect ( mentionNode . getFormattedDisplayText ( ) ) . toBe ( "@file:file.ts" )
88+ } )
89+
90+ it ( "should format directory mentions with @dir: prefix" , ( ) => {
91+ const mentionNode = $createMentionNode ( "@" , "/path/to/dir/" , "/path/to/dir/" , undefined , { type : "folder" } )
92+
93+ expect ( mentionNode . getFormattedDisplayText ( ) ) . toBe ( "@dir:/path/to/dir/" )
94+ } )
95+
96+ it ( "should format git mentions with @git: prefix" , ( ) => {
97+ const mentionNode = $createMentionNode ( "@" , "abc123def456" , "abc123" , undefined , { type : "git" } )
98+
99+ expect ( mentionNode . getFormattedDisplayText ( ) ) . toBe ( "@git:abc123" )
100+ } )
101+
102+ it ( "should format url mentions with @url: prefix" , ( ) => {
103+ const mentionNode = $createMentionNode ( "@" , "https://example.com" , "example.com" , undefined , { type : "url" } )
104+
105+ expect ( mentionNode . getFormattedDisplayText ( ) ) . toBe ( "@url:example.com" )
106+ } )
107+
108+ it ( "should keep standard format for mentions without type" , ( ) => {
109+ const mentionNode = $createMentionNode ( "@" , "test-file.ts" , "test-file.ts" )
110+
111+ expect ( mentionNode . getFormattedDisplayText ( ) ) . toBe ( "@test-file.ts" )
112+ } )
113+
114+ it ( "should keep @ prefix for special mentions (problems, terminal)" , ( ) => {
115+ const problemsNode = $createMentionNode ( "@" , "problems" , "problems" , undefined , { type : "problems" } )
116+ const terminalNode = $createMentionNode ( "@" , "terminal" , "terminal" , undefined , { type : "terminal" } )
117+
118+ expect ( problemsNode . getFormattedDisplayText ( ) ) . toBe ( "@problems" )
119+ expect ( terminalNode . getFormattedDisplayText ( ) ) . toBe ( "@terminal" )
120+ } )
121+
122+ it ( "should serialize and deserialize with value and label" , ( ) => {
123+ const mentionNode = $createMentionNode ( "@" , "/path/to/filename.ts" , "filename.ts" , undefined , { type : "file" } )
124+ const serialized = mentionNode . exportJSON ( )
125+
126+ expect ( serialized . value ) . toBe ( "/path/to/filename.ts" )
127+ expect ( serialized . label ) . toBe ( "filename.ts" )
128+
129+ const deserialized = MentionNode . importJSON ( serialized )
130+ expect ( deserialized . getValue ( ) ) . toBe ( "/path/to/filename.ts" )
131+ expect ( deserialized . getLabel ( ) ) . toBe ( "filename.ts" )
132+ } )
133+
134+ it ( "should update value and label" , ( ) => {
135+ const mentionNode = $createMentionNode ( "@" , "file.ts" , "file.ts" )
136+
137+ const withValue = mentionNode . setValue ( "/path/to/file.ts" )
138+ expect ( withValue . getValue ( ) ) . toBe ( "/path/to/file.ts" )
139+
140+ const withLabel = withValue . setLabel ( "file.ts" )
141+ expect ( withLabel . getLabel ( ) ) . toBe ( "file.ts" )
142+ } )
143+
144+ it ( "should update display text when setting data with type" , ( ) => {
145+ const mentionNode = $createMentionNode ( "@" , "/path/to/file.ts" , "file.ts" )
146+
147+ const withType = mentionNode . setData ( { type : "file" } )
148+ expect ( withType . getFormattedDisplayText ( ) ) . toBe ( "@file:file.ts" )
149+ } )
68150} )
0 commit comments