"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 path = require("path");
// tslint:disable:no-implicit-dependencies
const schematics_1 = require("@angular-devkit/schematics");
// tslint:disable-next-line:no-submodule-imports
const testing_1 = require("@angular-devkit/schematics/testing");
describe("Update 3.0.0", () => {
    let appTree;
    const schematicRunner = new testing_1.SchematicTestRunner("ig-migrate", path.join(__dirname, "../migration-collection.json"));
    beforeEach(() => {
        appTree = new testing_1.UnitTestTree(new schematics_1.EmptyTree());
    });
    it("should add ig-typography class to body if needed", (done) => __awaiter(void 0, void 0, void 0, function* () {
        const indexFile = "/src/index.html";
        appTree.create(indexFile, `<body>
<app-root></app-root>
</body>`);
        yield schematicRunner.runSchematicAsync("migration-02", {}, appTree).toPromise();
        expect(appTree.readContent(indexFile))
            .toEqual(`<body class="ig-typography">
<app-root></app-root>
</body>`);
        appTree.overwrite(indexFile, `<body class="">`);
        yield schematicRunner.runSchematicAsync("migration-02", {}, appTree).toPromise();
        expect(appTree.readContent(indexFile)).toEqual(`<body class="ig-typography">`);
        appTree.overwrite(indexFile, `<body class="test class">`);
        yield schematicRunner.runSchematicAsync("migration-02", {}, appTree).toPromise();
        expect(appTree.readContent(indexFile)).toEqual(`<body class="test class ig-typography">`);
        appTree.overwrite(indexFile, `<body class="test ig-typography">`);
        yield schematicRunner.runSchematicAsync("migration-02", {}, appTree).toPromise();
        expect(appTree.readContent(indexFile)).toEqual(`<body class="test ig-typography">`);
        done();
    }));
    it("should add additional header styles to home css", (done) => __awaiter(void 0, void 0, void 0, function* () {
        const cssFile = "/src/app/home/home.component.css";
        appTree.create(cssFile, `body {
  height: 100%;
}
`);
        yield schematicRunner.runSchematicAsync("migration-02", {}, appTree).toPromise();
        expect(appTree.readContent(cssFile))
            .toEqual(`body {
  height: 100%;
}

h1 {
  font-size: 3rem;
  font-weight: 600;
  color: rgba(0, 0, 0, .74);
}

h3 {
  font-size: 1.75rem;
  font-weight: 600;
}
`);
        done();
    }));
    it("should remove forRoot() from IgxGridModule", (done) => __awaiter(void 0, void 0, void 0, function* () {
        const indexFile = "/src/app/app.module.ts";
        appTree.create(indexFile, `@NgModule({
  imports: [
   IgxGridModule.forRoot(),
   IgxRippleModule
  ]
})`);
        yield schematicRunner.runSchematicAsync("migration-02", {}, appTree).toPromise();
        expect(appTree.readContent(indexFile))
            .toEqual(`@NgModule({
  imports: [
   IgxGridModule,
   IgxRippleModule
  ]
})`);
        done();
    }));
    it("should update config", (done) => __awaiter(void 0, void 0, void 0, function* () {
        const indexFile = "ignite-ui-cli.json";
        appTree.create(indexFile, `{
    "version": "",
    "project": {
        "framework": "angular",
        "projectType": "igx-ts",
        "projectTemplate": ""
    },
    "packagesInstalled": true
}`);
        yield schematicRunner.runSchematicAsync("migration-02", {}, appTree).toPromise();
        expect(appTree.readContent(indexFile))
            .toEqual(`{
    "version": "3.0.0",
    "project": {
        "framework": "angular",
        "projectType": "igx-ts",
        "projectTemplate": "side-nav"
    },
    "packagesInstalled": true
}
`);
        done();
    }));
});
