-
-
Notifications
You must be signed in to change notification settings - Fork 195
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Simplified creating angular template project #1638
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
/// <reference path=".d.ts" /> | ||
"use strict"; | ||
|
||
import * as yok from "../lib/common/yok"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can use: import { Yok } from "../lib/common/yok"; and define it as |
||
import * as stubs from "./stubs"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can use: import { LoggerStub, ErrorsStub } from "./stubs"; and use them directly later in your code |
||
import { CreateProjectCommand } from "../lib/commands/create-project"; | ||
import * as constants from "../lib/constants"; | ||
import {assert} from "chai"; | ||
|
||
let selectedTemplateName: string; | ||
let isProjectCreated: boolean; | ||
let dummyArgsString = "dummyArgsString"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can define this as array: let dummyArgs = [ "dummyString" ]; and use it later as: createProjectCommand.execute(dummyArgsString).wait(); |
||
|
||
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.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 Service Tests', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are testing just the command, not the project Service itself, so you do not need this |
||
let testInjector: IInjector; | ||
|
||
beforeEach(() => { | ||
testInjector = createTestInjector(); | ||
isProjectCreated = false; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. set |
||
}); | ||
|
||
describe("project commands tests", () => { | ||
describe("#CreateProjectCommand", () => { | ||
it("should not fail when using only --ng.", () => { | ||
let options: IOptions = testInjector.resolve("$options"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this line is used in all tests, consider moving it to |
||
options.ng = true; | ||
|
||
let createProjectCommand: ICommand = testInjector.resolve("$createCommand"); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this line is used in all tests, consider moving it to |
||
|
||
createProjectCommand.execute([dummyArgsString]).wait(); | ||
|
||
assert.isTrue(isProjectCreated); | ||
}); | ||
|
||
it("should not fail when using only --template.", () => { | ||
let options: IOptions = testInjector.resolve("$options"); | ||
options.template = "ng"; | ||
|
||
let createProjectCommand: ICommand = testInjector.resolve("$createCommand"); | ||
|
||
createProjectCommand.execute([dummyArgsString]).wait(); | ||
|
||
assert.isTrue(isProjectCreated); | ||
}); | ||
|
||
it("should set the template name correctly when used --ng.", () => { | ||
let options: IOptions = testInjector.resolve("$options"); | ||
options.ng = true; | ||
|
||
let createProjectCommand: ICommand = testInjector.resolve("$createCommand"); | ||
|
||
createProjectCommand.execute([dummyArgsString]).wait(); | ||
|
||
assert.deepEqual(options.template, constants.ANGULAR_NAME); | ||
}); | ||
|
||
it("should not set the template name when --ng is not used.", () => { | ||
let options: IOptions = testInjector.resolve("$options"); | ||
options.ng = false; | ||
|
||
let createProjectCommand: ICommand = testInjector.resolve("$createCommand"); | ||
|
||
createProjectCommand.execute([dummyArgsString]).wait(); | ||
|
||
assert.isUndefined(options.template); | ||
}); | ||
|
||
it("should fail when --ng and --template are used simultaneously.", () => { | ||
let options: IOptions = testInjector.resolve("$options"); | ||
options.ng = true; | ||
options.template = "ng"; | ||
|
||
let createProjectCommand: ICommand = testInjector.resolve("$createCommand"); | ||
|
||
assert.throws(() => { | ||
createProjectCommand.execute([dummyArgsString]).wait(); | ||
}); | ||
}); | ||
}); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
instead of setting
this.$options.template
you can use something like: