- Maintenance: Ticket Macro QUnit test works regardless of upcoming DST changes.
- Maintenance: Added SinonJS library for standalone test spies, stubs, time travel and mocks.
This commit is contained in:
parent
d25e53fdfb
commit
c80ea0bbc6
4 changed files with 16230 additions and 41 deletions
|
@ -188,3 +188,13 @@ Source: https://github.com/google/material-design-icons
|
||||||
Copyright: Google
|
Copyright: Google
|
||||||
License: Apache License, Version 2.0
|
License: Apache License, Version 2.0
|
||||||
-----------------------------------------------------------------------------
|
-----------------------------------------------------------------------------
|
||||||
|
QUnit
|
||||||
|
Source: https://qunitjs.com/
|
||||||
|
Copyright: jQuery Foundation and other contributors
|
||||||
|
License: MIT
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
Sinon.JS
|
||||||
|
Source: https://sinonjs.org
|
||||||
|
Copyright: Sinon committers
|
||||||
|
License: BSD-3
|
||||||
|
-----------------------------------------------------------------------------
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
|
|
||||||
<link rel="stylesheet" href="/assets/tests/qunit-1.21.0.css">
|
<link rel="stylesheet" href="/assets/tests/qunit-1.21.0.css">
|
||||||
<%= javascript_include_tag "/assets/tests/qunit-1.21.0.js", "/assets/tests/ticket_macro.js", nonce: true %>
|
<%= javascript_include_tag "/assets/tests/qunit-1.21.0.js", "/assets/tests/sinon-9.2.4", "/assets/tests/ticket_macro.js", nonce: true %>
|
||||||
|
|
||||||
<style type="text/css">
|
<style type="text/css">
|
||||||
body {
|
body {
|
||||||
|
@ -8,15 +8,4 @@ body {
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|
||||||
<script type="text/javascript">
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<%- date = Time.current.in_time_zone('Europe/London') %>
|
|
||||||
|
|
||||||
<data
|
|
||||||
data-offset-5-days=<%= date.utc_offset - (date + 5.days).utc_offset %>
|
|
||||||
data-offset-3-minutes=<%= date.utc_offset - (date + 3.minutes).utc_offset %>
|
|
||||||
data-offset-10-hours=<%= date.utc_offset - (date + 10.hours).utc_offset %>
|
|
||||||
>
|
|
||||||
|
|
||||||
<div id="qunit" class="u-dontfold"></div>
|
<div id="qunit" class="u-dontfold"></div>
|
||||||
|
|
16184
public/assets/tests/sinon-9.2.4.js
Normal file
16184
public/assets/tests/sinon-9.2.4.js
Normal file
File diff suppressed because one or more lines are too long
|
@ -1,5 +1,13 @@
|
||||||
test( "ticket macro pending time check", function() {
|
QUnit.module("ticket macro pending time check", hooks => {
|
||||||
var test_relative = function(rules, target, description, offset){
|
hooks.beforeEach( () => {
|
||||||
|
this.clock = sinon.useFakeTimers()
|
||||||
|
})
|
||||||
|
|
||||||
|
hooks.afterEach(() => {
|
||||||
|
this.clock.restore()
|
||||||
|
})
|
||||||
|
|
||||||
|
var calculate_travel_on_ticket = (rules) => {
|
||||||
var ticket = new App.Ticket()
|
var ticket = new App.Ticket()
|
||||||
|
|
||||||
App.Ticket.macro({
|
App.Ticket.macro({
|
||||||
|
@ -9,38 +17,36 @@ test( "ticket macro pending time check", function() {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
var compare_against = new Date()
|
return new Date(ticket.pending_time) - new Date()
|
||||||
var travel = Math.abs( new Date(ticket.pending_time) - compare_against)
|
|
||||||
|
|
||||||
var diff = Math.abs(target - travel) - offset*1000
|
|
||||||
|
|
||||||
ok(diff < 1000, description)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
var data = document.getElementsByTagName('data')[0].dataset
|
test("5 days", assert => {
|
||||||
debugger
|
var rules = {
|
||||||
|
operator: "relative",
|
||||||
|
range: "day",
|
||||||
|
value: 5
|
||||||
|
}
|
||||||
|
|
||||||
var rules = {
|
assert.equal(calculate_travel_on_ticket(rules), 60 * 60 * 24 * 5 * 1000)
|
||||||
operator: "relative",
|
})
|
||||||
range: "day",
|
|
||||||
value: 5
|
|
||||||
}
|
|
||||||
|
|
||||||
test_relative(rules, 60 * 60 * 24 * 5 * 1000, '5 days', data['offset-5Days'])
|
test("5 minutes", assert => {
|
||||||
|
var rules = {
|
||||||
|
operator: "relative",
|
||||||
|
range: "minute",
|
||||||
|
value: 3
|
||||||
|
}
|
||||||
|
|
||||||
var rules = {
|
assert.equal(calculate_travel_on_ticket(rules), 60 * 3 * 1000)
|
||||||
operator: "relative",
|
});
|
||||||
range: "minute",
|
|
||||||
value: 3
|
|
||||||
}
|
|
||||||
|
|
||||||
test_relative(rules, 60 * 3 * 1000, '5 minutes', data['offset-3Minutes'])
|
test("10 hours", assert => {
|
||||||
|
var rules = {
|
||||||
|
operator: "relative",
|
||||||
|
range: "hour",
|
||||||
|
value: 10
|
||||||
|
}
|
||||||
|
|
||||||
var rules = {
|
assert.equal(calculate_travel_on_ticket(rules), 60 * 60 * 10 * 1000)
|
||||||
operator: "relative",
|
});
|
||||||
range: "hour",
|
|
||||||
value: 10
|
|
||||||
}
|
|
||||||
|
|
||||||
test_relative(rules, 60 * 60 * 10 * 1000, '10 hours', data['offset-10Hours'])
|
|
||||||
})
|
})
|
||||||
|
|
Loading…
Reference in a new issue