-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
150 additions
and
5 deletions.
There are no files selected for viewing
96 changes: 96 additions & 0 deletions
96
new-packages/ts-project/__tests__/source-edits/edit-guard.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
import { expect, test } from 'vitest'; | ||
import { createTestProject, testdir, ts } from '../utils'; | ||
|
||
test('should be possible to update a guard name', async () => { | ||
const tmpPath = await testdir({ | ||
'tsconfig.json': JSON.stringify({}), | ||
'index.ts': ts` | ||
import { createMachine } from "xstate"; | ||
createMachine({ | ||
on: { | ||
CALL_HIM_MAYBE: { | ||
guard: "isItTooLate", | ||
actions: "callDavid", | ||
}, | ||
}, | ||
}); | ||
`, | ||
}); | ||
|
||
const project = await createTestProject(tmpPath); | ||
|
||
const textEdits = project.editDigraph( | ||
{ | ||
fileName: 'index.ts', | ||
machineIndex: 0, | ||
}, | ||
{ | ||
type: 'edit_guard', | ||
path: [], | ||
transitionPath: ['on', 'CALL_HIM_MAYBE', 0], | ||
name: 'isHeAwake', | ||
}, | ||
); | ||
expect(await project.applyTextEdits(textEdits)).toMatchInlineSnapshot(` | ||
{ | ||
"index.ts": "import { createMachine } from "xstate"; | ||
createMachine({ | ||
on: { | ||
CALL_HIM_MAYBE: { | ||
guard: "isHeAwake", | ||
actions: "callDavid", | ||
}, | ||
}, | ||
});", | ||
} | ||
`); | ||
}); | ||
|
||
test('should be possible to update a parametrized guard name', async () => { | ||
const tmpPath = await testdir({ | ||
'tsconfig.json': JSON.stringify({}), | ||
'index.ts': ts` | ||
import { createMachine } from "xstate"; | ||
createMachine({ | ||
on: { | ||
CALL_HIM_MAYBE: { | ||
guard: { type: "isItTooLate", time: "9am" }, | ||
actions: "callDavid", | ||
}, | ||
}, | ||
}); | ||
`, | ||
}); | ||
|
||
const project = await createTestProject(tmpPath); | ||
|
||
const textEdits = project.editDigraph( | ||
{ | ||
fileName: 'index.ts', | ||
machineIndex: 0, | ||
}, | ||
{ | ||
type: 'edit_guard', | ||
path: [], | ||
transitionPath: ['on', 'CALL_HIM_MAYBE', 0], | ||
name: 'isHeAwake', | ||
}, | ||
); | ||
expect(await project.applyTextEdits(textEdits)).toMatchInlineSnapshot(` | ||
{ | ||
"index.ts": "import { createMachine } from "xstate"; | ||
createMachine({ | ||
on: { | ||
CALL_HIM_MAYBE: { | ||
guard: { type: "isHeAwake", time: "9am" }, | ||
actions: "callDavid", | ||
}, | ||
}, | ||
});", | ||
} | ||
`); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters