Skip to content

Ts all the tests#1998

Merged
balloob merged 8 commits intodevfrom
ts-tests
Nov 6, 2018
Merged

Ts all the tests#1998
balloob merged 8 commits intodevfrom
ts-tests

Conversation

@balloob
Copy link
Copy Markdown
Member

@balloob balloob commented Nov 5, 2018

Convert our tests to TypeScript to unblock #680

@ghost ghost assigned balloob Nov 5, 2018
@ghost ghost added the in progress label Nov 5, 2018
@@ -1,4 +1,4 @@
const leftPad = (number) => (number < 10 ? `0${number}` : number);
const leftPad = (num) => (num < 10 ? `0${num}` : num);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

types?

@@ -1,7 +1,7 @@
/** Return an icon representing a binary sensor state. */

export default function binarySensorIcon(state) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

state: HassEntity


export default function coverIcon(state) {
var open = state.state && state.state !== "closed";
export default function coverIcon(state: HassEntity) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return type : string?

};

export default function domainIcon(domain, state) {
export default function domainIcon(domain: string, state?: string) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return type : string

// Return an ordered array of available views
export default function extractViews(entities) {
const views = [];
export default function extractViews(entities: HassEntities) {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

return type : HassEntity[]

return message + (args.length ? ": " + args.join(",") : "");
};
// Mock Localize function for testing
const localize = (message, ...args) =>
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

message: string

it("Localizes binary sensor invalid device class", () => {
const altLocalize = function(message, ...args) {
if (message === "state.binary_sensor.invalid_device_class.off")
const altLocalize = (message, ...args) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

message: string

it("Localizes unknown sensor value with units", () => {
const altLocalize = function(message, ...args) {
if (message === "state.sensor.unknown") return null;
const altLocalize = (message, ...args) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

message: string

it("Localizes unavailable sensor value with units", () => {
const altLocalize = function(message, ...args) {
if (message === "state.sensor.unavailable") return null;
const altLocalize = (message, ...args) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

message: string

it("Localizes sensor value with component translation", () => {
const altLocalize = function(message, ...args) {
if (message !== "component.sensor.state.custom_state") return null;
const altLocalize = (message, ...args) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

message: string

it("Localizes unavailable", () => {
const altLocalize = function(message, ...args) {
if (message === "state.sensor.unavailable") return null;
const altLocalize = (message, ...args) => {
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

message: string

@iantrich
Copy link
Copy Markdown
Member

iantrich commented Nov 5, 2018

Looking over other people's changes is hard! 😃

@balloob
Copy link
Copy Markdown
Member Author

balloob commented Nov 6, 2018

You're right Ian, I went lazy and didn't add types to all methods, guess I converted too many 🤷‍♂️ Anyway, new day, new changes and just spend some time polishing this PR and adding the types.

@balloob
Copy link
Copy Markdown
Member Author

balloob commented Nov 6, 2018

For the types in the test file: they are really just for tests and don't need to have extensive typing. I've used a bunch of any to get it to pass.

@balloob balloob merged commit cdb2093 into dev Nov 6, 2018
@balloob balloob deleted the ts-tests branch November 6, 2018 09:09
@ghost ghost removed the in progress label Nov 6, 2018
@github-actions github-actions bot locked and limited conversation to collaborators Jul 7, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants