Skip to content

Instantly share code, notes, and snippets.

@cdata
Created November 2, 2015 18:32
Show Gist options
  • Save cdata/9b2374db0e42606dbf65 to your computer and use it in GitHub Desktop.
Save cdata/9b2374db0e42606dbf65 to your computer and use it in GitHub Desktop.
<html>
<head>
<meta charset="UTF-8">
<title>custom-quiz basic tests</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0">
<script src="../../../bower_components/webcomponentsjs/webcomponents-lite.js"></script>
<script src="../../../bower_components/web-component-tester/browser.js"></script>
<script src="../../../bower_components/test-fixture/test-fixture-mocha.js"></script>
<script src="../../../bower_components/iron-test-helpers/mock-interactions.js"></script>
<link rel="import" href="../../../bower_components/test-fixture/test-fixture.html">
<!-- build:js ../editor/index.html -->
<link rel="import" href="../custom-quiz.html">
<!-- endbuild -->
<style>
html,
body {
margin: 0;
padding: 0;
height: 100vh;
width: 100%;
position: relative;
overflow: hidden;
}
test-fixture {
display: block;
height: 100%;
width: 100%;
}
</style>
</head>
<body>
<test-fixture id="quiz">
<template>
<custom-quiz></custom-quiz>
</template>
</test-fixture>
<link rel="import" href="../demo/demo-data.html">
<script>
'use strict';
suite('<custom-quiz>', function() {
var quiz, input;
setup(function() {
quiz = fixture('quiz');
quiz.overlay = window.dummyOverlays[0];
input = Polymer.dom(quiz.root).querySelector('input-item');
});
function testGrading(answer, combination, done) {
input.value = answer;
quiz.addEventListener('quiz-graded', function(e) {
var result = e.detail;
console.log(result, combination);
assert(result === combination, 'combination correctly evaluated');
done();
});
quiz.fire('grade-answer');
}
test('can grade totally incorrect answer', function(done) {
testGrading('totally wrong', window.dummyOverlays[0].combinations[1], done);
});
test('can grade correct answer', function(done) {
testGrading('9', window.dummyOverlays[0].combinations[0], done);
});
test('can grade incorrect answer', function(done) {
testGrading('43', window.dummyOverlays[0].combinations[3], done);
});
test('can grade neutral answer with respect of combinations order', function(done) {
testGrading('10', window.dummyOverlays[0].combinations[4], done);
});
test('can position it\'s items', function(done) {
quiz.style.display = 'block';
var item = Polymer.dom(quiz.root).querySelector('input-item');
var itemRect = item.getBoundingClientRect();
var quizRect = quiz.getBoundingClientRect();
var itemLeftExpected = window.dummyOverlays[0].items[0].x * quizRect.width;
var itemTopExpected = window.dummyOverlays[0].items[0].y * quizRect.height;
console.log(itemLeftExpected,itemRect.left);
console.log(itemTopExpected,itemRect.top);
//TODO: test proper scaling...
assert('TODO',itemLeftExpected === itemRect.left, 'correct left');
assert('TODO'itemTopExpected === itemRect.top, 'correct left');
done();
});
});
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment