-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Modularize index + config checker (#6)
* Extract out of index different sub-functionnality into modules * Create a config checker module that make sure the different attribute are valid * Reset works for Log based widget * Changelog modification
- Loading branch information
Showing
13 changed files
with
410 additions
and
79 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
module.exports = class ConfigError extends Error { | ||
constructor(...args) { | ||
super(...args); | ||
Error.captureStackTrace(this, ConfigError); | ||
} | ||
}; |
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,27 @@ | ||
const calculateScreenSize = require("../calculateScreenSize"); | ||
|
||
describe("utils/calculateScreenSize", () => { | ||
it("find biggest number", () => { | ||
expect( | ||
calculateScreenSize({ | ||
widgets: [ | ||
{ | ||
col: 27, | ||
colspan: 1, | ||
row: 0, | ||
rowspan: 2 | ||
}, | ||
{ | ||
col: 12, | ||
colspan: 1, | ||
row: 1, | ||
rowspan: 2 | ||
} | ||
] | ||
}) | ||
).toEqual({ | ||
rows: 2, | ||
cols: 28 | ||
}); | ||
}); | ||
}); |
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,227 @@ | ||
const configChecker = require("../configChecker"); | ||
const RawLog = require("../../widgets/RawLog"); | ||
|
||
describe("utils/configChecker", () => { | ||
it("returns true when valud", () => { | ||
expect( | ||
configChecker({ | ||
source: "a", | ||
widgets: [ | ||
{ | ||
name: "colspan invalid", | ||
type: RawLog.CONFIG_TYPE, | ||
row: 1, | ||
col: 1, | ||
rowspan: 1, | ||
colspan: 1 | ||
} | ||
] | ||
}) | ||
).toBe(true); | ||
}); | ||
|
||
describe("source", () => { | ||
it("detect missing", () => { | ||
expect(() => { | ||
configChecker({}); | ||
}).toThrow("must contain a 'source' "); | ||
}); | ||
|
||
it("detect invalid", () => { | ||
expect(() => { | ||
configChecker({ source: 1 }); | ||
}).toThrow("must contain a 'source' "); | ||
}); | ||
}); | ||
describe("widgets", () => { | ||
it("detect missing", () => { | ||
expect(() => { | ||
configChecker({ source: "a" }); | ||
}).toThrow("must have at least 1 widget"); | ||
}); | ||
it("detect invalid", () => { | ||
expect(() => { | ||
configChecker({ source: "a", widgets: {} }); | ||
}).toThrow("must have at least 1 widget"); | ||
}); | ||
it("detect empty", () => { | ||
expect(() => { | ||
configChecker({ source: "a", widgets: [] }); | ||
}).toThrow("must have at least 1 widget"); | ||
}); | ||
}); | ||
|
||
describe("individual widget", () => { | ||
it("detect empty", () => { | ||
expect(() => { | ||
configChecker({ source: "a", widgets: [1] }); | ||
}).toThrow("is not an object"); | ||
}); | ||
describe("name", () => { | ||
it("detect missing", () => { | ||
expect(() => { | ||
configChecker({ source: "a", widgets: [{}] }); | ||
}).toThrow("missing the required attribute 'name'"); | ||
}); | ||
it("detect invalid ", () => { | ||
expect(() => { | ||
configChecker({ source: "a", widgets: [{ name: 1 }] }); | ||
}).toThrow("must be a string"); | ||
}); | ||
it("detect duplicate ", () => { | ||
expect(() => { | ||
configChecker({ | ||
source: "a", | ||
widgets: [ | ||
{ | ||
type: RawLog.CONFIG_TYPE, | ||
name: "Sonos App Error type", | ||
match: "<Error> ([a-z]+)", | ||
col: 3, | ||
colspan: 1, | ||
row: 0, | ||
rowspan: 2 | ||
}, | ||
{ | ||
type: RawLog.CONFIG_TYPE, | ||
name: "Sonos App Error type", | ||
match: "<Error> ([a-z]+)", | ||
col: 3, | ||
colspan: 1, | ||
row: 0, | ||
rowspan: 2 | ||
} | ||
] | ||
}); | ||
}).toThrow("Multiple widgets with name"); | ||
}); | ||
}); | ||
describe("type", () => { | ||
it("detect missing", () => { | ||
expect(() => { | ||
configChecker({ source: "a", widgets: [{ name: "1" }] }); | ||
}).toThrow("must have a type"); | ||
}); | ||
it("detect invalid ", () => { | ||
expect(() => { | ||
configChecker({ source: "a", widgets: [{ name: "1", type: "1" }] }); | ||
}).toThrow("an unknown type "); | ||
}); | ||
}); | ||
describe("row", () => { | ||
it("detect missing", () => { | ||
expect(() => { | ||
configChecker({ | ||
source: "a", | ||
widgets: [{ name: "1", type: RawLog.CONFIG_TYPE }] | ||
}); | ||
}).toThrow("missing required integer attribute 'row'"); | ||
}); | ||
it("detect invalid ", () => { | ||
expect(() => { | ||
configChecker({ | ||
source: "a", | ||
widgets: [{ name: "1", type: RawLog.CONFIG_TYPE, row: "a" }] | ||
}); | ||
}).toThrow("'row' must be an integer"); | ||
}); | ||
}); | ||
describe("col", () => { | ||
it("detect missing", () => { | ||
expect(() => { | ||
configChecker({ | ||
source: "a", | ||
widgets: [{ name: "1", type: RawLog.CONFIG_TYPE, row: 1 }] | ||
}); | ||
}).toThrow("missing required integer attribute 'col'"); | ||
}); | ||
it("detect invalid ", () => { | ||
expect(() => { | ||
configChecker({ | ||
source: "a", | ||
widgets: [{ name: "1", type: RawLog.CONFIG_TYPE, row: 1, col: "a" }] | ||
}); | ||
}).toThrow("'col' must be an integer"); | ||
}); | ||
}); | ||
describe("col", () => { | ||
it("detect missing", () => { | ||
expect(() => { | ||
configChecker({ | ||
source: "a", | ||
widgets: [{ name: "1", type: RawLog.CONFIG_TYPE, row: 1 }] | ||
}); | ||
}).toThrow("missing required integer attribute 'col'"); | ||
}); | ||
it("detect invalid ", () => { | ||
expect(() => { | ||
configChecker({ | ||
source: "a", | ||
widgets: [{ name: "1", type: RawLog.CONFIG_TYPE, row: 1, col: "a" }] | ||
}); | ||
}).toThrow("'col' must be an integer"); | ||
}); | ||
}); | ||
describe("rowspan", () => { | ||
it("detect missing", () => { | ||
expect(() => { | ||
configChecker({ | ||
source: "a", | ||
widgets: [{ name: "1", type: RawLog.CONFIG_TYPE, row: 1, col: 1 }] | ||
}); | ||
}).toThrow("missing required integer attribute 'rowspan'"); | ||
}); | ||
it("detect invalid ", () => { | ||
expect(() => { | ||
configChecker({ | ||
source: "a", | ||
widgets: [ | ||
{ | ||
name: "1", | ||
type: RawLog.CONFIG_TYPE, | ||
row: 1, | ||
col: 1, | ||
rowspan: "a" | ||
} | ||
] | ||
}); | ||
}).toThrow("'rowspan' must be an integer"); | ||
}); | ||
}); | ||
describe("colspan", () => { | ||
it("detect missing", () => { | ||
expect(() => { | ||
configChecker({ | ||
source: "a", | ||
widgets: [ | ||
{ | ||
name: "1", | ||
type: RawLog.CONFIG_TYPE, | ||
row: 1, | ||
col: 1, | ||
rowspan: 1 | ||
} | ||
] | ||
}); | ||
}).toThrow("missing required integer attribute 'colspan'"); | ||
}); | ||
it("detect invalid ", () => { | ||
expect(() => { | ||
configChecker({ | ||
source: "a", | ||
widgets: [ | ||
{ | ||
name: "colspan invalid", | ||
type: RawLog.CONFIG_TYPE, | ||
row: 1, | ||
col: 1, | ||
rowspan: 1, | ||
colspan: "a" | ||
} | ||
] | ||
}); | ||
}).toThrow("'colspan' must be an integer"); | ||
}); | ||
}); | ||
}); | ||
}); |
Oops, something went wrong.