"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 core_1 = require("@angular-devkit/core");
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("Initilization", () => {
    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();
    }));
    it("Should not be already installed", () => __awaiter(void 0, void 0, void 0, function* () {
        expect(appTree.exists("hardhat/hardhat.config.ts")).toBeFalse();
    }));
    it("works", () => __awaiter(void 0, void 0, void 0, function* () {
        const tree = yield schematicRunner
            .runSchematicAsync("ng-add", { project: "default", test: true, demoToInstall: true, addOns: [], dappDemo: "helloWorldContract" }, appTree)
            .toPromise();
        expect(tree.files.length).toBeGreaterThan(2);
    }));
    it("No demo app installation should work", () => __awaiter(void 0, void 0, void 0, function* () {
        const tree = yield schematicRunner
            .runSchematicAsync("ng-add", { project: "default", contractName: 'gasLess', test: true, demoToInstall: false, addOns: [], dappDemo: "minimalContract" }, appTree)
            .toPromise();
        console.log(tree.files);
        const app_module_file = tree.readContent("/projects/schematest/src/app/app.module.ts");
        console.log(app_module_file);
        expect(tree.files.length).toBeGreaterThan(2);
    }));
    it("No demo app should miminalcontract", () => __awaiter(void 0, void 0, void 0, function* () {
        const tree = yield schematicRunner
            .runSchematicAsync("ng-add", { project: "default", contractName: 'gasLess', test: true, demoToInstall: false, addOns: [], dappDemo: "minimalContract" }, appTree)
            .toPromise();
        expect(tree.exists((0, core_1.normalize)("/projects/schematest/src/app/0-minimal-contract/minimal-contract.module.ts"))).toBeTrue();
    }));
    it("Creates Hardhat Config File", () => __awaiter(void 0, void 0, void 0, function* () {
        const tree = yield schematicRunner
            .runSchematicAsync("ng-add", { project: "default", test: true, demoToInstall: true, addOns: [], dappDemo: "helloWorldContract" }, appTree)
            .toPromise();
        expect(tree.exists("hardhat/hardhat.config.ts")).toBeTrue();
    }));
    it("Creates Contract JSON Config File", () => __awaiter(void 0, void 0, void 0, function* () {
        const tree = yield schematicRunner
            .runSchematicAsync("ng-add", { project: "default", test: true, demoToInstall: true, addOns: [], dappDemo: "helloWorldContract" }, appTree)
            .toPromise();
        expect(tree.exists("hardhat/contract.config.json")).toBeTrue();
    }));
    // it("Update the polyfills", async () => {
    //   const tree = await schematicRunner
    //     .runSchematicAsync("ng-add",  { project: "default", test:true,demoToInstall:false, addOns:[],dappDemo: "minimalContract" }, appTree)
    //     .toPromise();
    //     console.log(tree.files)
    //   const polyfills = tree.readContent("/projects/schematest/src/polyfills.ts");;
    //   expect(polyfills).toContain("require('process')")
    // });
    it("Should add Injector module ", () => __awaiter(void 0, void 0, void 0, function* () {
        const tree = yield schematicRunner
            .runSchematicAsync("ng-add", { project: "default", test: true, demoToInstall: true, addOns: [], dappDemo: "helloWorldContract" }, appTree)
            .toPromise();
        const app_module_file = tree.readContent("/projects/schematest/src/app/app.module.ts");
        expect(app_module_file).toContain("DappInjectorModule");
    }));
    it("Add dependencies", () => __awaiter(void 0, void 0, void 0, function* () {
        const tree = yield schematicRunner
            .runSchematicAsync("ng-add", { project: "default", test: true, demoToInstall: true, addOns: [], dappDemo: "helloWorldContract" }, appTree)
            .toPromise();
        const packageJson = tree.read("package.json").toString("utf-8");
        expect(packageJson).toContain("\"hardhat\":");
    }));
    it("Add scripts", () => __awaiter(void 0, void 0, void 0, function* () {
        const tree = yield schematicRunner
            .runSchematicAsync("ng-add", { project: "default", test: true, demoToInstall: true, addOns: [], dappDemo: "helloWorldContract" }, appTree)
            .toPromise();
        const packageJson = tree.read("package.json").toString("utf-8");
        expect(packageJson).toContain(`"compile": "cd hardhat && npx hardhat --tsconfig ./tsconfig.hardhat.json compile"`);
    }));
    // it("It adds fonts to index.html", async () => {
    //   const tree = await schematicRunner
    //     .runSchematicAsync("ng-add",  { project: "default", test:true,demoToInstall:true, addOns:[],dappDemo: "helloWorldContract" }, appTree)
    //     .toPromise();
    //     const indexHtml = tree.read(normalize("/projects/schematest/src/index.html"))!.toString("utf-8");
    //     expect(indexHtml).toContain(`<link href="https://fonts.googleapis.com/icon?family=Material+Icons" rel="stylesheet">`);
    // });
    it("No Demo app should install Mnimal Module", () => __awaiter(void 0, void 0, void 0, function* () {
        const tree = yield schematicRunner
            .runSchematicAsync("ng-add", { project: "default", uiFramework: "primeNG", test: true, demoToInstall: false, addOns: [], dappDemo: "minimalContract" }, appTree)
            .toPromise();
        expect(tree.exists((0, core_1.normalize)("/projects/schematest/src/app/0-minimal-contract/minimal-contract.module.ts"))).toBeTrue();
    }));
    it("Hello app creates Hello world chain module", () => __awaiter(void 0, void 0, void 0, function* () {
        const tree = yield schematicRunner
            .runSchematicAsync("ng-add", { project: "default", test: true, demoToInstall: true, addOns: [], dappDemo: "helloWorldContract" }, appTree)
            .toPromise();
        expect(tree.exists((0, core_1.normalize)("/projects/schematest/src/app/1-hello-world-contract/hello-world-contract.module.ts"))).toBeTrue();
    }));
    it("Debug app creates Debug world  module", () => __awaiter(void 0, void 0, void 0, function* () {
        const tree = yield schematicRunner
            .runSchematicAsync("ng-add", { project: "default", test: true, demoToInstall: true, addOns: [], dappDemo: "debugContract" }, appTree)
            .toPromise();
        expect(tree.exists((0, core_1.normalize)("/projects/schematest/src/app/2-debug-contract/debug-contract.module.ts"))).toBeTrue();
    }));
    it("NFT Demo app creates NFT world  module", () => __awaiter(void 0, void 0, void 0, function* () {
        const tree = yield schematicRunner
            .runSchematicAsync("ng-add", { project: "default", test: true, demoToInstall: true, addOns: [], dappDemo: "nftContract" }, appTree)
            .toPromise();
        expect(tree.exists((0, core_1.normalize)("/projects/schematest/src/app/3-nft-contract/nft-contract.module.ts"))).toBeTrue();
    }));
    it("NFT Demo creates custom webpack", () => __awaiter(void 0, void 0, void 0, function* () {
        const tree = yield schematicRunner
            .runSchematicAsync("ng-add", { project: "default", test: true, demoToInstall: true, addOns: [], dappDemo: "nftContract" }, appTree)
            .toPromise();
        expect(tree.exists((0, core_1.normalize)("extra-webpack.config.js"))).toBeTrue();
    }));
});
//# sourceMappingURL=initialization_tests.js.map