-
-
Notifications
You must be signed in to change notification settings - Fork 195
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1638 from NativeScript/milanov/add-angular-and-ng…
…-template-parameters Simplified creating angular template project
- Loading branch information
Showing
10 changed files
with
172 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
/// <reference path=".d.ts" /> | ||
"use strict"; | ||
|
||
import { Yok } from "../lib/common/yok"; | ||
import * as stubs from "./stubs"; | ||
import { CreateProjectCommand } from "../lib/commands/create-project"; | ||
import * as constants from "../lib/constants"; | ||
import {assert} from "chai"; | ||
|
||
let selectedTemplateName: string; | ||
let isProjectCreated: boolean; | ||
let dummyArgs = ["dummyArgsString"]; | ||
|
||
class ProjectServiceMock implements IProjectService { | ||
createProject(projectName: string, selectedTemplate?: string): IFuture<void> { | ||
return (() => { | ||
selectedTemplateName = selectedTemplate; | ||
isProjectCreated = true; | ||
}).future<void>()(); | ||
} | ||
} | ||
|
||
class ProjectNameValidatorMock implements IProjectNameValidator { | ||
public validate(name: string): boolean { | ||
return true; | ||
} | ||
} | ||
|
||
function createTestInjector() { | ||
let testInjector = new Yok(); | ||
|
||
testInjector.register("injector", testInjector); | ||
testInjector.register("staticConfig", {}); | ||
testInjector.register("projectService", ProjectServiceMock); | ||
testInjector.register("errors", stubs.ErrorsStub); | ||
testInjector.register("logger", stubs.LoggerStub); | ||
testInjector.register("projectNameValidator", ProjectNameValidatorMock); | ||
testInjector.register("options", { | ||
ng: false, | ||
template: undefined | ||
}); | ||
testInjector.register("createCommand", CreateProjectCommand); | ||
|
||
return testInjector; | ||
} | ||
|
||
describe("Project commands tests", () => { | ||
let testInjector: IInjector; | ||
let options: IOptions; | ||
let createProjectCommand: ICommand; | ||
|
||
beforeEach(() => { | ||
testInjector = createTestInjector(); | ||
isProjectCreated = false; | ||
selectedTemplateName = undefined; | ||
options = testInjector.resolve("$options"); | ||
createProjectCommand = testInjector.resolve("$createCommand"); | ||
}); | ||
|
||
describe("#CreateProjectCommand", () => { | ||
it("should not fail when using only --ng.", () => { | ||
options.ng = true; | ||
|
||
createProjectCommand.execute(dummyArgs).wait(); | ||
|
||
assert.isTrue(isProjectCreated); | ||
}); | ||
|
||
it("should not fail when using only --template.", () => { | ||
options.template = "ng"; | ||
|
||
createProjectCommand.execute(dummyArgs).wait(); | ||
|
||
assert.isTrue(isProjectCreated); | ||
}); | ||
|
||
it("should set the template name correctly when used --ng.", () => { | ||
options.ng = true; | ||
|
||
createProjectCommand.execute(dummyArgs).wait(); | ||
|
||
assert.deepEqual(selectedTemplateName, constants.ANGULAR_NAME); | ||
}); | ||
|
||
it("should not set the template name when --ng is not used.", () => { | ||
options.ng = false; | ||
|
||
createProjectCommand.execute(dummyArgs).wait(); | ||
|
||
assert.isUndefined(selectedTemplateName); | ||
}); | ||
|
||
it("should fail when --ng and --template are used simultaneously.", () => { | ||
options.ng = true; | ||
options.template = "ng"; | ||
|
||
assert.throws(() => { | ||
createProjectCommand.execute(dummyArgs).wait(); | ||
}); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters