2017-05-22 20:59:12 +00:00
|
|
|
import { ContextPathSelectComponent, ContextChangeEvent } from './context-path-select.component';
|
2017-03-21 21:24:11 +00:00
|
|
|
|
|
|
|
|
|
|
|
describe("ContextPathSelectComponent", () => {
|
|
|
|
var component: ContextPathSelectComponent;
|
|
|
|
var currentContext: string;
|
|
|
|
var isValidContext: boolean;
|
|
|
|
var contexts: string[];
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
component = new ContextPathSelectComponent();
|
|
|
|
currentContext = '/';
|
|
|
|
isValidContext = false;
|
|
|
|
contexts = ['/'];
|
|
|
|
component.currentContext = currentContext;
|
|
|
|
component.isValidContext = isValidContext;
|
|
|
|
component.contexts = contexts;
|
|
|
|
});
|
|
|
|
|
2017-04-05 21:14:08 +00:00
|
|
|
describe("ngOnChanges", () => {
|
2017-03-21 21:24:11 +00:00
|
|
|
|
|
|
|
it("sets valid context flag to true if current context is valid", () => {
|
2017-04-05 21:14:08 +00:00
|
|
|
component.ngOnChanges({});
|
2017-03-21 21:24:11 +00:00
|
|
|
|
|
|
|
expect(component.isValidContext).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("sets valid context flag to false if current context is invalid", () => {
|
|
|
|
component.currentContext = "asdfdsf";
|
2017-04-05 21:14:08 +00:00
|
|
|
component.ngOnChanges({});
|
2017-03-21 21:24:11 +00:00
|
|
|
|
|
|
|
expect(component.isValidContext).toBe(false);
|
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2017-04-05 21:14:08 +00:00
|
|
|
describe("setContext", () => {
|
2017-03-21 21:24:11 +00:00
|
|
|
var newContext: string;
|
|
|
|
|
|
|
|
beforeEach(() => {
|
|
|
|
newContext = '/conf';
|
|
|
|
});
|
|
|
|
|
|
|
|
it("sets current context to given context", () => {
|
|
|
|
component.setContext(newContext);
|
|
|
|
|
|
|
|
expect(component.currentContext).toEqual(newContext);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("sets valid context flag to true if given context is valid", () => {
|
|
|
|
component.setContext(newContext);
|
|
|
|
|
|
|
|
expect(component.isValidContext).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("sets valid context flag to false if given context is invalid", () => {
|
|
|
|
component.setContext("asdfsadfs");
|
|
|
|
|
|
|
|
expect(component.isValidContext).toBe(false);
|
|
|
|
});
|
2017-05-22 20:59:12 +00:00
|
|
|
|
|
|
|
it("emits output event indicating build context changed", (done) => {
|
|
|
|
component.contextChanged.subscribe((event: ContextChangeEvent) => {
|
|
|
|
expect(event.contextDir).toEqual(newContext);
|
|
|
|
expect(event.isValid).toEqual(component.isValidContext);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
component.setContext(newContext);
|
|
|
|
});
|
2017-03-21 21:24:11 +00:00
|
|
|
});
|
|
|
|
|
2017-04-05 21:14:08 +00:00
|
|
|
describe("setSelectedContext", () => {
|
2017-05-22 20:59:12 +00:00
|
|
|
var newContext: string;
|
2017-03-21 21:24:11 +00:00
|
|
|
|
|
|
|
beforeEach(() => {
|
2017-05-22 20:59:12 +00:00
|
|
|
newContext = '/conf';
|
2017-03-21 21:24:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("sets current context to given context", () => {
|
2017-05-22 20:59:12 +00:00
|
|
|
component.setSelectedContext(newContext);
|
2017-03-21 21:24:11 +00:00
|
|
|
|
2017-05-22 20:59:12 +00:00
|
|
|
expect(component.currentContext).toEqual(newContext);
|
2017-03-21 21:24:11 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
it("sets valid context flag to true if given context is valid", () => {
|
2017-05-22 20:59:12 +00:00
|
|
|
component.setSelectedContext(newContext);
|
2017-03-21 21:24:11 +00:00
|
|
|
|
|
|
|
expect(component.isValidContext).toBe(true);
|
|
|
|
});
|
|
|
|
|
|
|
|
it("sets valid context flag to false if given context is invalid", () => {
|
|
|
|
component.setSelectedContext("a;lskjdf;ldsa");
|
|
|
|
|
|
|
|
expect(component.isValidContext).toBe(false);
|
|
|
|
});
|
2017-05-22 20:59:12 +00:00
|
|
|
|
|
|
|
it("emits output event indicating build context changed", (done) => {
|
|
|
|
component.contextChanged.subscribe((event: ContextChangeEvent) => {
|
|
|
|
expect(event.contextDir).toEqual(newContext);
|
|
|
|
expect(event.isValid).toEqual(component.isValidContext);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
|
|
|
|
component.setSelectedContext(newContext);
|
|
|
|
});
|
2017-03-21 21:24:11 +00:00
|
|
|
});
|
|
|
|
});
|