File size: 3,240 Bytes
1e92f2d
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
import { test, expect } from '@playwright/test'

test.describe('styling example', () => {
  test.beforeEach(
    async ({ page }) =>
      await page.goto('http://localhost:3000/examples/styling')
  )

  test('applies styles to editor from style prop', async ({ page }) => {
    page.waitForLoadState('domcontentloaded')

    const editor = page.locator('[data-slate-editor=true]').nth(0)
    const styles = await editor.evaluate(el => {
      const {
        backgroundColor,
        minHeight,
        outlineWidth,
        outlineStyle,
        outlineColor,
        position,
        whiteSpace,
        wordWrap,
      } = window.getComputedStyle(el)
      return {
        backgroundColor,
        minHeight,
        outlineWidth,
        outlineStyle,
        outlineColor,
        position,
        whiteSpace,
        wordWrap,
      }
    })

    // Provided styles
    expect(styles.backgroundColor).toBe('rgb(255, 230, 156)')
    expect(styles.minHeight).toBe('200px')
    expect(styles.outlineWidth).toBe('2px')
    expect(styles.outlineStyle).toBe('solid')
    expect(styles.outlineColor).toBe('rgb(0, 128, 0)')

    // Default styles
    expect(styles.position).toBe('relative')
    expect(styles.whiteSpace).toBe('pre-wrap')
    expect(styles.wordWrap).toBe('break-word')
  })

  test('applies styles to editor from className prop', async ({ page }) => {
    page.waitForLoadState('domcontentloaded')

    const editor = page.locator('[data-slate-editor=true]').nth(1)
    const styles = await editor.evaluate(el => {
      const {
        backgroundColor,
        paddingTop,
        paddingRight,
        paddingBottom,
        paddingLeft,
        fontSize,
        minHeight,
        outlineWidth,
        outlineStyle,
        outlineColor,
        borderTopLeftRadius,
        borderTopRightRadius,
        borderBottomRightRadius,
        borderBottomLeftRadius,
        outlineOffset,
        position,
        whiteSpace,
        wordWrap,
      } = window.getComputedStyle(el)
      return {
        backgroundColor,
        paddingTop,
        paddingRight,
        paddingBottom,
        paddingLeft,
        fontSize,
        minHeight,
        outlineWidth,
        outlineStyle,
        outlineColor,
        borderTopLeftRadius,
        borderTopRightRadius,
        borderBottomRightRadius,
        borderBottomLeftRadius,
        outlineOffset,
        position,
        whiteSpace,
        wordWrap,
      }
    })

    expect(styles.backgroundColor).toBe('rgb(218, 225, 255)')
    expect(styles.paddingTop).toBe('40px')
    expect(styles.paddingRight).toBe('40px')
    expect(styles.paddingBottom).toBe('40px')
    expect(styles.paddingLeft).toBe('40px')
    expect(styles.fontSize).toBe('20px')
    expect(styles.minHeight).toBe('150px')
    expect(styles.borderBottomLeftRadius).toBe('20px')
    expect(styles.borderBottomRightRadius).toBe('20px')
    expect(styles.borderTopLeftRadius).toBe('20px')
    expect(styles.borderTopRightRadius).toBe('20px')
    expect(styles.outlineOffset).toBe('-20px')
    expect(styles.outlineWidth).toBe('3px')
    expect(styles.outlineStyle).toBe('dashed')
    expect(styles.outlineColor).toBe('rgb(0, 94, 128)')
    expect(styles.whiteSpace).toBe('pre-wrap')
  })
})