const test = require('tap').test;
const Looks = require('../../src/blocks/scratch3_looks');
const Runtime = require('../../src/engine/runtime');
const util = {
    target: {
        currentCostume: 0, // Internally, current costume is 0 indexed
        getCostumes: function () {
            return this.sprite.costumes;
        },
        sprite: {
            costumes: [
                {name: 'first name'},
                {name: 'second name'},
                {name: 'third name'}
            ]
        }
    }
};

const fakeRuntime = {
    getTargetForStage: () => util.target, // Just return the dummy target above.
    on: () => {} // Stub out listener methods used in constructor.
};
const blocks = new Looks(fakeRuntime);

test('getCostumeNumberName returns 1-indexed costume number', t => {
    util.target.currentCostume = 0; // This is 0-indexed.
    const args = {NUMBER_NAME: 'number'};
    const number = blocks.getCostumeNumberName(args, util);
    t.strictEqual(number, 1);
    t.end();
});

test('getCostumeNumberName can return costume name', t => {
    util.target.currentCostume = 0; // This is 0-indexed.
    const args = {NUMBER_NAME: 'name'};
    const number = blocks.getCostumeNumberName(args, util);
    t.strictEqual(number, 'first name');
    t.end();
});

test('getBackdropNumberName returns 1-indexed costume number', t => {
    util.target.currentCostume = 2; // This is 0-indexed.
    const args = {NUMBER_NAME: 'number'};
    const number = blocks.getBackdropNumberName(args, util);
    t.strictEqual(number, 3);
    t.end();
});

test('getBackdropNumberName can return costume name', t => {
    util.target.currentCostume = 2; // This is 0-indexed.
    const args = {NUMBER_NAME: 'name'};
    const number = blocks.getBackdropNumberName(args, util);
    t.strictEqual(number, 'third name');
    t.end();
});

test('numbers should be rounded to two decimals in say', t => {
    const rt = new Runtime();
    const looks = new Looks(rt);

    const args = {MESSAGE: 3.14159};
    const expectedSayString = '3.14';

    rt.removeAllListeners('SAY'); // Prevent say blocks from executing

    rt.addListener('SAY', (target, type, sayString) => {
        t.strictEqual(sayString, expectedSayString);
        t.end();
    });

    looks.say(args, util);
});

@@ -1166,37 +1166,35 @@
 e'%7D;%0A    const n
-umber
+ame
  = blocks.getCos
@@ -1240,21 +1240,241 @@
 tEqual(n
-umber
+ame, 'first name');%0A    t.end();%0A%7D);%0A%0Atest('getCostumeName returns costume name', t =%3E %7B%0A    util.target.currentCostume = 0; // This is 0-indexed.%0A    const name = blocks.getCostumeNumberName(%7B%7D, util);%0A    t.strictEqual(name
 , 'first

Test for getCostumeName