"use strict";
var _this = this;
Object.defineProperty(exports, "__esModule", { value: true });
var tslib_1 = require("tslib");
var chai_1 = require("chai");
var lodash_1 = require("lodash");
var memFs = require("mem-fs");
var fsEditor = require("mem-fs-editor");
var migrate_manifest_1 = require("../../steps/migrate_manifest");
var immutable_1 = require("immutable");
describe("migrate manifest", function () {
    var editor;
    var options;
    var cwd = process.cwd();
    var src = cwd + "/src/test/fixtures/basic_ticket_sample_app";
    var dest = cwd + "/tmp/test/basic_ticket_sample_app";
    beforeEach(function () {
        editor = fsEditor.create(memFs.create());
        options = immutable_1.Map({ src: src, dest: dest, editor: editor });
    });
    it("should copy the manifest to the destination", function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
        return tslib_1.__generator(this, function (_a) {
            switch (_a.label) {
                case 0: return [4 /*yield*/, migrate_manifest_1.default(options)];
                case 1:
                    _a.sent();
                    chai_1.expect(editor.exists(dest + "/dist/manifest.json")).to.be.true;
                    return [2 /*return*/];
            }
        });
    }); });
    it("should set frameworkVersion to 2.0", function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
        return tslib_1.__generator(this, function (_a) {
            switch (_a.label) {
                case 0: return [4 /*yield*/, migrate_manifest_1.default(options)];
                case 1:
                    _a.sent();
                    chai_1.expect(editor.readJSON(dest + "/dist/manifest.json").frameworkVersion).to.equal("2.0");
                    return [2 /*return*/];
            }
        });
    }); });
    describe("location", function () {
        function setManifest(toMerge) {
            var manifestJson = editor.readJSON(src + "/manifest.json");
            editor.writeJSON(src + "/manifest.json", lodash_1.merge(manifestJson, toMerge));
        }
        describe("with a string", function () {
            before(function () { return setManifest({ location: "ticket_sidebar" }); });
            after(function () {
                return setManifest({ location: ["ticket_sidebar", "new_ticket_sidebar"] });
            });
            it("should rewrite the location to a hash", function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
                var manifestJson;
                return tslib_1.__generator(this, function (_a) {
                    switch (_a.label) {
                        case 0: return [4 /*yield*/, migrate_manifest_1.default(options)];
                        case 1:
                            _a.sent();
                            manifestJson = editor.readJSON(dest + "/dist/manifest.json");
                            chai_1.expect(lodash_1.get(manifestJson, "location.support")).to.have.property("ticket_sidebar", "assets/index.html");
                            return [2 /*return*/];
                    }
                });
            }); });
        });
        describe("with an array of strings", function () {
            it("should rewrite all the locations to a hash", function () { return tslib_1.__awaiter(_this, void 0, void 0, function () {
                var manifestJson, support;
                return tslib_1.__generator(this, function (_a) {
                    switch (_a.label) {
                        case 0: return [4 /*yield*/, migrate_manifest_1.default(options)];
                        case 1:
                            _a.sent();
                            manifestJson = editor.readJSON(dest + "/dist/manifest.json");
                            support = lodash_1.get(manifestJson, "location.support");
                            chai_1.expect(support).to.have.property("ticket_sidebar", "assets/index.html");
                            chai_1.expect(support).to.have.property("new_ticket_sidebar", "assets/index.html");
                            return [2 /*return*/];
                    }
                });
            }); });
        });
    });
});
