@@ -47,6 +47,16 @@ function changeInputValue(input: HTMLInputElement | HTMLSelectElement, value: st
4747 input . dispatchEvent ( new Event ( 'change' , { bubbles : true } ) )
4848}
4949
50+ function selectBorderStyle ( elem : HTMLElement , value : string ) {
51+ const trigger = elem . querySelector ( '.w-e-table-property-select-trigger' ) as HTMLButtonElement
52+ const option = elem . querySelector (
53+ `.w-e-table-property-select-option[data-value="${ value } "]`
54+ ) as HTMLButtonElement
55+
56+ trigger . click ( )
57+ option . click ( )
58+ }
59+
5060function createContextSelection ( editor , rows : number [ ] [ ] [ ] ) : NodeEntryWithContext [ ] [ ] {
5161 return rows . map ( row =>
5262 row . map ( path => [
@@ -76,15 +86,12 @@ describe('table property menus', () => {
7686 setSelectionInsideFirstCell ( editor )
7787
7888 const elem = menu . getModalContentElem ( editor ) as HTMLDivElement
79- const borderStyle = elem . querySelector ( '[name="borderStyle"]' ) as HTMLSelectElement
89+ const borderStyle = elem . querySelector ( '[name="borderStyle"]' ) as HTMLInputElement
8090 const borderWidth = elem . querySelector ( '[name="borderWidth"]' ) as HTMLInputElement
8191 const borderColorTrigger = elem . querySelector ( '[data-mark="color"]' ) as HTMLElement
8292 const backgroundColorTrigger = elem . querySelector ( '[data-mark="bgColor"]' ) as HTMLElement
83- const width = elem . querySelector ( '[name="width"]' ) as HTMLInputElement
84- const fullWidthButton = elem . querySelector (
85- '.w-e-table-property-segment-button[data-value="100%"]'
86- ) as HTMLButtonElement
8793 const textAlign = elem . querySelector ( '[name="textAlign"]' ) as HTMLInputElement | null
94+ const width = elem . querySelector ( '[name="width"]' ) as HTMLInputElement | null
8895 const button = elem . querySelector ( '.button-container button' ) as HTMLButtonElement
8996
9097 vi . spyOn ( editor , 'getMenuConfig' ) . mockImplementation ( ( mark : string ) => {
@@ -97,24 +104,23 @@ describe('table property menus', () => {
97104 return { } as any
98105 } )
99106
100- fullWidthButton . click ( )
101- changeInputValue ( borderStyle , 'dashed' )
107+ selectBorderStyle ( elem , 'dashed' )
102108 changeInputValue ( borderWidth , '2' )
103109 borderColorTrigger . click ( )
104110 ; ( borderColorTrigger . querySelector ( 'li[data-value="#ff0000"]' ) as HTMLElement ) . click ( )
105111 backgroundColorTrigger . click ( )
106112 ; ( backgroundColorTrigger . querySelector ( 'li[data-value="#00ff00"]' ) as HTMLElement ) . click ( )
107113
108114 expect ( textAlign ) . toBeNull ( )
109- expect ( width . value ) . toBe ( '100%' )
110- expect ( fullWidthButton . classList . contains ( 'active' ) ) . toBe ( true )
115+ expect ( width ) . toBeNull ( )
116+ expect ( borderStyle . value ) . toBe ( 'dashed' )
111117
112118 button . click ( )
113119 vi . runAllTimers ( )
114120
115121 const table = editor . children [ 0 ] as TableElement & Record < string , string >
116122
117- expect ( table . width ) . toBe ( '100% ' )
123+ expect ( table . width ) . toBe ( 'auto ' )
118124 expect ( table . borderStyle ) . toBe ( 'dashed' )
119125 expect ( table . borderColor ) . toBe ( '#ff0000' )
120126 expect ( table . borderWidth ) . toBe ( '2' )
@@ -123,6 +129,44 @@ describe('table property menus', () => {
123129 expect ( focusSpy ) . toHaveBeenCalled ( )
124130 } )
125131
132+ test ( 'TableProperty shows default border style and makes selected border color visible' , ( ) => {
133+ vi . useFakeTimers ( )
134+ const editor = createEditor ( { content : createTableContent ( ) } )
135+ const menu = new TableProperty ( )
136+
137+ setSelectionInsideFirstCell ( editor )
138+ vi . spyOn ( editor , 'getMenuConfig' ) . mockImplementation ( ( mark : string ) => {
139+ if ( mark === 'color' ) {
140+ return { colors : [ '#ff0000' ] } as any
141+ }
142+ return { } as any
143+ } )
144+
145+ const elem = menu . getModalContentElem ( editor ) as HTMLDivElement
146+ const borderStyle = elem . querySelector ( '[name="borderStyle"]' ) as HTMLInputElement
147+ const borderWidth = elem . querySelector ( '[name="borderWidth"]' ) as HTMLInputElement
148+ const borderColorTrigger = elem . querySelector ( '[data-mark="color"]' ) as HTMLElement
149+ const button = elem . querySelector ( '.button-container button' ) as HTMLButtonElement
150+
151+ expect ( borderStyle . value ) . toBe ( 'none' )
152+ expect ( borderWidth . placeholder ) . toBe ( '默认 1' )
153+
154+ borderColorTrigger . click ( )
155+ ; ( borderColorTrigger . querySelector ( 'li[data-value="#ff0000"]' ) as HTMLElement ) . click ( )
156+
157+ expect ( borderStyle . value ) . toBe ( 'solid' )
158+ expect ( borderWidth . value ) . toBe ( '1' )
159+
160+ button . click ( )
161+ vi . runAllTimers ( )
162+
163+ const table = editor . children [ 0 ] as TableElement & Record < string , string >
164+
165+ expect ( table . borderColor ) . toBe ( '#ff0000' )
166+ expect ( table . borderStyle ) . toBe ( 'solid' )
167+ expect ( table . borderWidth ) . toBe ( '1' )
168+ } )
169+
126170 test ( 'CellProperty applies properties to every selected cell in the batch selection' , ( ) => {
127171 vi . useFakeTimers ( )
128172 const editor = createEditor ( { content : createTableContent ( ) } )
@@ -145,7 +189,6 @@ describe('table property menus', () => {
145189 )
146190
147191 const elem = menu . getModalContentElem ( editor ) as HTMLDivElement
148- const borderStyle = elem . querySelector ( '[name="borderStyle"]' ) as HTMLSelectElement
149192 const textAlign = elem . querySelector ( '[name="textAlign"]' ) as HTMLInputElement
150193 const rightAlignButton = elem . querySelector (
151194 '.w-e-table-property-align-button[data-value="right"]'
@@ -164,7 +207,7 @@ describe('table property menus', () => {
164207 return { } as any
165208 } )
166209
167- changeInputValue ( borderStyle , 'solid' )
210+ selectBorderStyle ( elem , 'solid' )
168211 rightAlignButton . click ( )
169212 middleVerticalAlignButton . click ( )
170213 backgroundColorTrigger . click ( )
@@ -235,7 +278,7 @@ describe('table property menus', () => {
235278
236279 const elem = menu . getModalContentElem ( editor ) as HTMLDivElement
237280 const backgroundColor = elem . querySelector ( '[name="backgroundColor"]' ) as HTMLInputElement
238- const borderStyle = elem . querySelector ( '[name="borderStyle"]' ) as HTMLSelectElement
281+ const borderStyle = elem . querySelector ( '[name="borderStyle"]' ) as HTMLInputElement
239282 const rightAlignButton = elem . querySelector (
240283 '.w-e-table-property-align-button[data-value="right"]'
241284 ) as HTMLButtonElement
@@ -287,6 +330,8 @@ describe('table property menus', () => {
287330 colorOption . click ( )
288331
289332 expect ( borderColorInput . value ) . toBe ( '#00ff00' )
333+ expect ( ( elem . querySelector ( '[name="borderStyle"]' ) as HTMLInputElement ) . value ) . toBe ( 'solid' )
334+ expect ( ( elem . querySelector ( '[name="borderWidth"]' ) as HTMLInputElement ) . value ) . toBe ( '1' )
290335 expect (
291336 ( borderColorTrigger . querySelector ( '.color-group-block' ) as HTMLElement ) . style . backgroundColor
292337 ) . toContain ( '0, 255, 0' )
0 commit comments