@@ -6,12 +6,25 @@ import DisplayNote from "./DisplayNote.vue";
66import { useNoteModel } from "./note-model" ;
77import { addNoteToPage , createPageYDoc } from "@deepnotes/collab-wire" ;
88
9- function createNoteModel ( ydoc : Y . Doc , id : string , opts ?: { containerEnabled ?: boolean } ) {
9+ function createNoteModel (
10+ ydoc : Y . Doc ,
11+ id : string ,
12+ opts ?: { containerEnabled ?: boolean ; collapsingEnabled ?: boolean ; colorInherit ?: boolean ; colorValue ?: string } ,
13+ ) {
1014 const noteMap = addNoteToPage ( ydoc , id ) ;
1115 if ( opts ?. containerEnabled ) {
1216 const containerMap = noteMap . get ( "container" ) as Y . Map < unknown > ;
1317 containerMap . set ( "enabled" , true ) ;
1418 }
19+ if ( opts ?. collapsingEnabled ) {
20+ const collapsingMap = noteMap . get ( "collapsing" ) as Y . Map < boolean > ;
21+ collapsingMap . set ( "enabled" , true ) ;
22+ }
23+ if ( opts ?. colorInherit !== undefined || opts ?. colorValue !== undefined ) {
24+ const colorMap = noteMap . get ( "color" ) as Y . Map < unknown > ;
25+ if ( opts . colorInherit !== undefined ) colorMap . set ( "inherit" , opts . colorInherit ) ;
26+ if ( opts . colorValue !== undefined ) colorMap . set ( "value" , opts . colorValue ) ;
27+ }
1528 return useNoteModel ( noteMap ) ;
1629}
1730
@@ -21,7 +34,7 @@ describe("DisplayNote", () => {
2134 const model = createNoteModel ( ydoc , "note-1" ) ;
2235
2336 const wrapper = mount ( DisplayNote , {
24- props : { model, zoom : 1 } ,
37+ props : { id : "note-1" , model, zoom : 1 } ,
2538 } ) ;
2639
2740 expect ( wrapper . findAll ( '[data-testid="display-note"]' ) ) . toHaveLength ( 1 ) ;
@@ -33,7 +46,12 @@ describe("DisplayNote", () => {
3346 const childModel = createNoteModel ( ydoc , "child-1" ) ;
3447
3548 const wrapper = mount ( DisplayNote , {
36- props : { model : parentModel , zoom : 1 , childModels : [ childModel ] } ,
49+ props : {
50+ id : "parent" ,
51+ model : parentModel ,
52+ zoom : 1 ,
53+ childModels : [ { id : "child-1" , model : childModel } ] ,
54+ } ,
3755 } ) ;
3856
3957 const notes = wrapper . findAll ( '[data-testid="display-note"]' ) ;
@@ -46,9 +64,62 @@ describe("DisplayNote", () => {
4664 const childModel = createNoteModel ( ydoc , "child-1" ) ;
4765
4866 const wrapper = mount ( DisplayNote , {
49- props : { model : parentModel , zoom : 1 , childModels : [ childModel ] } ,
67+ props : {
68+ id : "parent" ,
69+ model : parentModel ,
70+ zoom : 1 ,
71+ childModels : [ { id : "child-1" , model : childModel } ] ,
72+ } ,
5073 } ) ;
5174
5275 expect ( wrapper . findAll ( '[data-testid="display-note"]' ) ) . toHaveLength ( 1 ) ;
5376 } ) ;
77+
78+ it ( "shows collapse button when collapsing is enabled" , ( ) => {
79+ const ydoc = createPageYDoc ( ) ;
80+ const model = createNoteModel ( ydoc , "note-1" , { collapsingEnabled : true } ) ;
81+
82+ const wrapper = mount ( DisplayNote , {
83+ props : { id : "note-1" , model, zoom : 1 } ,
84+ } ) ;
85+
86+ expect ( wrapper . find ( "button" ) . exists ( ) ) . toBe ( true ) ;
87+ } ) ;
88+
89+ it ( "hides collapse button when collapsing is disabled" , ( ) => {
90+ const ydoc = createPageYDoc ( ) ;
91+ const model = createNoteModel ( ydoc , "note-1" ) ;
92+
93+ const wrapper = mount ( DisplayNote , {
94+ props : { id : "note-1" , model, zoom : 1 } ,
95+ } ) ;
96+
97+ expect ( wrapper . find ( "button" ) . exists ( ) ) . toBe ( false ) ;
98+ } ) ;
99+
100+ it ( "inherits parent color when color.inherit is true" , ( ) => {
101+ const ydoc = createPageYDoc ( ) ;
102+ const model = createNoteModel ( ydoc , "note-1" , { colorInherit : true } ) ;
103+
104+ const wrapper = mount ( DisplayNote , {
105+ props : { id : "note-1" , model, zoom : 1 , parentColor : "#ef4444" } ,
106+ } ) ;
107+
108+ const el = wrapper . find ( '[data-testid="display-note"]' ) ;
109+ const style = el . attributes ( "style" ) ;
110+ expect ( style ) . toContain ( "border-color: #ef4444" ) ;
111+ } ) ;
112+
113+ it ( "uses own color when color.inherit is false" , ( ) => {
114+ const ydoc = createPageYDoc ( ) ;
115+ const model = createNoteModel ( ydoc , "note-1" , { colorInherit : false , colorValue : "blue" } ) ;
116+
117+ const wrapper = mount ( DisplayNote , {
118+ props : { id : "note-1" , model, zoom : 1 , parentColor : "#ef4444" } ,
119+ } ) ;
120+
121+ const el = wrapper . find ( '[data-testid="display-note"]' ) ;
122+ const style = el . attributes ( "style" ) ;
123+ expect ( style ) . toContain ( "border-color: #3b82f6" ) ;
124+ } ) ;
54125} ) ;
0 commit comments