"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 test_1 = require("@schematics/angular/utility/test");
const path = require("path");
const test_utils_1 = require("../../test-utils");
describe('Application Schematic', () => {
    const schematicRunner = new testing_1.SchematicTestRunner('@nativescript/schematics', path.join(__dirname, '../../collection.json'));
    const defaultOptions = {
        name: 'foo',
        prefix: '',
        sourceDir: 'app',
        style: 'css',
        theme: true,
        webpack: true,
    };
    it('should create all files of an application', () => __awaiter(void 0, void 0, void 0, function* () {
        const options = Object.assign({}, defaultOptions);
        const tree = yield schematicRunner.runSchematicAsync('application', options).toPromise();
        const files = tree.files;
        expect(files).toContain('/foo/angular.json');
        expect(files).toContain('/foo/ngcc.config.js');
        expect(files).toContain('/foo/nsconfig.json');
        expect(files).toContain('/foo/.gitignore');
        expect(files).toContain('/foo/package.json');
        expect(files).toContain('/foo/tsconfig.json');
        expect(files).toContain('/foo/app/app.css');
        expect(files).toContain('/foo/app/package.json');
        expect(files).toContain('/foo/app/main.ts');
        expect(files).toContain('/foo/app/app.module.ts');
        expect(files).toContain('/foo/app/app.component.ts');
        expect(files).toContain('/foo/app/home/home.component.ts');
        expect(files).toContain('/foo/app/home/home.component.html');
        expect(files).toContain('/foo/app/home/home.component.css');
    }));
    it('should create root NgModule with bootstrap information', () => __awaiter(void 0, void 0, void 0, function* () {
        const options = Object.assign({}, defaultOptions);
        const tree = yield schematicRunner.runSchematicAsync('application', options).toPromise();
        const content = test_1.getFileContent(tree, '/foo/app/app.module.ts');
        expect(content).toMatch(test_utils_1.isInModuleMetadata('AppModule', 'bootstrap', 'AppComponent', true));
        expect(content).toMatch(test_utils_1.isInModuleMetadata('AppModule', 'declarations', 'AppComponent', true));
        expect(content).toMatch(test_utils_1.isInModuleMetadata('AppModule', 'imports', 'NativeScriptModule', true));
        expect(content).toMatch('import { NativeScriptModule } from \'@nativescript/angular\'');
        expect(content).toMatch('import { AppComponent } from \'./app.component\'');
    }));
    it('should handle a different sourceDir', () => {
        const options = Object.assign(Object.assign({}, defaultOptions), { sourceDir: 'some/custom/path' });
        let tree = null;
        expect(() => tree = schematicRunner
            .runSchematic('application', options))
            .not.toThrow();
        if (tree) {
            const files = tree.files;
            expect(files).toContain('/foo/tsconfig.json');
            expect(files).toContain('/foo/some/custom/path/app.module.ts');
        }
    });
    it('should handle the theme flag', () => {
        const options = Object.assign(Object.assign({}, defaultOptions), { theme: false });
        const tree = schematicRunner.runSchematic('application', options);
        const appComponent = '/foo/app/app.component.ts';
        expect(test_1.getFileContent(tree, appComponent))
            .not
            .toMatch(new RegExp('class="h1 text-center"'));
        expect(test_1.getFileContent(tree, appComponent))
            .not
            .toMatch(new RegExp('class="btn btn-primary btn-active"'));
        expect(test_1.getFileContent(tree, appComponent))
            .not
            .toMatch(new RegExp('class="h2 text-center"'));
    });
    it('should handle the webpack flag', () => {
        const options = Object.assign(Object.assign({}, defaultOptions), { webpack: false });
        const tree = schematicRunner.runSchematic('application', options);
        const packageJson = '/foo/package.json';
        expect(test_1.getFileContent(tree, packageJson))
            .not
            .toMatch(new RegExp('@ngtools/webpack'));
        const files = tree.files;
        expect(files).not.toContain('/foo/webpack.config.js');
    });
    it('should generate correct files when different style extension is specified', () => {
        const options = Object.assign(Object.assign({}, defaultOptions), { style: 'scss' });
        const tree = schematicRunner.runSchematic('application', options);
        const files = tree.files;
        expect(files).not.toContain('/foo/app/app.css');
        expect(files).toContain('/foo/app/app.android.scss');
        expect(files).toContain('/foo/app/app.ios.scss');
        expect(files).not.toContain('/foo/app/home/home.component.css');
        expect(files).toContain('/foo/app/home/home.component.scss');
    });
});
//# sourceMappingURL=index_spec.js.map