Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test harness #13

Merged
merged 5 commits into from
Sep 3, 2013
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
.grunt/
_SpecRunner.html
bin/coverage
node_modules/
.DS_Store
report/
21 changes: 21 additions & 0 deletions Gruntfile.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
module.exports = function(grunt) {

grunt.initConfig({
qunit: {
options: {
"--web-security": "no",
coverage: {
src: ["js/grande.js"],
instrumentedFiles: "temp/",
htmlReport: "report/coverage",
coberturaReport: "report/",
linesThresholdPct: 85
}
},
all: ["test/**.html"]
}
});

grunt.loadNpmTasks("grunt-qunit-istanbul");
};

1 change: 1 addition & 0 deletions js/grande.js
Original file line number Diff line number Diff line change
Expand Up @@ -314,4 +314,5 @@
}

root.grande = grande;

}).call(this);
30 changes: 30 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
{
"name": "grande.js",
"version": "0.0.1",
"author": "Matt DuVall <[email protected]>",
"description": "Open source implementation of Medium's UI features.",
"repository": {
"type": "git",
"url": "https://github.com/mduvall/grande.js"
},
"dependencies": {
},
"devDependencies": {
"istanbul": "~0.1.10",
"sinon": "*",
"grunt": "~0.4.1",
"qunitjs": "*",
"grunt-qunit-istanbul": "*"
},
"keywords": [
"ui",
"medium",
"ux",
"design"
],
"preferGlobal": true,
"license": {
"type": "MIT",
"url": "https://github.com/mduvall/grande.js/blob/master/LICENSE"
}
}
39 changes: 39 additions & 0 deletions test/grande.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Grande tests</title>
<link rel="stylesheet" href="../node_modules/qunitjs/qunit/qunit.css">
</head>
<body>
<div id="qunit"></div>
<div id="qunit-fixture">
<div class="g-body">
<div class="text-menu hide">
<div class="options">
<span class="no-overflow">
<span class="ui-inputs">
<button class="bold">B</button>
<button class="italic">i</button>
<button class="header1">h1</button>
<button class="header2">h2</button>
<button class="quote">&rdquo;</button>
<button class="url useicons">&#xe001;</button>
<input class="url-input" type="text" placeholder="Paste or type a link"/>
</span>
</span>
</div>
</div>

<section>
<article contenteditable="true" class="content">
</article>
</section>
</div>
</div>
<script src="../node_modules/qunitjs/qunit/qunit.js"></script>
<script src="lib/sinon.js"></script>
<script src="../js/grande.js"></script>
<script src="grande.js"></script>
</body>
</html>
74 changes: 74 additions & 0 deletions test/grande.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
module("grande initialization");

test("it should be available at the global scope", function() {
ok(typeof window.grande === "object",
"grande should be available at the window");
});


module("public api");

test("it should provide bind as a method", function() {
ok(typeof window.grande.bind === "function",
"bind should be a public api method");
});

test("it should provide select as a method", function() {
ok(typeof window.grande.select === "function",
"select should be a public API method");
});


module("event bindings", {
teardown: function() {
unbind();
}
});

test("it should bind the same events to the editableNode mousedown,keyup,mouseup", function() {
var editableNode = document.querySelectorAll(".g-body article")[0];

grande.bind();

ok(editableNode.onmousedown === editableNode.onkeyup,
"mousedown, keyup, and mouseup should delegate to the same function");
ok(editableNode.onmousedown === editableNode.onmouseup,
"mousedown, keyup, and mouseup should delegate to the same function");
});

test("it should bind mousedown, mouseup, and keyup on the document", function() {
ok(document.onmousedown === null,
"document mousedown should be null");
ok(document.onmouseup === null,
"document mouseup should be null");
ok(document.onkeyup === null,
"document keyup should be null");

grande.bind();

ok(typeof document.onmousedown === "function",
"document mousedown should be bound to a function");
ok(typeof document.onmouseup === "function",
"document mouseup should be bound to a function");
ok(typeof document.onkeyup === "function",
"document keyup should be bound to a function");
});

test("it should bind to the windows resize event", function() {
ok(window.onresize === null,
"window resize should be null");

grande.bind();

ok(typeof window.onresize === "function",
"window resize should be bound to a function");
});


function unbind() {
document.onmousedown =
document.onmouseup =
document.onkeyup =
window.onresize = null;
}

Loading