-
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
e60f0be
commit 522dc27
Showing
6 changed files
with
551 additions
and
51 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,34 @@ | ||
import { describe } from 'mocha'; | ||
import { expect } from 'chai'; | ||
import { FlexComponent, Frame, Size, SourceComponent } from '@/layout'; | ||
|
||
describe('FlexContainer', () => { | ||
it('should layout vertically', () => { | ||
const component = new FlexComponent(); | ||
component.direction = 'vertical'; | ||
component.spacing = 10; | ||
|
||
const childA = new SourceComponent(); | ||
childA.size = new Size(100, 100); | ||
component.addChild(childA); | ||
|
||
const childB = new SourceComponent(); | ||
childB.size = new Size(100, 100); | ||
component.addChild(childB); | ||
|
||
const node = component.exerciseLayout(new Size(100, 210)); | ||
expect(node.frame).to.eql(new Frame(0, 0, 100, 210)); | ||
expect(node.isContainer).to.equal(true); | ||
expect(node.children.length).to.equal(2); | ||
|
||
const aNode = node.children[0]; | ||
const bNode = node.children[1]; | ||
expect(aNode.frame).to.eql(new Frame(0, 0, 100, 100)); | ||
expect(aNode.isContainer).to.equal(false); | ||
expect(aNode.children).to.eql([]); | ||
|
||
expect(bNode.frame).to.eql(new Frame(0, 110, 100, 100)); | ||
expect(bNode.isContainer).to.equal(false); | ||
expect(bNode.children).to.eql([]); | ||
}); | ||
}) |
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,23 @@ | ||
import { describe } from 'mocha'; | ||
import { expect } from 'chai'; | ||
import { Frame, InsetComponent, Size, SourceComponent } from '@/layout'; | ||
import Insets from '@/layout/Insets'; | ||
|
||
describe('InsetComponent', () => { | ||
it('should layout', () => { | ||
const component = new InsetComponent() | ||
component.insets = new Insets(10, 10, 10, 10); | ||
|
||
component.addChild(new SourceComponent()) | ||
|
||
const node = component.exerciseLayout(new Size(1920, 1080)); | ||
expect(node.frame).to.eql(new Frame(0, 0, 1904.4444444444446, 1080)) | ||
expect(node.isContainer).to.equal(true); | ||
expect(node.children.length).to.equal(1); | ||
|
||
const childNode = node.children[0]; | ||
expect(childNode.frame).to.eql(new Frame(10, 10, 1884.4444444444446, 1060)); | ||
expect(childNode.isContainer).to.equal(false); | ||
expect(childNode.children).to.eql([]); | ||
}); | ||
}); |
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 { describe } from 'mocha'; | ||
import { expect } from 'chai'; | ||
import { FlexComponent, Frame, InsetComponent, LayoutExerciser, Size, SourceComponent } from '@/layout'; | ||
import Insets from '@/layout/Insets'; | ||
|
||
describe('LayoutExerciser', () => { | ||
it('should perform layout', () => { | ||
const component = new SourceComponent() | ||
|
||
const exerciser = new LayoutExerciser() | ||
const node = exerciser.execute(component, new Size(160, 100)); | ||
|
||
expect(node.frame).to.eql(new Frame(0, 5, 160, 90)); | ||
expect(node.isContainer).to.equal(false); | ||
expect(node.children).to.eql([]); | ||
}) | ||
|
||
it('should perform complex layout', () => { | ||
const rootComponent = new InsetComponent(); | ||
rootComponent.insets = new Insets(50, 50, 50, 50); | ||
|
||
const verticalFlexComponent = new FlexComponent(); | ||
verticalFlexComponent.direction = 'vertical'; | ||
verticalFlexComponent.spacing = 50; | ||
rootComponent.addChild(verticalFlexComponent); | ||
|
||
const horizontalFlexComponent = new FlexComponent(); | ||
horizontalFlexComponent.direction = 'horizontal'; | ||
horizontalFlexComponent.spacing = 50; | ||
horizontalFlexComponent.addChild(new SourceComponent()) | ||
horizontalFlexComponent.addChild(new SourceComponent()) | ||
|
||
verticalFlexComponent.addChild(horizontalFlexComponent); | ||
verticalFlexComponent.addChild(new SourceComponent()) | ||
|
||
const exerciser = new LayoutExerciser() | ||
const node = exerciser.execute(rootComponent, new Size(1920, 1080)); | ||
|
||
expect(node.frame).to.eql(new Frame(0, 0, 1920, 1080)); | ||
expect(node.isContainer).to.equal(true); | ||
expect(node.children.length).to.equal(1); | ||
|
||
const verticalFlexNode = node.children[0]; | ||
expect(verticalFlexNode.frame).to.eql(new Frame(50, 50, 1820, 980)); | ||
expect(verticalFlexNode.isContainer).to.equal(true); | ||
expect(verticalFlexNode.children.length).to.equal(2); | ||
|
||
const horizontalFlexNode = verticalFlexNode.children[0]; | ||
expect(horizontalFlexNode.frame).to.eql(new Frame(0, 0, 1820, 465)); | ||
expect(horizontalFlexNode.isContainer).to.equal(true); | ||
expect(horizontalFlexNode.children.length).to.equal(2); | ||
|
||
const bottomSourceNode = verticalFlexNode.children[1]; | ||
expect(bottomSourceNode.frame).to.eql(new Frame(496.66666666666663, 515, 826.6666666666667, 465)); | ||
expect(bottomSourceNode.isContainer).to.equal(false); | ||
expect(bottomSourceNode.children).to.eql([]); | ||
|
||
const topLeftSourceNode = horizontalFlexNode.children[0]; | ||
expect(topLeftSourceNode.frame).to.eql(new Frame(58.33333333333326, 0, 826.6666666666667, 465)); | ||
expect(topLeftSourceNode.isContainer).to.equal(false); | ||
expect(topLeftSourceNode.children).to.eql([]); | ||
|
||
const topRightSourceNode = horizontalFlexNode.children[1]; | ||
expect(topRightSourceNode.frame).to.eql(new Frame(935, 0, 826.6666666666667, 465)); | ||
expect(topRightSourceNode.isContainer).to.equal(false); | ||
expect(topRightSourceNode.children).to.eql([]); | ||
}); | ||
}); |
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 { describe } from 'mocha'; | ||
import { expect } from 'chai'; | ||
import { Frame, Size, SourceComponent } from '@/layout'; | ||
|
||
describe('SourceComponent', () => { | ||
it('should layout', () => { | ||
const component = new SourceComponent(); | ||
|
||
const node = component.exerciseLayout(new Size(1920, 1080)); | ||
expect(node.frame).to.eql(new Frame(0, 0, 1920, 1080)); | ||
expect(node.isContainer).to.equal(false); | ||
expect(node.children).to.eql([]); | ||
}) | ||
}); |
Oops, something went wrong.