"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const chai_1 = require("chai");
const controls_1 = require("../../src/ui/editor/frame/sources/controls");
const emptyFixture = [];
const simpleFixture = [
    {
        sceneID: 'scene1',
        controls: [
            {
                controlID: 'control1',
                kind: 'button',
                disabled: false,
            },
        ],
    },
];
const fixtureWithNoControls = [
    {
        sceneID: 'scene1',
        controls: [],
    },
];
const fixtureWithTopCustomProp = [
    Object.assign({}, simpleFixture[0], { foo: 'bar' }),
];
const fixtureWithModifiedTopCustomProp = [
    Object.assign({}, simpleFixture[0], { foo: 'baz' }),
];
const fixtureWithNestedCustomProp = [
    Object.assign({}, simpleFixture[0], { controls: [
            Object.assign({}, simpleFixture[0].controls[0], { foo: 'bar' }),
        ] }),
];
describe('ResourceComparator', () => {
    let src;
    beforeEach(() => {
        src = new controls_1.ControlsSource();
    });
    it('is a noop without changes', () => {
        chai_1.expect(src.compare(simpleFixture, simpleFixture)).to.be.empty;
        chai_1.expect(src.compare(emptyFixture, emptyFixture)).to.be.empty;
    });
    it('adds property to a top level object', () => {
        chai_1.expect(src.compare(simpleFixture, fixtureWithTopCustomProp)).to.deep.equal([
            {
                method: 'onSceneUpdate',
                params: { scenes: [{ sceneID: 'scene1', foo: 'bar' }] },
            },
        ]);
    });
    it('adds property to a nested object', () => {
        chai_1.expect(src.compare(simpleFixture, fixtureWithNestedCustomProp)).to.deep.equal([
            {
                method: 'onControlUpdate',
                params: {
                    sceneID: 'scene1',
                    controls: fixtureWithNestedCustomProp[0].controls,
                },
            },
        ]);
    });
    it('modifies an object property', () => {
        chai_1.expect(src.compare(fixtureWithModifiedTopCustomProp, fixtureWithTopCustomProp)).to.deep.equal([
            {
                method: 'onSceneUpdate',
                params: { scenes: [{ sceneID: 'scene1', foo: 'bar' }] },
            },
        ]);
    });
    it('destroys deep resources', () => {
        chai_1.expect(src.compare(simpleFixture, fixtureWithNoControls)).to.deep.equal([
            {
                method: 'onControlDelete',
                params: { sceneID: 'scene1', controls: [{ controlID: 'control1' }] },
            },
        ]);
    });
    it('adds deep resources', () => {
        chai_1.expect(src.compare(fixtureWithNoControls, simpleFixture)).to.deep.equal([
            {
                method: 'onControlCreate',
                params: { sceneID: 'scene1', controls: simpleFixture[0].controls },
            },
        ]);
    });
    it('destroys top level resources', () => {
        chai_1.expect(src.compare(simpleFixture, emptyFixture)).to.deep.equal([
            {
                method: 'onSceneDelete',
                params: { sceneID: 'scene1', reassignSceneID: 'default' },
            },
        ]);
    });
    it('adds top level resources', () => {
        chai_1.expect(src.compare(emptyFixture, simpleFixture)).to.deep.equal([
            {
                method: 'onSceneCreate',
                params: { scenes: [simpleFixture[0]] },
            },
        ]);
    });
});
