"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = require("path");
const testing_1 = require("@angular-devkit/schematics/testing");
const schematics_1 = require("@angular-devkit/schematics");
const test_utils_1 = require("../../test-utils");
const utils_1 = require("../../utils");
const ts_utils_1 = require("../../ts-utils");
describe('Master-detail schematic', () => {
    const master = 'heroes';
    const detail = 'hero';
    const project = 'some-project';
    const importPrefix = '@src';
    const masterClassName = utils_1.toComponentClassName(master);
    const detailClassName = utils_1.toComponentClassName(detail + "Detail");
    const defaultOptions = {
        master,
        detail,
        project,
    };
    const schematicRunner = new testing_1.SchematicTestRunner('nativescript-schematics', path_1.join(__dirname, '../../collection.json'));
    let appTree;
    describe('When in {N}-only project', () => {
        beforeEach(() => {
            appTree = new testing_1.UnitTestTree(new schematics_1.HostTree);
            appTree = test_utils_1.createEmptyNsOnlyProject(project);
            appTree = schematicRunner.runSchematic('master-detail', Object.assign({}, defaultOptions), appTree);
        });
        it('should create all necessary files', () => {
            const { files } = appTree;
            expect(files).toContain(`/app/${master}/${master}.module.ts`);
            expect(files).toContain(`/app/${master}/data.service.ts`);
            expect(files).toContain(`/app/${master}/${detail}-detail/${detail}-detail.component.ts`);
            expect(files).toContain(`/app/${master}/${detail}-detail/${detail}-detail.component.html`);
            expect(files).toContain(`/app/${master}/${master}/${master}.component.ts`);
            expect(files).toContain(`/app/${master}/${master}/${master}.component.html`);
        });
    });
    describe('When in web+{N} project', () => {
        beforeEach(() => {
            appTree = new testing_1.UnitTestTree(new schematics_1.HostTree);
            appTree = test_utils_1.createEmptySharedProject(project);
            appTree = schematicRunner.runSchematic('master-detail', Object.assign({}, defaultOptions), appTree);
        });
        it('should create all necessary files', () => {
            const { files } = appTree;
            expect(files).toContain(`/src/app/${master}/${master}.module.tns.ts`);
            expect(files).toContain(`/src/app/${master}/${master}.module.ts`);
            expect(files).toContain(`/src/app/${master}/${master}.common.ts`);
            expect(files).toContain(`/src/app/${master}/data.service.ts`);
            expect(files).toContain(`/src/app/${master}/${detail}-detail/${detail}-detail.component.ts`);
            expect(files).toContain(`/src/app/${master}/${detail}-detail/${detail}-detail.component.html`);
            expect(files).toContain(`/src/app/${master}/${detail}-detail/${detail}-detail.component.tns.html`);
            expect(files).toContain(`/src/app/${master}/${master}/${master}.component.ts`);
            expect(files).toContain(`/src/app/${master}/${master}/${master}.component.html`);
            expect(files).toContain(`/src/app/${master}/${master}/${master}.component.tns.html`);
        });
        it('should import the components in common module using @src', () => {
            const source = ts_utils_1.getSourceFile(appTree, `/src/app/${master}/${master}.common.ts`);
            const masterImports = ts_utils_1.findImports(masterClassName, source);
            expect(masterImports.length).toEqual(1);
            expect(masterImports[0].getFullText()).toContain(`${importPrefix}/app/${master}/${master}/${master}.component`);
            const detailImports = ts_utils_1.findImports(detailClassName, source);
            expect(detailImports.length).toEqual(1);
            expect(detailImports[0].getFullText()).toContain(`${importPrefix}/app/${master}/${detail}-detail/${detail}-detail.component`);
        });
    });
});
//# sourceMappingURL=index_spec.js.map