Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ Feature: Annotations Collaboration
And the caret is put after "foo"
And "{Backspace}" is pressed
And Editor B is focused
And the caret is put after "fo" by Editor B
And "a" is typed by Editor B
And the caret is put after "fo" in Editor B
And "a" is typed in Editor B
Then the text is "fo,a"
And "fo" has marks "c1"
And "a" has no marks
2 changes: 0 additions & 2 deletions packages/editor/gherkin-spec/selection.feature
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,6 @@ Feature: Selection
And "{Shift>}{ArrowLeft}{/Shift}" is pressed
Then "o|" is selected

# Flaky
@skip
Scenario: Expanding selection backwards, then forwards
Given the text "foo|bar"
When the editor is focused
Expand Down
101 changes: 0 additions & 101 deletions packages/editor/gherkin-spec/undo-redo-collaboration.feature

This file was deleted.

38 changes: 27 additions & 11 deletions packages/editor/gherkin-spec/undo-redo.feature
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,22 @@ Feature: Undo/Redo
Given one editor
And a global keymap

Scenario: Undoing writing two words
Given the text ""
When "foo" is typed
And " bar" is typed
And undo is performed
Then the text is "foo"

Scenario: Selection change does not affect the undo stack
Given the text ""
When "foo" is typed
And "{ArrowLeft}" is pressed
And "bar" is typed
Then the text is "fobaro"
When undo is performed
Then the text is "foo"

Scenario: Undoing annotation
Given the text "foo"
When "foo" is selected
Expand All @@ -15,17 +31,17 @@ Feature: Undo/Redo
Scenario: Undoing the deletion of the last char of annotated text
Given the text "foo"
And a "comment" "c1" around "foo"
When "ArrowRight" is pressed
And "Backspace" is pressed
When "{ArrowRight}" is pressed
And "{Backspace}" is pressed
And undo is performed
Then the text is "foo"
And "foo" has marks "c1"

Scenario: Redoing the deletion of the last char of annotated text
Given the text "foo"
And a "comment" "c1" around "foo"
When "ArrowRight" is pressed
And "Backspace" is pressed
When "{ArrowRight}" is pressed
And "{Backspace}" is pressed
And undo is performed
When redo is performed
Then the text is "fo"
Expand All @@ -34,8 +50,8 @@ Feature: Undo/Redo
Scenario: Undoing inserting text after annotated text
Given the text "foo"
And a "comment" "c1" around "foo"
When "ArrowRight" is pressed
And "Space" is pressed
When "{ArrowRight}" is pressed
And "{Space}" is pressed
Then the text is "foo, "
And "foo" has marks "c1"
And " " has no marks
Expand All @@ -46,8 +62,8 @@ Feature: Undo/Redo
Scenario: Undoing and redoing inserting text after annotated text
Given the text "foo"
And a "comment" "c1" around "foo"
When "ArrowRight" is pressed
And "Space" is pressed
When "{ArrowRight}" is pressed
And "{Space}" is pressed
And undo is performed
Then the text is "foo"
And "foo" has marks "c1"
Expand All @@ -60,22 +76,22 @@ Feature: Undo/Redo
Given the text "foo bar"
And a "comment" "c1" around "bar"
When "foo bar" is selected
And "Backspace" is pressed
And "{Backspace}" is pressed
And undo is performed
Then the text is "foo ,bar"
And "bar" has marks "c1"

Scenario: Undoing deletion of annotated block
Given the text "foo"
And a "comment" "c1" around "foo"
When "Backspace" is pressed
When "{Backspace}" is pressed
And undo is performed
Then the text is "foo"
And "foo" has marks "c1"

Scenario: Undoing annotation across text blocks
Given the text "foo"
When "Enter" is pressed
When "{Enter}" is pressed
And "bar" is typed
And "foobar" is selected
And "link" is toggled
Expand Down
10 changes: 10 additions & 0 deletions packages/editor/gherkin-tests-v2/undo-redo.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import {Feature} from 'racejar/vitest'
import undoRedoFeature from '../gherkin-spec/undo-redo.feature?raw'
import {parameterTypes} from '../src/test'
import {stepDefinitions} from '../src/test/vitest'

Feature({
featureText: undoRedoFeature,
stepDefinitions,
parameterTypes,
})
17 changes: 0 additions & 17 deletions packages/editor/gherkin-tests/undo-redo.test.ts

This file was deleted.

