"use strict";
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
    function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
    return new (P || (P = Promise))(function (resolve, reject) {
        function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
        function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
        function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
        step((generator = generator.apply(thisArg, _arguments || [])).next());
    });
};
Object.defineProperty(exports, "__esModule", { value: true });
const testing_1 = require("@angular-devkit/schematics/testing");
const path = require("path");
const collectionPath = path.join(__dirname, "../../collection.json");
const workspaceOptions = {
    name: "workspace",
    newProjectRoot: "projects",
    version: "6.0.0",
};
const appOptions = {
    name: "schematest",
};
let appTree;
const schematicRunner = new testing_1.SchematicTestRunner("ng-add", collectionPath);
describe("already Installed", () => {
    beforeEach(() => __awaiter(void 0, void 0, void 0, function* () {
        appTree = yield schematicRunner
            .runExternalSchematicAsync("@schematics/angular", "workspace", workspaceOptions)
            .toPromise();
        appTree = yield schematicRunner
            .runExternalSchematicAsync("@schematics/angular", "application", appOptions, appTree)
            .toPromise();
        appTree.create("/hardhat/scripts/deploy.ts", `const deployContracts=["helloWorldContract"]`);
        appTree.create("/hardhat/hardhat.config.ts", "I am already there");
        appTree.create("/hardhat/contract.config.json", `{
      "helloWorldContract": {
          "artifactsPath": "0-HelloWorldContract.sol/HelloWorldContract.json",
          "name":"HelloWorldContract",
          "ctor":["Hello Angular Chained"],
          "jsonName":"hello_world_on_chain"
        }}`);
    }));
    it("Is already installed", () => __awaiter(void 0, void 0, void 0, function* () {
        expect(appTree.exists("hardhat/hardhat.config.ts")).toBeTrue();
    }));
    it("changes Deploy Contract", () => __awaiter(void 0, void 0, void 0, function* () {
        const existing_deploy_file = appTree.readContent("hardhat/scripts/deploy.ts");
        expect(existing_deploy_file).toContain(`const deployContracts=["helloWorldContract"]`);
        const tree = yield schematicRunner
            .runSchematicAsync("ng-add", { project: "default", configuration: "debugContract" }, appTree)
            .toPromise();
        const new_deploy_file = tree.readContent("hardhat/scripts/deploy.ts");
        expect(new_deploy_file).toContain(`const deployContracts=["debugContract"]`);
    }));
    it("Creates Contract JSON Config File", () => __awaiter(void 0, void 0, void 0, function* () {
        const tree = yield schematicRunner
            .runSchematicAsync("ng-add", { project: "default", configuration: "debugContract" }, appTree)
            .toPromise();
        const config_contract = JSON.parse(tree.read("hardhat/contract.config.json").toString("utf-8"));
        expect(Object.keys(config_contract).length == 2).toBeTrue();
    }));
    it("Should not add dependencies if already installed", () => __awaiter(void 0, void 0, void 0, function* () {
        const tree = yield schematicRunner
            .runSchematicAsync("ng-add", {}, appTree)
            .toPromise();
        const packageJson = tree.read("package.json").toString("utf-8");
        expect(packageJson.includes("\"hardhat\":")).toBeFalse();
    }));
    // it("Hello app creates Hello world chain module", async () => {
    //   const tree = await schematicRunner
    //     .runSchematicAsync("ng-add", {}, appTree)
    //     .toPromise();
    //     expect(tree.exists("/projects/schematest/src/app/hello-world-contract/hello-world-contract.module.ts")).toBeTrue();
    // });
});
//# sourceMappingURL=already_installed_tests.js.map