Skip to content

Commit

Permalink
migrate first geometry tests: Area
Browse files Browse the repository at this point in the history
  • Loading branch information
axelpale committed Jan 13, 2025
1 parent 21b3dfd commit e605601
Show file tree
Hide file tree
Showing 5 changed files with 136 additions and 0 deletions.
13 changes: 13 additions & 0 deletions test/headless/geometry/Area/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
export default function (test) {
const namespace = 'Area'
const methods = [
'projectTo',
'transitRaw'
]

let i, m
for (i = 0; i < methods.length; i += 1) {
m = methods[i]
test(namespace + ':' + m, import.meta.dirname, m + '.html')
}
}
59 changes: 59 additions & 0 deletions test/headless/geometry/Area/projectTo.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Area:projectTo - Tapspace Test</title>
<style>
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
#container {
background: gray;
width: 100%;
height: 100%;
}
#testspace {
width: 800px;
height: 600px;
}
</style>
<script src="../../../../dist/tapspace.min.js"></script>
<script src="../../testlib.js"></script>
</head>
<body>
<div id="container">
<div id="testspace"></div>
</div>
<script>
const t = test
t.plan(1)

// Setup
const view = tapspace.createView('#testspace')
const space = tapspace.createSpace()
view.addChild(space)

// Virtual camera
const camDist = 300
const camera = view.atCenter().offset(0, 0, -camDist)

// Create an element
const hello = tapspace.createItem('hello')
hello.setSize({ w: 20, h: 20 })
space.addChild(hello, space.at(10, 10, camDist))

// Create area
const area = hello.getArea()

// Original area: 400
t.equal(
area.projectTo(view, camera).getNumber(),
100,
'should have quarter of original area'
)
</script>
</body>
</html>
52 changes: 52 additions & 0 deletions test/headless/geometry/Area/transitRaw.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Area:transitRaw - Tapspace Test</title>
<style>
html, body {
margin: 0;
padding: 0;
width: 100%;
height: 100%;
}
#container {
background: gray;
width: 100%;
height: 100%;
}
#testspace {
width: 800px;
height: 600px;
}
</style>
<script src="../../../../dist/tapspace.min.js"></script>
<script src="../../testlib.js"></script>
</head>
<body>
<div id="container">
<div id="testspace"></div>
</div>
<script>
const t = test
t.plan(2)

// Setup
const view = tapspace.createView('#testspace')
const space = tapspace.createSpace()
view.addChild(space)
space.scaleBy(2, space.at(0, 0))

// Create an element
const hello = tapspace.createItem('hello')
hello.setSize({ w: 20, h: 20 })
space.addChild(hello, space.at(10, 10, 10))

// Create area
const area = hello.getArea()

t.equal(area.getRaw(), 400, 'should have correct area')
t.equal(area.transitRaw(view), 1600, 'should scale as area')
</script>
</body>
</html>
10 changes: 10 additions & 0 deletions test/headless/geometry/index.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import testArea from './Area/index.mjs'
import { makeTestAllOk } from '../utils.mjs'

export default function (test, browser) {
// Custom test runner to reduce boilerplate code.
// Opens the test page and evaluates the test results.
const testAllOk = makeTestAllOk(test, browser)

testArea(testAllOk)
}
2 changes: 2 additions & 0 deletions test/headless/suites.mjs
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import testComponents from './components/index.mjs'
import testGeometry from './geometry/index.mjs'
import testVersion from './version/index.mjs'

export default function (test, browser) {
testComponents(test, browser)
testGeometry(test, browser)
testVersion(test, browser)
}

0 comments on commit e605601

Please sign in to comment.