mirror of
https://github.com/scratchfoundation/scratch-vm.git
synced 2025-08-12 22:42:03 -04:00
Add a utility for giving blocks new IDs, use it for sharing blocks.
This commit is contained in:
parent
884fd54d2b
commit
31fbcfa4d7
4 changed files with 164 additions and 0 deletions
test/unit
64
test/unit/util_new-block-ids.js
Normal file
64
test/unit/util_new-block-ids.js
Normal file
|
@ -0,0 +1,64 @@
|
|||
const newBlockIds = require('../../src/util/new-block-ids');
|
||||
const simpleStack = require('../fixtures/simple-stack');
|
||||
const tap = require('tap');
|
||||
const test = tap.test;
|
||||
|
||||
let originals;
|
||||
let newBlocks;
|
||||
|
||||
tap.beforeEach(done => {
|
||||
originals = simpleStack;
|
||||
// Will be mutated so make a copy first
|
||||
newBlocks = JSON.parse(JSON.stringify(simpleStack));
|
||||
newBlockIds(newBlocks);
|
||||
done();
|
||||
});
|
||||
|
||||
|
||||
/**
|
||||
* The structure of the simple stack is:
|
||||
* moveTo (looks_size) -> stopAllSounds
|
||||
* The list of blocks is
|
||||
* 0: moveTo (TO input block: 1, shadow: 2)
|
||||
* 1: looks_size (parent: 0)
|
||||
* 2: obscured shadow for moveTo input (parent: 0)
|
||||
* 3: stopAllSounds (parent: 0)
|
||||
* Inspect fixtures/blocks for the full object.
|
||||
*/
|
||||
|
||||
test('top-level block IDs have all changed', t => {
|
||||
newBlocks.forEach((block, i) => {
|
||||
t.notEqual(block.id, originals[i].id);
|
||||
});
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('input reference is maintained on parent for attached block', t => {
|
||||
t.equal(newBlocks[0].inputs.TO.block, newBlocks[1].id);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('input reference is maintained on parent for obscured shadow', t => {
|
||||
t.equal(newBlocks[0].inputs.TO.shadow, newBlocks[2].id);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('parent reference is maintained for attached input', t => {
|
||||
t.equal(newBlocks[1].parent, newBlocks[0].id);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('parent reference is maintained for obscured shadow', t => {
|
||||
t.equal(newBlocks[2].parent, newBlocks[0].id);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('parent reference is maintained for next block', t => {
|
||||
t.equal(newBlocks[3].parent, newBlocks[0].id);
|
||||
t.end();
|
||||
});
|
||||
|
||||
test('next reference is maintained for previous block', t => {
|
||||
t.equal(newBlocks[0].next, newBlocks[3].id);
|
||||
t.end();
|
||||
});
|
Loading…
Add table
Add a link
Reference in a new issue