Permalink
Browse files

Start some unit tests for catalog controls.

  • Loading branch information...
1 parent d140e5e commit 2b90aa7020407bbc1e2ef205103e9db17bbdc221 @JanMiksovsky committed May 22, 2012
View
@@ -6,4 +6,5 @@ quickui.catalog.*
controlDocumentation.js
docs.js
docs.css
-tests/common/common.*
+test/unittests.js
+test/common/common.*
View
@@ -0,0 +1,28 @@
+/*
+ * Build catalog with Grunt.js.
+ * For now, this just builds unit tests.
+ */
+module.exports = function(grunt) {
+
+ grunt.loadTasks( "../quickui/grunt" );
+
+ // Project configuration.
+ grunt.initConfig({
+ coffee: {
+ test: {
+ src: "test/*.coffee",
+ dest: "test/unittests.js"
+ }
+ },
+ watch: {
+ test: {
+ files: "<config:coffee.test.src>",
+ tasks: "coffee:test"
+ }
+ }
+ });
+
+ // Default task.
+ grunt.registerTask( "default", "coffee watch" );
+
+};
View
@@ -0,0 +1,63 @@
+###
+List tests
+###
+
+$ ->
+
+ class SimpleItem extends Control
+ constructor: -> return Control.coffee()
+ foo: Control.property()
+ bar: Control.property()
+
+
+ test "List: map string items to content", ->
+ $list = List.create
+ items: [
+ "One"
+ "Two"
+ "Three"
+ ]
+ equal $list.items().length, 3
+ equal $list.children().length, 3
+ equal $list.children().eq(0).text(), "One"
+ equal $list.text(), "OneTwoThree"
+
+
+ test "List: mapFunction specifies string name of property getter/setter", ->
+ $list = List.create
+ itemClass: SimpleItem
+ mapFunction: "foo"
+ items: [
+ "One"
+ "Two"
+ "Three"
+ ]
+ $controls = $list.children().control()
+ equal $controls.length, 3
+ equal $controls.eq(0).foo(), "One"
+
+
+ test "List: custom mapFunction getter/setter", ->
+ $list = List.create
+ itemClass: SimpleItem
+ mapFunction: ( item ) ->
+ if item is undefined
+ {
+ foo: @foo()
+ bar: @bar()
+ }
+ else
+ @properties item
+ items: [
+ { foo: "One", bar: 1 }
+ { foo: "Two", bar: 2 }
+ { foo: "Three", bar: 3 }
+ ]
+ $controls = $list.children().control()
+ $c = $controls.eq(0)
+ equal $c.foo(), "One"
+ equal $c.bar(), 1
+ $list.isDirty true # Clear list's cache of items
+ item = $list.items()[0]
+ equal item.foo, "One"
+ equal item.bar, 1
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
View
@@ -0,0 +1,29 @@
+<!DOCTYPE html>
+
+<html>
+<head>
+<title>QuickUI Unit Tests</title>
+
+<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
+
+<link rel="stylesheet" type="text/css" href="http://code.jquery.com/qunit/git/qunit.css" />
+<link rel="stylesheet" type="text/css" href="../quickui.catalog/quickui.catalog.css"></script>
+
+<script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.js"></script>
+<script type="text/javascript" src="http://code.jquery.com/qunit/git/qunit.js"></script>
+<script type="text/javascript" src="http://quickui/release/quickui.js"></script>
+<script type="text/javascript" src="../quickui.catalog/quickui.catalog.js"></script>
+<script type="text/javascript" src="unittests.js"></script>
+
+</head>
+
+<body data-create-controls="true">
+ <h1 id="qunit-header">QuickUI Catalog Unit Tests</h1>
+ <h2 id="qunit-banner"></h2>
+ <div id="qunit-testrunner-toolbar"></div>
+ <h2 id="qunit-userAgent"></h2>
+ <ol id="qunit-tests"></ol>
+ <div id="qunit-fixture">test markup, will be hidden</div>
+</body>
+
+</html>

0 comments on commit 2b90aa7

Please sign in to comment.