From b618f2493c62cc08b07309b08e371ee1442ddc80 Mon Sep 17 00:00:00 2001 From: Paul Kaplan <pkaplan@media.mit.edu> Date: Fri, 8 Feb 2019 13:56:00 -0500 Subject: [PATCH] Fix backdrop uploading from gif --- src/containers/costume-tab.jsx | 2 +- src/containers/stage-selector.jsx | 12 ++++++++---- src/lib/file-uploader.js | 2 +- test/integration/backdrops.test.js | 2 +- test/integration/costumes.test.js | 2 +- test/integration/sprites.test.js | 6 +++--- 6 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/containers/costume-tab.jsx b/src/containers/costume-tab.jsx index efaca4fbe..7d5caf341 100644 --- a/src/containers/costume-tab.jsx +++ b/src/containers/costume-tab.jsx @@ -207,7 +207,7 @@ class CostumeTab extends React.Component { handleFileUpload(e.target, (buffer, fileType, fileName) => { costumeUpload(buffer, fileType, storage, vmCostumes => { vmCostumes.forEach((costume, i) => { - costume.name = `${fileName}${i + 1}`; + costume.name = `${fileName}${i ? i + 1 : ''}`; }); this.handleNewCostume(vmCostumes); }); diff --git a/src/containers/stage-selector.jsx b/src/containers/stage-selector.jsx index efb8dc7d2..6d9188874 100644 --- a/src/containers/stage-selector.jsx +++ b/src/containers/stage-selector.jsx @@ -63,9 +63,13 @@ class StageSelector extends React.Component { handleClick () { this.props.onSelect(this.props.id); } - handleNewBackdrop (backdrop) { - this.props.vm.addBackdrop(backdrop.md5, backdrop).then(() => - this.props.onActivateTab(COSTUMES_TAB_INDEX)); + handleNewBackdrop (backdrops_) { + const backdrops = Array.isArray(backdrops_) ? backdrops_ : [backdrops_]; + Promise.all(backdrops.map(backdrop => + this.props.vm.addBackdrop(backdrop.md5, backdrop) + )).then(() => + this.props.onActivateTab(COSTUMES_TAB_INDEX) + ); } handleSurpriseBackdrop () { // @todo should this not add a backdrop you already have? @@ -80,7 +84,7 @@ class StageSelector extends React.Component { handleFileUpload(e.target, (buffer, fileType, fileName) => { costumeUpload(buffer, fileType, storage, vmCostumes => { vmCostumes.forEach((costume, i) => { - costume.name = `${fileName}${i + 1}`; + costume.name = `${fileName}${i ? i + 1 : ''}`; }); this.handleNewBackdrop(vmCostumes); }); diff --git a/src/lib/file-uploader.js b/src/lib/file-uploader.js index 70fb32aff..86e0a29d9 100644 --- a/src/lib/file-uploader.js +++ b/src/lib/file-uploader.js @@ -210,7 +210,7 @@ const spriteUpload = function (fileData, fileType, spriteName, storage, handleSp // Make a sprite from an image by making it a costume first costumeUpload(fileData, fileType, storage, vmCostumes => { vmCostumes.forEach((costume, i) => { - costume.name = `${spriteName}${i + 1}`; + costume.name = `${spriteName}${i ? i + 1 : ''}`; }); const newSprite = { name: spriteName, diff --git a/test/integration/backdrops.test.js b/test/integration/backdrops.test.js index d0a3e84aa..b9acd8307 100644 --- a/test/integration/backdrops.test.js +++ b/test/integration/backdrops.test.js @@ -51,7 +51,7 @@ describe('Working with backdrops', () => { await expect(logs).toEqual([]); }); - test.only('Adding multiple backdrops at the same time', async () => { + test('Adding multiple backdrops at the same time', async () => { const files = [ path.resolve(__dirname, '../fixtures/gh-3582-png.png'), path.resolve(__dirname, '../fixtures/100-100.svg') diff --git a/test/integration/costumes.test.js b/test/integration/costumes.test.js index 19c885ab8..0dc781493 100644 --- a/test/integration/costumes.test.js +++ b/test/integration/costumes.test.js @@ -204,7 +204,7 @@ describe('Working with costumes', () => { await expect(logs).toEqual([]); }); - test.only('Adding multiple costumes at the same time', async () => { + test('Adding multiple costumes at the same time', async () => { const files = [ path.resolve(__dirname, '../fixtures/gh-3582-png.png'), path.resolve(__dirname, '../fixtures/100-100.svg') diff --git a/test/integration/sprites.test.js b/test/integration/sprites.test.js index fc026f967..32c3b690a 100644 --- a/test/integration/sprites.test.js +++ b/test/integration/sprites.test.js @@ -116,7 +116,7 @@ describe('Working with sprites', () => { // Check to make sure the size is right await clickText('Costumes'); - await clickText('100-1001', scope.costumesTab); // The name of the costume + await clickText('100-100', scope.costumesTab); // The name of the costume await clickText('100 x 100', scope.costumesTab); // The size of the costume const logs = await getLogs(); await expect(logs).toEqual([]); @@ -134,7 +134,7 @@ describe('Working with sprites', () => { await clickText('paddleball', scope.spriteTile); // Sprite is named for costume filename await clickText('Costumes'); - await findByText('paddleball1', scope.costumesTab); + await findByText('paddleball', scope.costumesTab); await findByText('paddleball2', scope.costumesTab); await findByText('paddleball3', scope.costumesTab); await findByText('paddleball4', scope.costumesTab); @@ -182,7 +182,7 @@ describe('Working with sprites', () => { await expect(logs).toEqual([]); }); - test.only('Adding multiple sprites at the same time', async () => { + test('Adding multiple sprites at the same time', async () => { const files = [ path.resolve(__dirname, '../fixtures/gh-3582-png.png'), path.resolve(__dirname, '../fixtures/100-100.svg') -- GitLab