Commit c9a0af2e authored by Mark Stenglein's avatar Mark Stenglein
Browse files

Fix types errors ContentLine.spec.ts

- The changes to the API I made required that I fix this test file.

- This file still fails, I need to finish the lower level Parameter
  test file before I can be sure where the issue actually lies.

  - Ideally that will be the contents of the next few commits.
parent 8f06efaf
import ContentLine from "../src/ContentLine"; import ContentLine from "../src/ContentLine";
import Parameter from "../src/Parameter";
import { expect } from "chai"; import { expect } from "chai";
import "mocha"; import "mocha";
...@@ -15,7 +16,8 @@ describe("ContentLine", () => { ...@@ -15,7 +16,8 @@ describe("ContentLine", () => {
*/ */
describe("constructor", () => { describe("constructor", () => {
it("Should create an object", () => { it("Should create an object", () => {
const test: ContentLine = new ContentLine("name", ["param"], "value"); let param: Parameter = new Parameter("testParam", ["test1"]);
const test: ContentLine = new ContentLine("name", [param], "value");
let result: boolean = true; let result: boolean = true;
if (typeof test === undefined) { if (typeof test === undefined) {
...@@ -26,41 +28,46 @@ describe("ContentLine", () => { ...@@ -26,41 +28,46 @@ describe("ContentLine", () => {
}); });
it("Should have the same name as given on input", () => { it("Should have the same name as given on input", () => {
const param: Parameter = new Parameter("testParam", ["test1"]);
const test: string = "name"; const test: string = "name";
const testLine: ContentLine = new ContentLine(test, ["param"], "value"); const testLine: ContentLine = new ContentLine(test, [param], "value");
const result: string = testLine.name; const result: string = testLine.name;
expect(result).to.be.equal(test); expect(result).to.be.equal(test);
}); });
it("Should have the same param as given on input", () => { it("Should have the same param as given on input", () => {
const testParam1: string[] = ["param1"]; const testParam1: Parameter[] = [new Parameter("testParam", ["test1"])];
const testLine: ContentLine = new ContentLine("name", testParam1, "value"); const testLine: ContentLine = new ContentLine("name", testParam1, "value");
const result: string[] = testLine.params; const result: Parameter[] = testLine.params;
expect(result).to.be.deep.equal(testParam1); expect(result).to.be.deep.equal(testParam1);
}); });
it("Should accept multiple param values on input", () => { it("Should accept multiple param values on input", () => {
const testParams: string[] = ["param1", "param2"]; const param1: Parameter = new Parameter("param1", ["value1"]);
const param2: Parameter = new Parameter("param2", ["value2"]);
const testParams: Parameter[] = [param1, param2];
const testLine: ContentLine = new ContentLine("name", testParams, "value"); const testLine: ContentLine = new ContentLine("name", testParams, "value");
const result: string[] = testLine.params; const result: Parameter[] = testLine.params;
expect(result).to.be.deep.equal(testParams); expect(result).to.be.deep.equal(testParams);
}); });
it("Should accept no param values as input", () => { it("Should accept no param values as input", () => {
const testParams: string[] = []; const testParams: Parameter[] = [];
const testLine: ContentLine = new ContentLine("name", testParams, "value"); const testLine: ContentLine = new ContentLine("name", testParams, "value");
const result: string[] = testLine.params; const result: Parameter[] = testLine.params;
expect(result).to.be.deep.equal(testParams); expect(result).to.be.deep.equal(testParams);
}); });
it("Should have the same value as given on input", () => { it("Should have the same value as given on input", () => {
const testValue: string = "testValue"; const testValue: string = "testValue";
const testLine: ContentLine = new ContentLine("name", ["test"], testValue); const testParam: Parameter = new Parameter("name", [testValue]);
const result: string = testLine.value; const testLine: ContentLine = new ContentLine("name", [testParam], testValue);
const result: string = testLine.params[0].paramValues[0];
expect(result).to.be.equal(testValue); expect(result).to.be.equal(testValue);
}); });
...@@ -116,12 +123,15 @@ describe("ContentLine", () => { ...@@ -116,12 +123,15 @@ describe("ContentLine", () => {
describe("generate", () => { describe("generate", () => {
it("Should respond as non-static method", () => { it("Should respond as non-static method", () => {
expect(ContentLine).respondsTo('generate'); expect(ContentLine).respondsTo("generate");
}); });
it("Should generate properly formatted lines", () => { it("Should generate properly formatted lines", () => {
const test: ContentLine = new ContentLine("NAME", ["param1", "param2"], "value"); const param1: Parameter = new Parameter("PARAM-ONE", ["value1", "value2"])
const expected = "NAME;param1;param2:value" const param2: Parameter = new Parameter("PARAM-TWO", ["value1"])
const params: Parameter[] = [param1, param2];
const test: ContentLine = new ContentLine("NAME", params, "value");
const expected = "NAME;PARAM-ONE=value1,value2;PARAM-TWO=value1:value";
const result = test.generate(); const result = test.generate();
expect(result).to.be.equal(expected); expect(result).to.be.equal(expected);
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment