-
-
Notifications
You must be signed in to change notification settings - Fork 134
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bumped dependency versions, extended window provider with new capabil…
…ities for focus/resize/move window (#540)
- Loading branch information
Showing
8 changed files
with
5,688 additions
and
4,552 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
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,68 @@ | ||
import { isSize, Size } from "./size.class"; | ||
|
||
describe("Size", () => { | ||
it("should calculate the correct area of a Size", () => { | ||
const size = new Size(100, 100); | ||
const expected = size.width * size.height; | ||
|
||
expect(size.area()).toEqual(expected); | ||
}); | ||
|
||
it("should return a proper string representation", () => { | ||
const size = new Size(100, 100); | ||
const expected = "(100x100)"; | ||
|
||
expect(size.toString()).toEqual(expected); | ||
}); | ||
|
||
describe("isSize typeguard", () => { | ||
it("should identify a Size object", () => { | ||
// GIVEN | ||
const s = new Size(100, 100); | ||
|
||
// WHEN | ||
const result = isSize(s); | ||
|
||
// THEN | ||
expect(result).toBeTruthy(); | ||
}); | ||
|
||
it("should rule out non-size objects", () => { | ||
// GIVEN | ||
const r = "foo"; | ||
|
||
// WHEN | ||
const result = isSize(r); | ||
|
||
// THEN | ||
expect(result).toBeFalsy(); | ||
}); | ||
|
||
it("should rule out possible object with missing properties", () => { | ||
// GIVEN | ||
const r = { | ||
width: 100, | ||
}; | ||
|
||
// WHEN | ||
const result = isSize(r); | ||
|
||
// THEN | ||
expect(result).toBeFalsy(); | ||
}); | ||
|
||
it("should rule out possible object with wrong property type", () => { | ||
// GIVEN | ||
const r = { | ||
width: "foo", | ||
height: 200, | ||
}; | ||
|
||
// WHEN | ||
const result = isSize(r); | ||
|
||
// THEN | ||
expect(result).toBeFalsy(); | ||
}); | ||
}); | ||
}); |
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,33 @@ | ||
export class Size { | ||
constructor( | ||
public width: number, | ||
public height: number, | ||
) {} | ||
|
||
public area() { | ||
return this.width * this.height; | ||
} | ||
|
||
public toString() { | ||
return `(${this.width}x${this.height})`; | ||
} | ||
} | ||
|
||
const testSize = new Size(100, 100); | ||
const sizeKeys = Object.keys(testSize); | ||
export function isSize(possibleSize: any): possibleSize is Size { | ||
if (typeof possibleSize !== "object") { | ||
return false; | ||
} | ||
for (const key of sizeKeys) { | ||
if (!(key in possibleSize)) { | ||
return false; | ||
} | ||
const possibleSizeKeyType = typeof possibleSize[key]; | ||
const sizeKeyType = typeof testSize[key as keyof typeof testSize]; | ||
if (possibleSizeKeyType !== sizeKeyType) { | ||
return false; | ||
} | ||
} | ||
return true; | ||
} |
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
Oops, something went wrong.