|
| 1 | +/// <reference path=".d.ts" /> |
| 2 | +"use strict"; |
| 3 | + |
| 4 | +import { Yok } from "../lib/common/yok"; |
| 5 | +import * as stubs from "./stubs"; |
| 6 | +import { CreateProjectCommand } from "../lib/commands/create-project"; |
| 7 | +import * as constants from "../lib/constants"; |
| 8 | +import {assert} from "chai"; |
| 9 | + |
| 10 | +let selectedTemplateName: string; |
| 11 | +let isProjectCreated: boolean; |
| 12 | +let dummyArgs = ["dummyArgsString"]; |
| 13 | + |
| 14 | +class ProjectServiceMock implements IProjectService { |
| 15 | + createProject(projectName: string, selectedTemplate?: string): IFuture<void> { |
| 16 | + return (() => { |
| 17 | + selectedTemplateName = selectedTemplate; |
| 18 | + isProjectCreated = true; |
| 19 | + }).future<void>()(); |
| 20 | + } |
| 21 | +} |
| 22 | + |
| 23 | +class ProjectNameValidatorMock implements IProjectNameValidator { |
| 24 | + public validate(name: string): boolean { |
| 25 | + return true; |
| 26 | + } |
| 27 | +} |
| 28 | + |
| 29 | +function createTestInjector() { |
| 30 | + let testInjector = new Yok(); |
| 31 | + |
| 32 | + testInjector.register("injector", testInjector); |
| 33 | + testInjector.register("staticConfig", {}); |
| 34 | + testInjector.register("projectService", ProjectServiceMock); |
| 35 | + testInjector.register("errors", stubs.ErrorsStub); |
| 36 | + testInjector.register("logger", stubs.LoggerStub); |
| 37 | + testInjector.register("projectNameValidator", ProjectNameValidatorMock); |
| 38 | + testInjector.register("options", { |
| 39 | + ng: false, |
| 40 | + template: undefined |
| 41 | + }); |
| 42 | + testInjector.register("createCommand", CreateProjectCommand); |
| 43 | + |
| 44 | + return testInjector; |
| 45 | +} |
| 46 | + |
| 47 | +describe("Project commands tests", () => { |
| 48 | + let testInjector: IInjector; |
| 49 | + let options: IOptions; |
| 50 | + let createProjectCommand: ICommand; |
| 51 | + |
| 52 | + beforeEach(() => { |
| 53 | + testInjector = createTestInjector(); |
| 54 | + isProjectCreated = false; |
| 55 | + selectedTemplateName = undefined; |
| 56 | + options = testInjector.resolve("$options"); |
| 57 | + createProjectCommand = testInjector.resolve("$createCommand"); |
| 58 | + }); |
| 59 | + |
| 60 | + describe("#CreateProjectCommand", () => { |
| 61 | + it("should not fail when using only --ng.", () => { |
| 62 | + options.ng = true; |
| 63 | + |
| 64 | + createProjectCommand.execute(dummyArgs).wait(); |
| 65 | + |
| 66 | + assert.isTrue(isProjectCreated); |
| 67 | + }); |
| 68 | + |
| 69 | + it("should not fail when using only --template.", () => { |
| 70 | + options.template = "ng"; |
| 71 | + |
| 72 | + createProjectCommand.execute(dummyArgs).wait(); |
| 73 | + |
| 74 | + assert.isTrue(isProjectCreated); |
| 75 | + }); |
| 76 | + |
| 77 | + it("should set the template name correctly when used --ng.", () => { |
| 78 | + options.ng = true; |
| 79 | + |
| 80 | + createProjectCommand.execute(dummyArgs).wait(); |
| 81 | + |
| 82 | + assert.deepEqual(selectedTemplateName, constants.ANGULAR_NAME); |
| 83 | + }); |
| 84 | + |
| 85 | + it("should not set the template name when --ng is not used.", () => { |
| 86 | + options.ng = false; |
| 87 | + |
| 88 | + createProjectCommand.execute(dummyArgs).wait(); |
| 89 | + |
| 90 | + assert.isUndefined(selectedTemplateName); |
| 91 | + }); |
| 92 | + |
| 93 | + it("should fail when --ng and --template are used simultaneously.", () => { |
| 94 | + options.ng = true; |
| 95 | + options.template = "ng"; |
| 96 | + |
| 97 | + assert.throws(() => { |
| 98 | + createProjectCommand.execute(dummyArgs).wait(); |
| 99 | + }); |
| 100 | + }); |
| 101 | + }); |
| 102 | +}); |
0 commit comments