11import { NodeCore } from "@/entities/nodes/types" ;
2- import { describe , expect , it } from "vitest" ;
2+ import { getSchema } from "@/entities/schema/domain/get-schema" ;
3+ import { describe , expect , it , vi } from "vitest" ;
34import { generateNodeSchema } from "../../../../../tests/fake/schema" ;
45import { getNodeLabel } from "./get-node-label" ;
56
7+ vi . mock ( "@/entities/schema/domain/get-schema" , ( ) => ( {
8+ getSchema : vi . fn ( ( ) => ( {
9+ schema : generateNodeSchema ( ) ,
10+ isGeneric : false ,
11+ isNode : true ,
12+ isProfile : false ,
13+ } ) ) ,
14+ } ) ) ;
15+
616describe ( "getNodeLabel" , ( ) => {
7- const baseSchema = generateNodeSchema ( ) ;
817 const baseNode : NodeCore = {
918 id : "test-id" ,
1019 hfid : null ,
@@ -14,78 +23,74 @@ describe("getNodeLabel", () => {
1423
1524 it ( "should join multiple hfids with comma when node has hfid array" , ( ) => {
1625 // GIVEN
17- const node = { ...baseNode , hfid : [ "hfid-1" , "hfid-2" ] } ;
18- const schema = baseSchema ;
26+ const node : NodeCore = { ...baseNode , hfid : [ "hfid-1" , "hfid-2" ] } ;
1927
2028 // WHEN
21- const result = getNodeLabel ( { node, schema } ) ;
29+ const result = getNodeLabel ( node ) ;
2230
2331 // THEN
2432 expect ( result ) . toBe ( "hfid-1, hfid-2" ) ;
2533 } ) ;
2634
2735 it ( "should use display_label when hfid is not present" , ( ) => {
2836 // GIVEN
29- const node = { ...baseNode , display_label : "Display Label" } ;
30- const schema = baseSchema ;
37+ const node : NodeCore = { ...baseNode , display_label : "Display Label" } ;
3138
3239 // WHEN
33- const result = getNodeLabel ( { node, schema } ) ;
40+ const result = getNodeLabel ( node ) ;
3441
3542 // THEN
3643 expect ( result ) . toBe ( "Display Label" ) ;
3744 } ) ;
3845
3946 it ( "should fallback to node.id when neither hfid nor display_label are present" , ( ) => {
4047 // WHEN
41- const result = getNodeLabel ( { node : baseNode , schema : baseSchema } ) ;
48+ const result = getNodeLabel ( baseNode ) ;
4249
4350 // THEN
4451 expect ( result ) . toBe ( "test-id" ) ;
4552 } ) ;
4653
4754 it ( "should prefer hfid over display_label when both are available" , ( ) => {
4855 // GIVEN
49- const node = {
56+ const node : NodeCore = {
5057 ...baseNode ,
5158 hfid : [ "hfid-1" ] ,
5259 display_label : "Display Label" ,
5360 } ;
54- const schema = baseSchema ;
5561
5662 // WHEN
57- const result = getNodeLabel ( { node, schema } ) ;
63+ const result = getNodeLabel ( node ) ;
5864
5965 // THEN
6066 expect ( result ) . toBe ( "hfid-1" ) ;
6167 } ) ;
6268
63- it ( "should fallback to node.id when schema allows special labels but node values are null" , ( ) => {
64- // GIVEN
65- const schema = baseSchema ;
66-
69+ it ( "should fallback to node.id when special labels are null" , ( ) => {
6770 // WHEN
68- const result = getNodeLabel ( { node : baseNode , schema } ) ;
71+ const result = getNodeLabel ( baseNode ) ;
6972
7073 // THEN
7174 expect ( result ) . toBe ( "test-id" ) ;
7275 } ) ;
7376
74- it ( "should use node.id when schema disables special labels even if node has them " , ( ) => {
77+ it ( "should use node.id when schema is not found even if node has special labels " , ( ) => {
7578 // GIVEN
76- const node = {
79+ vi . mocked ( getSchema ) . mockReturnValueOnce ( {
80+ schema : null ,
81+ isGeneric : false ,
82+ isNode : false ,
83+ isProfile : false ,
84+ } ) ;
85+ const node : NodeCore = {
7786 ...baseNode ,
7887 hfid : [ "hfid-1" ] ,
7988 display_label : "Display Label" ,
80- } ;
81- const schema = {
82- ...baseSchema ,
83- human_friendly_id : null ,
84- display_labels : null ,
89+ __typename : "UnknownType" ,
8590 } ;
8691
8792 // WHEN
88- const result = getNodeLabel ( { node, schema : schema } ) ;
93+ const result = getNodeLabel ( node ) ;
8994
9095 // THEN
9196 expect ( result ) . toBe ( "test-id" ) ;
0 commit comments