41 changes: 33 additions & 8 deletions packages/editor/src/test/vitest/step-definitions.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ export const stepDefinitions = [
await userEvent.type(context.locator, text)
}),
When(
'{string} is typed by Editor B',
'{string} is typed in Editor B',
async (context: Context, text: string) => {
await userEvent.type(context.locatorB, text)
},
Expand Down Expand Up @@ -222,23 +222,40 @@ export const stepDefinitions = [
*/
When(
'{button} is pressed',
async (_: Context, button: Parameter['button']) => {
async (context: Context, button: Parameter['button']) => {
const previousSelection = context.editor.getSnapshot().context.selection
await userEvent.keyboard(button)
await new Promise((resolve) => setTimeout(resolve, 100))

await vi.waitFor(() => {
const currentSelection = context.editor.getSnapshot().context.selection

if (currentSelection) {
expect(currentSelection).not.toBe(previousSelection)
}
})
},
),
When(
'{button} is pressed {int} times',
async (_: Context, button: Parameter['button'], times: number) => {
async (context: Context, button: Parameter['button'], times: number) => {
for (let i = 0; i < times; i++) {
const previousSelection = context.editor.getSnapshot().context.selection
await userEvent.keyboard(button)
await new Promise((resolve) => setTimeout(resolve, 100))

await vi.waitFor(() => {
const currentSelection =
context.editor.getSnapshot().context.selection

if (currentSelection) {
expect(currentSelection).not.toBe(previousSelection)
}
})
}
},
),
When(
'{shortcut} is pressed',
async (_: Context, shortcut: Parameter['shortcut']) => {
async (context: Context, shortcut: Parameter['shortcut']) => {
const shortcuts: Record<Parameter['shortcut'], string> = {
'deleteWord.backward': IS_MAC
? '{Alt>}{Backspace}{/Alt}'
Expand All @@ -248,8 +265,16 @@ export const stepDefinitions = [
: '{Control>}{Delete}{/Control}',
}

const previousSelection = context.editor.getSnapshot().context.selection
await userEvent.keyboard(shortcuts[shortcut])
await new Promise((resolve) => setTimeout(resolve, 100))

await vi.waitFor(() => {
const currentSelection = context.editor.getSnapshot().context.selection

if (currentSelection) {
expect(currentSelection).not.toBe(previousSelection)
}
})
},
),

Expand Down Expand Up @@ -315,7 +340,7 @@ export const stepDefinitions = [
},
),
When(
'the caret is put after {string} by Editor B',
'the caret is put after {string} in Editor B',
async (context: Context, text: string) => {
await vi.waitFor(() => {
const selection = getSelectionAfterText(
Expand Down
56 changes: 0 additions & 56 deletions packages/editor/tests/event.history.undo.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,67 +5,11 @@ import {userEvent} from 'vitest/browser'
import type {EditorSelection} from '../src'
import {execute, forward, raise} from '../src/behaviors/behavior.types.action'
import {defineBehavior} from '../src/behaviors/behavior.types.behavior'
import type {MutationEvent} from '../src/editor/relay-machine'
import {BehaviorPlugin} from '../src/plugins/plugin.behavior'
import {EventListenerPlugin} from '../src/plugins/plugin.event-listener'
import {getFirstBlock, getFocusBlock} from '../src/selectors'
import {createTestEditor} from '../src/test/vitest'

describe('event.history.undo', () => {
test('Scenario: Undoing writing two words', async () => {
const mutationEvents: Array<MutationEvent> = []

const {editor, locator} = await createTestEditor({
children: (
<EventListenerPlugin
on={(event) => {
if (event.type === 'mutation') {
mutationEvents.push(event)
}
}}
/>
),
})

await userEvent.type(locator, 'foo')
await userEvent.type(locator, ' bar')

await vi.waitFor(() => {
expect(getTersePt(editor.getSnapshot().context)).toEqual(['foo bar'])
})

editor.send({type: 'history.undo'})

await vi.waitFor(() => {
expect(getTersePt(editor.getSnapshot().context)).toEqual(['foo'])
})
})

test('Scenario: Selection change does not affect the undo stack', async () => {
const {editor, locator} = await createTestEditor()

await userEvent.click(locator)
await userEvent.type(locator, 'foo')
await userEvent.keyboard('{ArrowLeft}')
await userEvent.type(locator, 'bar')

await vi.waitFor(() => {
expect(getTersePt(editor.getSnapshot().context)).toEqual(['fobaro'])
})

editor.send({type: 'history.undo'})

await vi.waitFor(() => {
expect(getTersePt(editor.getSnapshot().context)).toEqual(['foo'])
})

editor.send({type: 'history.undo'})

await vi.waitFor(() => {
expect(getTersePt(editor.getSnapshot().context)).toEqual([''])
})
})

test('Scenario: Undoing action sets', async () => {
const {editor, locator} = await createTestEditor({
children: (
Expand Down