-
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.
- Loading branch information
1 parent
dca8e38
commit 678a7a6
Showing
6 changed files
with
100 additions
and
30 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
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,49 @@ | ||
import { ResolveConstraint } from "./constraint"; | ||
import { ComponentInstance, Side, ConstraintInstance } from "./definition"; | ||
|
||
const ParentComponent = (): ComponentInstance => ({ | ||
name: "parent", | ||
positions: { | ||
[Side.top]: 0, | ||
[Side.right]: 100, | ||
[Side.bottom]: 100, | ||
[Side.left]: 0 | ||
} | ||
}); | ||
|
||
const NewComponent = (name: string, positions = {}): ComponentInstance => ({ | ||
name, | ||
positions | ||
}); | ||
|
||
describe("constraint resolving tests", () => { | ||
test("a resolved constraint doesn't do anything", () => { | ||
const testedComponent = NewComponent("nameX"); | ||
const constraint: ConstraintInstance = { | ||
fromInstance: testedComponent, | ||
fromSide: Side.top, | ||
toInstance: ParentComponent(), | ||
toSide: Side.top, | ||
resolved: Boolean(true), | ||
distance: 10 | ||
}; | ||
ResolveConstraint(constraint); | ||
expect(constraint.resolved).toBe(Boolean(true)); | ||
expect(testedComponent.positions[Side.top]).toBe(undefined); | ||
}); | ||
|
||
test("a simple constraint from parent", () => { | ||
const testedComponent = NewComponent("nameX"); | ||
const constraint: ConstraintInstance = { | ||
fromInstance: testedComponent, | ||
fromSide: Side.top, | ||
toInstance: ParentComponent(), | ||
toSide: Side.top, | ||
resolved: Boolean(false), | ||
distance: 10 | ||
}; | ||
ResolveConstraint(constraint); | ||
expect(constraint.resolved).toBe(Boolean(true)); | ||
expect(testedComponent.positions[Side.top]).toBe(10); | ||
}); | ||
}); |
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,14 @@ | ||
import { LayoutInstance } from "./generator"; | ||
import { Side, ConstraintSize, ConstraintInstance } from "./definition"; | ||
|
||
export const ResolveConstraint = (constraint: ConstraintInstance): void => { | ||
const { | ||
fromInstance, | ||
fromSide, | ||
toInstance, | ||
toSide, | ||
distance, | ||
resolved | ||
} = constraint; | ||
if (resolved) return; | ||
}; |
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 |
---|---|---|
@@ -1,19 +1,42 @@ | ||
export type ConstraintSize = number; | ||
|
||
export type ConstraintSide = "top" | "right" | "bottom" | "left"; | ||
export enum Side { | ||
top = "top", | ||
right = "right", | ||
bottom = "bottom", | ||
left = "left" | ||
} | ||
|
||
export interface ConstraintDefinition { | ||
component: string; | ||
side: ConstraintSide; | ||
side: keyof typeof Side; | ||
distance: ConstraintSize; | ||
} | ||
|
||
export interface ConstraintComponent { | ||
export interface ComponentDefinition { | ||
constraints: ConstraintDefinition[]; | ||
width?: ConstraintSize; | ||
height?: ConstraintSize; | ||
} | ||
|
||
export interface ConstraintLayout { | ||
[key: string]: ConstraintComponent; | ||
export interface LayoutDefinition { | ||
[key: string]: ComponentDefinition; | ||
} | ||
|
||
export interface ComponentInstance { | ||
name: string; | ||
positions: { [key in Side]?: number }; | ||
} | ||
|
||
export type ComponentInstances = ComponentInstance[]; | ||
|
||
export interface ConstraintInstance { | ||
fromInstance: ComponentInstance; | ||
fromSide: Side; | ||
toInstance: ComponentInstance; | ||
toSide: Side; | ||
distance: ConstraintSize; | ||
resolved: Boolean; | ||
} | ||
|
||
export type ConstraintInstances = ConstraintInstance[]; |
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