trabajo-afectivo/public/assets/tests/ticket_macro.js
Mantas Masalskis c80ea0bbc6 - Maintenance: Ticket Macro QUnit test works regardless of upcoming DST changes.
- Maintenance: Added SinonJS library for standalone test spies, stubs, time travel and mocks.
2021-03-24 08:02:54 +00:00

52 lines
1 KiB
JavaScript

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({
ticket: ticket,
macro: {
"ticket.pending_time": rules
}
})
return new Date(ticket.pending_time) - new Date()
}
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)
});
})