"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 schematics_1 = require("@angular-devkit/schematics");
const testing_1 = require("@nstudio/xplat/testing");
const testing_2 = require("../../utils/testing");
describe('app', () => {
    let appTree;
    const defaultOptions = {
        name: 'foo',
        npmScope: 'testing',
        prefix: 'tt',
    };
    beforeEach(() => {
        appTree = schematics_1.Tree.empty();
        appTree = testing_1.createEmptyWorkspace(appTree);
    });
    it('should create all files of an app', () => __awaiter(void 0, void 0, void 0, function* () {
        const options = Object.assign({}, defaultOptions);
        // console.log('appTree:', appTree);
        const tree = yield testing_2.runSchematic('app', options, appTree);
        const files = tree.files;
        // console.log(files);
        expect(files.indexOf('/apps/nativescript-foo/.gitignore')).toBeGreaterThanOrEqual(0);
        expect(files.indexOf('/apps/nativescript-foo/package.json')).toBeGreaterThanOrEqual(0);
        expect(files.indexOf('/apps/nativescript-foo/references.d.ts')).toBeGreaterThanOrEqual(0);
        expect(files.indexOf('/apps/nativescript-foo/tsconfig.json')).toBeGreaterThanOrEqual(0);
        // tools
        expect(files.indexOf('/apps/nativescript-foo/tools/xplat-postinstall.js')).toBeGreaterThanOrEqual(0);
        // source dir
        expect(files.indexOf('/apps/nativescript-foo/src/app-root.xml')).toBeGreaterThanOrEqual(0);
        expect(files.indexOf('/apps/nativescript-foo/src/app.css')).toBeGreaterThanOrEqual(0);
        expect(files.indexOf('/apps/nativescript-foo/src/app.ts')).toBeGreaterThanOrEqual(0);
        expect(files.indexOf('/apps/nativescript-foo/src/main-page.ts')).toBeGreaterThanOrEqual(0);
        // xplat file defaults
        expect(files.indexOf('/libs/xplat/nativescript/core/src/lib/index.ts')).toBe(-1);
    }));
    it('should create all files of an app using groupByName', () => __awaiter(void 0, void 0, void 0, function* () {
        const options = Object.assign({}, defaultOptions);
        options.groupByName = true;
        // console.log('appTree:', appTree);
        const tree = yield testing_2.runSchematic('app', options, appTree);
        const files = tree.files;
        // console.log(files);
        expect(files.indexOf('/apps/foo-nativescript/.gitignore')).toBeGreaterThanOrEqual(0);
        expect(files.indexOf('/apps/foo-nativescript/package.json')).toBeGreaterThanOrEqual(0);
        expect(files.indexOf('/apps/foo-nativescript/references.d.ts')).toBeGreaterThanOrEqual(0);
        expect(files.indexOf('/apps/foo-nativescript/tsconfig.json')).toBeGreaterThanOrEqual(0);
        // tools
        expect(files.indexOf('/apps/foo-nativescript/tools/xplat-postinstall.js')).toBeGreaterThanOrEqual(0);
        const packageFile = testing_1.getFileContent(tree, 'package.json');
        // console.log(packageFile)
    }));
    it('should create all files for app in directory', () => __awaiter(void 0, void 0, void 0, function* () {
        const options = Object.assign({}, defaultOptions);
        options.directory = 'frontend';
        const tree = yield testing_2.runSchematic('app', options, appTree);
        // const files = tree.files;
        // console.log(files);
        expect(tree.exists('/apps/frontend/nativescript-foo/package.json')).toBeTruthy();
    }));
    it('should create all files for app in directory and ignore platform naming when directory is a platform', () => __awaiter(void 0, void 0, void 0, function* () {
        const options = Object.assign({}, defaultOptions);
        options.directory = 'nativescript';
        const tree = yield testing_2.runSchematic('app', options, appTree);
        // const files = tree.files;
        // console.log(files);
        expect(tree.exists('/apps/nativescript/foo/package.json')).toBeTruthy();
    }));
});
