- Maintenance: Ticket Macro QUnit test works regardless of upcoming DST changes.

- Maintenance: Added SinonJS library for standalone test spies, stubs, time travel and mocks.
antifascista
Mantas Masalskis 1 year ago committed by Thorsten Eckel
parent d25e53fdfb
commit c80ea0bbc6
  1. 10
      LICENSE-3RD-PARTY.txt
  2. 13
      app/views/tests/ticket_macro.html.erb
  3. 16184
      public/assets/tests/sinon-9.2.4.js
  4. 74
      public/assets/tests/ticket_macro.js

@ -188,3 +188,13 @@ Source: https://github.com/google/material-design-icons
Copyright: Google
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">
<%= 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">
body {
@ -8,15 +8,4 @@ body {
}
</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>

File diff suppressed because one or more lines are too long

@ -1,5 +1,13 @@
test( "ticket macro pending time check", function() {
var test_relative = function(rules, target, description, offset){
QUnit.module("ticket macro pending time check", hooks => {
hooks.beforeEach( () => {
this.clock = sinon.useFakeTimers()
})
hooks.afterEach(() => {
this.clock.restore()
})
var calculate_travel_on_ticket = (rules) => {
var ticket = new App.Ticket()
App.Ticket.macro({
@ -9,38 +17,36 @@ test( "ticket macro pending time check", function() {
}
})
var compare_against = 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
debugger
var rules = {
operator: "relative",
range: "day",
value: 5
}
test_relative(rules, 60 * 60 * 24 * 5 * 1000, '5 days', data['offset-5Days'])
var rules = {
operator: "relative",
range: "minute",
value: 3
}
test_relative(rules, 60 * 3 * 1000, '5 minutes', data['offset-3Minutes'])
var rules = {
operator: "relative",
range: "hour",
value: 10
return new Date(ticket.pending_time) - new Date()
}
test_relative(rules, 60 * 60 * 10 * 1000, '10 hours', data['offset-10Hours'])
test("5 days", assert => {
var rules = {
operator: "relative",
range: "day",
value: 5
}
assert.equal(calculate_travel_on_ticket(rules), 60 * 60 * 24 * 5 * 1000)
})
test("5 minutes", assert => {
var rules = {
operator: "relative",
range: "minute",
value: 3
}
assert.equal(calculate_travel_on_ticket(rules), 60 * 3 * 1000)
});
test("10 hours", assert => {
var rules = {
operator: "relative",
range: "hour",
value: 10
}
assert.equal(calculate_travel_on_ticket(rules), 60 * 60 * 10 * 1000)
});
})

Loading…
Cancel
Save