From 2ffa821d659e8bd602e4d6188e9d13e5bd191394 Mon Sep 17 00:00:00 2001 From: Mantas Date: Thu, 22 Oct 2020 15:52:26 +0300 Subject: [PATCH] Maintenance: Applied workaround to Ticket Macro QUnit test to avoid failure leading up to DST switch. --- app/views/tests/ticket_macro.html.erb | 8 ++++++++ public/assets/tests/ticket_macro.js | 13 ++++++++----- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/app/views/tests/ticket_macro.html.erb b/app/views/tests/ticket_macro.html.erb index 99a7630b7..0fe1ed2d1 100644 --- a/app/views/tests/ticket_macro.html.erb +++ b/app/views/tests/ticket_macro.html.erb @@ -11,4 +11,12 @@ body { +<%- date = Time.current.in_time_zone('Europe/London') %> + + + data-offset-3-minutes=<%= date.utc_offset - (date + 3.minutes).utc_offset %> + data-offset-10-hours=<%= date.utc_offset - (date + 10.hours).utc_offset %> +> +
diff --git a/public/assets/tests/ticket_macro.js b/public/assets/tests/ticket_macro.js index ee6356884..333e0c790 100644 --- a/public/assets/tests/ticket_macro.js +++ b/public/assets/tests/ticket_macro.js @@ -1,5 +1,5 @@ test( "ticket macro pending time check", function() { - var test_relative = function(rules, target, description){ + var test_relative = function(rules, target, description, offset){ var ticket = new App.Ticket() App.Ticket.macro({ @@ -12,18 +12,21 @@ 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) + 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') + test_relative(rules, 60 * 60 * 24 * 5 * 1000, '5 days', data['offset-5Days']) var rules = { operator: "relative", @@ -31,7 +34,7 @@ test( "ticket macro pending time check", function() { value: 3 } - test_relative(rules, 60 * 3 * 1000, '5 minutes') + test_relative(rules, 60 * 3 * 1000, '5 minutes', data['offset-3Minutes']) var rules = { operator: "relative", @@ -39,5 +42,5 @@ test( "ticket macro pending time check", function() { value: 10 } - test_relative(rules, 60 * 60 * 10 * 1000, '10 hours') + test_relative(rules, 60 * 60 * 10 * 1000, '10 hours', data['offset-10Hours']) })