Skip to content

Commit 8f8b957

Browse files
authored
Reintroduce manual Android tests (#5884)
* Re-add manual Android tests * Remove trailing slash * Disable autofocus
1 parent de26056 commit 8f8b957

File tree

6 files changed

+519
-19
lines changed

6 files changed

+519
-19
lines changed

docs/general/contributing.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ To run integrations with [Playwright](https://playwright.dev/), first run `yarn
101101

102102
[Here's a helpful page](https://github.com/Microsoft/vscode/wiki/IME-Test) detailing how to test various input scenarios on Windows, Mac and Linux.
103103

104+
## Android tests
105+
106+
When making changes that might affect Android compatibility, you can perform the manual Android tests at [/examples/android-tests](https://slatejs.org/examples/android-tests).
107+
104108
## Publishing Releases
105109

106110
**Important**: When creating releases using Lerna with the instructions below, you will be given choices around how to increase version numbers. You should always use a `major`, `minor` or `patch` release and must never use a `prerelease`. If a prerelease is used, the root package will not link to the packages in the `packages` directory creating hard to diagnose issues.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
"build:rollup": "rollup --config ./config/rollup/rollup.config.js --bundleConfigAsCjs",
1111
"changesetversion": "yarn changeset version && yarn install && git add .",
1212
"clean": "rimraf './packages/*/{dist,lib,node_modules}' './site/{.next,out}' --glob",
13-
"fix": "yarn fix:prettier && yarn fix:eslint",
13+
"fix": "yarn tsc:examples && yarn fix:prettier && yarn fix:eslint",
1414
"fix:eslint": "yarn lint:eslint --fix",
1515
"fix:prettier": "yarn lint:prettier --write",
1616
"lint": "yarn lint:typescript && yarn lint:eslint && yarn lint:prettier",

site/examples/js/android-tests.jsx

Lines changed: 234 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,234 @@
1+
import React, { useCallback, useEffect, useMemo, useState } from 'react'
2+
import { createEditor } from 'slate'
3+
import { withHistory } from 'slate-history'
4+
import { Editable, Slate, withReact } from 'slate-react'
5+
import { css } from '@emotion/css'
6+
7+
const TEST_CASES = [
8+
{
9+
id: 'split-join',
10+
name: 'Split/Join',
11+
instructions:
12+
'Hit enter twice then backspace twice in the following places:\n- Before "before"\n- Between the two "d"s in "middle"\n- After "after"',
13+
value: [
14+
{
15+
type: 'paragraph',
16+
children: [
17+
{ text: 'One ' },
18+
{ text: 'before', bold: true },
19+
{ text: ' two ' },
20+
{ text: 'middle', bold: true },
21+
{ text: ' three ' },
22+
{ text: 'after', bold: true },
23+
{ text: ' four' },
24+
],
25+
},
26+
],
27+
},
28+
{
29+
id: 'insert',
30+
name: 'Insertion',
31+
instructions:
32+
'Enter text below each line of instruction, including mis-spelling "wasnt"',
33+
value: [
34+
{
35+
type: 'paragraph',
36+
children: [
37+
{ text: 'Type by tapping keys: ', bold: true },
38+
{ text: 'It wasnt me. No.' },
39+
],
40+
},
41+
{
42+
type: 'paragraph',
43+
children: [{ text: '' }],
44+
},
45+
{
46+
type: 'paragraph',
47+
children: [
48+
{ text: 'Type using glide typing: ', bold: true },
49+
{ text: 'Yes Sam, I am.' },
50+
],
51+
},
52+
{
53+
type: 'paragraph',
54+
children: [{ text: '' }],
55+
},
56+
{
57+
type: 'paragraph',
58+
children: [
59+
{ text: 'Type using voice input: ', bold: true },
60+
{ text: 'The quick brown fox jumps over the lazy dog' },
61+
],
62+
},
63+
{
64+
type: 'paragraph',
65+
children: [{ text: '' }],
66+
},
67+
{
68+
type: 'paragraph',
69+
children: [{ text: 'Write any two words using an IME', bold: true }],
70+
},
71+
{
72+
type: 'paragraph',
73+
children: [{ text: '' }],
74+
},
75+
],
76+
},
77+
{
78+
id: 'special',
79+
name: 'Special',
80+
instructions: 'Follow the instructions on each line',
81+
value: [
82+
{
83+
type: 'paragraph',
84+
children: [
85+
{
86+
text: 'Type "it is", move cursor to "i|t" and hit enter.',
87+
bold: true,
88+
},
89+
],
90+
},
91+
{
92+
type: 'paragraph',
93+
children: [{ text: '' }],
94+
},
95+
{
96+
type: 'paragraph',
97+
children: [
98+
{
99+
text: 'Move cursor to "mid|dle" and press space, backspace, space, backspace.',
100+
bold: true,
101+
},
102+
],
103+
},
104+
{
105+
type: 'paragraph',
106+
children: [{ text: 'The middle word.' }],
107+
},
108+
{
109+
type: 'paragraph',
110+
children: [
111+
{
112+
text: 'Place cursor in line below. Wait for caps on keyboard to show up. If not try again. Type "It me. No." and check it doesn\'t mangle on the last period.',
113+
bold: true,
114+
},
115+
],
116+
},
117+
{
118+
type: 'paragraph',
119+
children: [{ text: '' }],
120+
},
121+
],
122+
},
123+
{
124+
id: 'empty',
125+
name: 'Empty',
126+
instructions:
127+
'Type "hello world", press enter, "hi", press enter, "bye", and then backspace over everything',
128+
value: [
129+
{
130+
type: 'paragraph',
131+
children: [{ text: '' }],
132+
},
133+
],
134+
},
135+
{
136+
id: 'remove',
137+
name: 'Remove',
138+
instructions:
139+
'Select from ANCHOR to FOCUS and press backspace. Move cursor to end. Backspace over all remaining content.',
140+
value: [
141+
{
142+
type: 'paragraph',
143+
children: [
144+
{ text: 'Go and ' },
145+
{ text: 'select', bold: true },
146+
{ text: ' from this ANCHOR and then' },
147+
],
148+
},
149+
{
150+
type: 'paragraph',
151+
children: [{ text: 'go and select' }],
152+
},
153+
{
154+
type: 'paragraph',
155+
children: [
156+
{ text: 'to this FOCUS then press ' },
157+
{ text: 'backspace.', bold: true },
158+
],
159+
},
160+
{
161+
type: 'paragraph',
162+
children: [
163+
{ text: 'After you have done that move selection to very end.' },
164+
],
165+
},
166+
{
167+
type: 'paragraph',
168+
children: [
169+
{ text: 'Then try ' },
170+
{ text: 'backspacing', bold: true },
171+
{ text: ' over all remaining text.' },
172+
],
173+
},
174+
],
175+
},
176+
]
177+
const AndroidTestsExample = () => {
178+
const [testId, setTestId] = useState(
179+
() => window.location.hash.replace('#', '') || TEST_CASES[0].id
180+
)
181+
useEffect(() => {
182+
window.history.replaceState({}, '', `#${testId}`)
183+
}, [testId])
184+
const testCase = TEST_CASES.find(({ id }) => id === testId)
185+
if (!testCase) {
186+
throw new Error(`Could not find test case '${testId}'`)
187+
}
188+
return (
189+
<>
190+
<label>
191+
Test case:{' '}
192+
<select value={testId} onChange={e => setTestId(e.target.value)}>
193+
{TEST_CASES.map(({ name, id }) => (
194+
<option key={id} value={id}>
195+
{name}
196+
</option>
197+
))}
198+
</select>
199+
</label>
200+
201+
<p
202+
className={css`
203+
font-weight: 600;
204+
margin: 0.5rem 0;
205+
white-space: pre-line;
206+
`}
207+
>
208+
{testCase.instructions}
209+
</p>
210+
211+
<TestCase key={testId} {...testCase} />
212+
</>
213+
)
214+
}
215+
const TestCase = ({ value }) => {
216+
const renderLeaf = useCallback(props => <Leaf {...props} />, [])
217+
const editor = useMemo(() => withHistory(withReact(createEditor())), [])
218+
return (
219+
<Slate editor={editor} initialValue={value}>
220+
<Editable
221+
renderLeaf={renderLeaf}
222+
placeholder="Enter some text…"
223+
spellCheck
224+
/>
225+
</Slate>
226+
)
227+
}
228+
const Leaf = ({ attributes, children, leaf }) => {
229+
if (leaf.bold) {
230+
children = <strong>{children}</strong>
231+
}
232+
return <span {...attributes}>{children}</span>
233+
}
234+
export default AndroidTestsExample

site/examples/js/check-lists.jsx

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1-
import React, { useMemo, useCallback } from 'react'
2-
import {
3-
Slate,
4-
Editable,
5-
withReact,
6-
useSlateStatic,
7-
useReadOnly,
8-
ReactEditor,
9-
} from 'slate-react'
1+
import { css } from '@emotion/css'
2+
import React, { useCallback, useMemo } from 'react'
103
import {
114
Editor,
12-
Transforms,
13-
Range,
145
Point,
15-
createEditor,
6+
Range,
167
Element as SlateElement,
8+
Transforms,
9+
createEditor,
1710
} from 'slate'
18-
import { css } from '@emotion/css'
1911
import { withHistory } from 'slate-history'
12+
import {
13+
Editable,
14+
ReactEditor,
15+
Slate,
16+
useReadOnly,
17+
useSlateStatic,
18+
withReact,
19+
} from 'slate-react'
2020

2121
const initialValue = [
2222
{

0 commit comments

Comments
 (0)