1
0
mirror of https://github.com/ianstormtaylor/slate.git synced 2025-08-31 19:01:54 +02:00

fix preserveSelection in tests

This commit is contained in:
Ian Storm Taylor
2017-09-18 09:12:47 -07:00
parent f52967c9e6
commit ee2c4e6bc7
45 changed files with 64 additions and 44 deletions

View File

@@ -593,8 +593,8 @@ class State extends Record(DEFAULTS) {
if (options.preserveSelection && !options.preserveKeys) {
const { document, selection } = this
object.selection.anchorPath = document.getPath(selection.anchorKey)
object.selection.focusPath = document.getPath(selection.focusKey)
object.selection.anchorPath = selection.isSet ? document.getPath(selection.anchorKey) : null
object.selection.focusPath = selection.isSet ? document.getPath(selection.focusKey) : null
delete object.selection.anchorKey
delete object.selection.focusKey
}

View File

@@ -21,7 +21,7 @@ export const output = (
<state>
<document>
<image>
<cursor />{' '}
{' '}<cursor />
</image>
</document>
</state>

View File

@@ -20,7 +20,7 @@ export const output = (
<state>
<document>
<paragraph>
one<link>tw<cursor /></link>
one<link>tw</link><cursor />
</paragraph>
</document>
</state>

View File

@@ -19,5 +19,11 @@ export const input = (
export const output = (
<state>
<document />
<selection
anchorKey={null}
anchorOffset={0}
focusKey={null}
focusOffset={0}
/>
</state>
)

View File

@@ -20,7 +20,7 @@ export const output = (
<state>
<document>
<paragraph>
<link>word</link>
<link>word</link><cursor />
</paragraph>
</document>
</state>

View File

@@ -20,7 +20,7 @@ export const output = (
<state>
<document>
<paragraph>
one<link>two</link>
one<link>two</link><cursor />
</paragraph>
</document>
</state>

View File

@@ -20,7 +20,7 @@ export const output = (
<state>
<document>
<paragraph>
wrd
w<cursor />rd
</paragraph>
</document>
</state>

View File

@@ -20,7 +20,7 @@ export const output = (
<state>
<document>
<paragraph>
d
<cursor />d
</paragraph>
</document>
</state>

View File

@@ -19,5 +19,11 @@ export const input = (
export const output = (
<state>
<document />
<selection
anchorKey={null}
anchorOffset={0}
focusKey={null}
focusOffset={0}
/>
</state>
)

View File

@@ -16,11 +16,12 @@ export const input = (
</state>
)
// TODO: this output selection state seems bad
export const output = (
<state>
<document>
<paragraph>
<cursor /><link>wo</link>
<anchor /><link><focus />wo</link>
</paragraph>
</document>
</state>

View File

@@ -26,7 +26,7 @@ export const output = (
<document>
<quote>
<paragraph>
onetwo
one<cursor />two
</paragraph>
</quote>
</document>

View File

@@ -20,7 +20,7 @@ export const output = (
<state>
<document>
<paragraph>
oe
o<cursor />e
</paragraph>
</document>
</state>

View File

@@ -26,7 +26,7 @@ export const output = (
<state>
<document>
<paragraph>
on
on<cursor />
</paragraph>
<paragraph>
three

View File

@@ -26,7 +26,7 @@ export const output = (
<state>
<document>
<paragraph>
o
<cursor />o
</paragraph>
<paragraph>
three

View File

@@ -19,5 +19,11 @@ export const input = (
export const output = (
<state>
<document />
<selection
anchorKey={null}
anchorOffset={0}
focusKey={null}
focusOffset={0}
/>
</state>
)

View File

@@ -28,6 +28,7 @@ export const input = (
</state>
)
// TODO: this output selection should be at the end of the block
export const output = (
<state>
<document>
@@ -38,7 +39,7 @@ export const output = (
two
</quote>
<quote>
three
<cursor />three
</quote>
</document>
</state>

View File

@@ -26,7 +26,7 @@ export const output = (
<state>
<document>
<paragraph>
wordfragment<cursor />
word<cursor />fragment
</paragraph>
</document>
</state>

View File

@@ -26,7 +26,7 @@ export const output = (
<state>
<document>
<paragraph>
<link>word</link>fragment<cursor />
<link>word</link><cursor />fragment
</paragraph>
</document>
</state>

View File

@@ -32,7 +32,7 @@ export const output = (
woone
</paragraph>
<quote>
two<cursor />rd
<cursor />tword
</quote>
</document>
</state>

View File

@@ -35,7 +35,7 @@ export const output = (
</paragraph>
<quote>
<quote>
tword
<cursor />tword
</quote>
</quote>
</document>

View File

@@ -26,7 +26,7 @@ export const output = (
<state>
<document>
<paragraph>
wofragment<cursor />rd
wo<cursor />fragmentrd
</paragraph>
</document>
</state>

View File

@@ -27,7 +27,7 @@ export const output = (
<state>
<document>
<paragraph>
<link>wo</link><hashtag><cursor />fragment</hashtag><link>rd</link>
<link>wo</link><hashtag>fragment</hashtag><cursor /><link>rd</link>
</paragraph>
</document>
</state>

View File

@@ -26,7 +26,7 @@ export const output = (
<state>
<document>
<paragraph>
<link>wo</link>fragment<cursor /><link>rd</link>
<link>wo</link><cursor />fragment<link>rd</link>
</paragraph>
</document>
</state>

View File

@@ -38,7 +38,7 @@ export const output = (
</paragraph>
<quote>
<quote>
tword
<cursor />tword
</quote>
</quote>
</quote>

View File

@@ -38,7 +38,7 @@ export const output = (
two
</quote>
<quote>
threeword
<cursor />threeword
</quote>
</document>
</state>

View File

@@ -26,7 +26,7 @@ export const output = (
<state>
<document>
<paragraph>
fragment<cursor />word
<cursor />fragmentword
</paragraph>
</document>
</state>

View File

@@ -32,7 +32,7 @@ export const output = (
word
</paragraph>
<paragraph>
fragment<cursor />another
<cursor />fragmentanother
</paragraph>
</document>
</state>

View File

@@ -29,7 +29,7 @@ export const output = (
<state>
<document>
<paragraph>
wofragment<cursor />other
wo<cursor />fragmentother
</paragraph>
</document>
</state>

View File

@@ -23,7 +23,7 @@ export const output = (
<state>
<document>
<paragraph>
word<emoji><cursor />{' '}</emoji>
word<emoji>{' '}<cursor /></emoji>
</paragraph>
</document>
</state>

View File

@@ -21,7 +21,7 @@ export const output = (
<state>
<document>
<paragraph>
wo<emoji><cursor />{' '}</emoji>rd
wo<emoji>{' '}<cursor /></emoji>rd
</paragraph>
</document>
</state>

View File

@@ -23,7 +23,7 @@ export const output = (
<state>
<document>
<paragraph>
<emoji><cursor />{' '}</emoji>word
<emoji>{' '}<cursor /></emoji>word
</paragraph>
</document>
</state>

View File

@@ -23,7 +23,7 @@ export const output = (
<state>
<document>
<paragraph>
<link>wo<emoji><cursor />{' '}</emoji>rd</link>
<link>wo<emoji>{' '}<cursor /></emoji>rd</link>
</paragraph>
</document>
</state>

View File

@@ -23,7 +23,7 @@ export const output = (
<state>
<document>
<paragraph>
<emoji><cursor />{' '}</emoji>
<emoji>{' '}<cursor /></emoji>
</paragraph>
</document>
</state>

View File

@@ -22,7 +22,7 @@ export const output = (
<state>
<document>
<paragraph>
wo<emoji><cursor />{' '}</emoji>rd
wo<emoji>{' '}<cursor /></emoji>rd
</paragraph>
</document>
</state>

View File

@@ -10,7 +10,7 @@ export const input = (
<state>
<document>
<paragraph>
w<b>or</b><cursor />d
w<b>or<cursor /></b>d
</paragraph>
</document>
</state>
@@ -20,7 +20,7 @@ export const output = (
<state>
<document>
<paragraph>
w<b>ora</b>d
w<b>ora<cursor /></b>d
</paragraph>
</document>
</state>

View File

@@ -23,7 +23,7 @@ export const output = (
word
</paragraph>
<paragraph>
<cursor /><link href="website.com">hyperlink</link>word
<link href="website.com"><cursor />hyperlink</link>word
</paragraph>
</document>
</state>

View File

@@ -20,7 +20,7 @@ export const output = (
<state>
<document>
<paragraph>
<link>wo</link><cursor /><link>rd</link>
<link>wo</link><link><cursor />rd</link>
</paragraph>
</document>
</state>

View File

@@ -20,7 +20,7 @@ export const output = (
<state>
<document>
<paragraph>
<link><link>wo</link><cursor /><link>rd</link></link>
<link><link>wo</link><link><cursor />rd</link></link>
</paragraph>
</document>
</state>

View File

@@ -20,7 +20,7 @@ export const output = (
<state>
<document>
<paragraph>
<link>w</link><cursor /><link>d</link>
<link>w</link><link><cursor />d</link>
</paragraph>
</document>
</state>

View File

@@ -20,7 +20,7 @@ export const output = (
<state>
<document>
<paragraph>
<link><b>wo</b></link><cursor /><link><b>rd</b></link>
<link><b>wo</b></link><link><b><cursor />rd</b></link>
</paragraph>
</document>
</state>

View File

@@ -20,7 +20,7 @@ export const output = (
<state>
<document>
<paragraph>
onetwothree
<anchor />onetwothree<focus />
</paragraph>
</document>
</state>

View File

@@ -20,7 +20,7 @@ export const output = (
<state>
<document>
<paragraph>
he<hashtag>ll</hashtag>o <anchor />wo<focus />rd</paragraph>
he<hashtag>ll</hashtag>o <anchor />wor<focus />d</paragraph>
</document>
</state>
)

View File

@@ -20,7 +20,7 @@ export const output = (
<state>
<document>
<paragraph>
<link>wo</link><hashtag><link><anchor />rd</link><link>an</link></hashtag><focus /><link>other</link>
<link>wo</link><hashtag><link><anchor />rd</link><link>an</link></hashtag><link><focus />other</link>
</paragraph>
</document>
</state>

View File

@@ -29,7 +29,7 @@ describe('changes', async () => {
const fn = module.default
const change = input.change()
fn(change)
const opts = { preseveSelection: true, preserveStateData: true }
const opts = { preserveSelection: true, preserveStateData: true }
const actual = change.state.toJSON(opts)
const expected = output.toJSON(opts)
assert.deepEqual(actual, expected)

View File

@@ -22,7 +22,7 @@ describe('history', async () => {
const { input, output } = module
const fn = module.default
const next = fn(input)
const opts = { preseveSelection: true, preserveStateData: true }
const opts = { preserveSelection: true, preserveStateData: true }
const actual = next.toJSON(opts)
const expected = output.toJSON(opts)
assert.deepEqual(actual, expected)