-
Notifications
You must be signed in to change notification settings - Fork 743
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
7 changed files
with
132 additions
and
120 deletions.
There are no files selected for viewing
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
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
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,63 @@ | ||
import { describe, expect, test } from 'vitest'; | ||
|
||
import { NodeType } from '@tmagic/schema'; | ||
|
||
import props from '@editor/services/props'; | ||
|
||
test('createId', async () => { | ||
const id = await props.createId('text'); | ||
|
||
console.log(id); | ||
|
||
expect(id.startsWith('text')).toBeTruthy(); | ||
}); | ||
|
||
describe('setNewItemId', () => { | ||
test('普通', async () => { | ||
const config = { | ||
id: 1, | ||
type: 'text', | ||
}; | ||
// 将组件与组件的子元素配置中的id都设置成一个新的ID | ||
await props.setNewItemId(config); | ||
expect(config.id === 1).toBeFalsy(); | ||
}); | ||
|
||
test('items', async () => { | ||
const config = { | ||
id: 1, | ||
type: NodeType.PAGE, | ||
items: [ | ||
{ | ||
type: 'text', | ||
id: 2, | ||
}, | ||
], | ||
}; | ||
await props.setNewItemId(config); | ||
expect(config.id === 1).toBeFalsy(); | ||
expect(config.items[0].id === 2).toBeFalsy(); | ||
}); | ||
|
||
test('pop', async () => { | ||
const config = { | ||
id: 1, | ||
type: NodeType.PAGE, | ||
items: [ | ||
{ | ||
type: 'button', | ||
id: 2, | ||
pop: 3, | ||
}, | ||
{ | ||
type: 'pop', | ||
id: 3, | ||
}, | ||
], | ||
}; | ||
await props.setNewItemId(config); | ||
expect(config.items[0].pop === 3).toBeFalsy(); | ||
expect(config.items[1].id === 3).toBeFalsy(); | ||
expect(config.items[1].id === config.items[0].pop).toBeTruthy(); | ||
}); | ||
}); |
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