Skip to content

Commit d935b09

Browse files
committed
test(tests): add tests for layout and style 🍝
- Add Render.applyLayout test for display, flex, min/max size, overflow - Add Render.applyStyle test for textAlign, cursor, visibility, zIndex and typography - Add Validator.validateNode test for new layout and style keys
1 parent 115c9f0 commit d935b09

File tree

2 files changed

+71
-0
lines changed

2 files changed

+71
-0
lines changed

tests/Render.test.ts

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,37 @@ Deno.test('Render.applyLayout sets position relative when x or y present', () =>
282282
assertEquals(style['top'], '20px')
283283
})
284284

285+
Deno.test('Render.applyLayout sets display flex alignItems justifyContent minWidth overflow', () => {
286+
const style: Record<string, string> = {}
287+
const element = { style } as unknown as HTMLElement
288+
Render.applyLayout(element, {
289+
display: 'flex',
290+
flexDirection: 'column',
291+
flexWrap: 'wrap',
292+
alignItems: 'center',
293+
justifyContent: 'space-between',
294+
minWidth: 200,
295+
maxWidth: '100%',
296+
minHeight: 100,
297+
maxHeight: '80vh',
298+
overflow: 'auto',
299+
overflowX: 'hidden',
300+
overflowY: 'scroll'
301+
})
302+
assertEquals(style['display'], 'flex')
303+
assertEquals(style['flexDirection'], 'column')
304+
assertEquals(style['flexWrap'], 'wrap')
305+
assertEquals(style['alignItems'], 'center')
306+
assertEquals(style['justifyContent'], 'space-between')
307+
assertEquals(style['minWidth'], '200px')
308+
assertEquals(style['maxWidth'], '100%')
309+
assertEquals(style['minHeight'], '100px')
310+
assertEquals(style['maxHeight'], '80vh')
311+
assertEquals(style['overflow'], 'auto')
312+
assertEquals(style['overflowX'], 'hidden')
313+
assertEquals(style['overflowY'], 'scroll')
314+
})
315+
285316
Deno.test('Render.applyStyle applies expanded style properties', () => {
286317
const style: Record<string, string> = {}
287318
const element = { style } as unknown as HTMLElement
@@ -317,6 +348,31 @@ Deno.test('Render.applyStyle applies fill stroke font border', () => {
317348
assertEquals(style['font'], '16px sans-serif')
318349
})
319350

351+
Deno.test('Render.applyStyle applies textAlign cursor visibility zIndex', () => {
352+
const style: Record<string, string> = {}
353+
const element = { style } as unknown as HTMLElement
354+
Render.applyStyle(element, {
355+
textAlign: 'center',
356+
textDecoration: 'underline',
357+
letterSpacing: '0.5px',
358+
lineHeight: '1.5',
359+
cursor: 'pointer',
360+
visibility: 'visible',
361+
background: 'linear-gradient(#333, #111)',
362+
outline: '1px solid blue',
363+
zIndex: '10'
364+
})
365+
assertEquals(style['textAlign'], 'center')
366+
assertEquals(style['textDecoration'], 'underline')
367+
assertEquals(style['letterSpacing'], '0.5px')
368+
assertEquals(style['lineHeight'], '1.5')
369+
assertEquals(style['cursor'], 'pointer')
370+
assertEquals(style['visibility'], 'visible')
371+
assertEquals(style['background'], 'linear-gradient(#333, #111)')
372+
assertEquals(style['outline'], '1px solid blue')
373+
assertEquals(style['zIndex'], '10')
374+
})
375+
320376
Deno.test('Render.applyStyleString parses declarations and calls setProperty', () => {
321377
const recordedSetPropertyCalls: [string, string][] = []
322378
const targetStyle = {

tests/Validator.test.ts

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,21 @@ Deno.test('Validator.validateNode copies id layout style attrs content src alt',
125125
assertEquals(validatedNode.alt, 'image')
126126
})
127127

128+
Deno.test('Validator.validateNode accepts layout with display flex and style with textAlign', () => {
129+
const validatedNode = Validator.validateNode(
130+
{
131+
type: 'div',
132+
layout: { display: 'flex', alignItems: 'center', justifyContent: 'space-between' },
133+
style: { textAlign: 'center', cursor: 'pointer' }
134+
},
135+
'root[0]'
136+
)
137+
assertEquals(validatedNode.layout?.display, 'flex')
138+
assertEquals(validatedNode.layout?.alignItems, 'center')
139+
assertEquals(validatedNode.style?.textAlign, 'center')
140+
assertEquals(validatedNode.style?.cursor, 'pointer')
141+
})
142+
128143
Deno.test('Validator.validateNode normalises type to lowercase', () => {
129144
const validatedNode = Validator.validateNode({ type: 'DIV' }, 'root[0]')
130145
assertEquals(validatedNode.type, 'div')

0 commit comments

Comments
 (0)