Skip to content

Commit

Permalink
Fix GMT tests in Scheduler (#1827)
Browse files Browse the repository at this point in the history
  • Loading branch information
Yarovaya authored Nov 3, 2017
1 parent 3537238 commit a208ab4
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ var $ = require("jquery"),
devices = require("core/devices"),
resizeCallbacks = require("core/utils/window").resizeCallbacks,
fx = require("animation/fx"),
Color = require("color");
Color = require("color"),
subscribes = require("ui/scheduler/ui.scheduler.subscribes");

require("ui/scheduler/ui.scheduler");

function getDeltaTz(schedulerTz) {
var defaultTz = new Date().getTimezoneOffset() * 60000;
var defaultTz = -10800000;
return schedulerTz * 3600000 + defaultTz;
}

Expand Down Expand Up @@ -1025,26 +1026,31 @@ QUnit.test("The timeZone option should be processed correctly", function(assert)
});

QUnit.test("All-day appointment should not be duplicated with custom timezone", function(assert) {
this.clock.restore();
var timezoneDifference = getDeltaTz(5),
getDate = function(date) {
return new Date(date.getTime() - timezoneDifference);
};

this.createInstance({
views: ["agenda"],
currentView: "agenda",
currentDate: new Date(2016, 4, 3),
timeZone: "Asia/Ashkhabad",
dataSource: [{
startDate: getDate(new Date(2016, 4, 4)),
endDate: getDate(new Date(2016, 4, 5))
}]
});
var tzOffsetStub = sinon.stub(subscribes, "getClientTimezoneOffset").returns(-10800000);
try {
this.clock.restore();
var timezoneDifference = getDeltaTz(5),
getDate = function(date) {
return new Date(date.getTime() - timezoneDifference);
};

this.createInstance({
views: ["agenda"],
currentView: "agenda",
currentDate: new Date(2016, 4, 3),
timeZone: "Asia/Ashkhabad",
dataSource: [{
startDate: getDate(new Date(2016, 4, 4)),
endDate: getDate(new Date(2016, 4, 5))
}]
});

var $appts = this.instance.element().find(".dx-scheduler-appointment");
var $appts = this.instance.element().find(".dx-scheduler-appointment");

assert.equal($appts.length, 1, "Appt count is OK");
assert.equal($appts.length, 1, "Appt count is OK");
} finally {
tzOffsetStub.restore();
}
});

QUnit.test("All-day appointment should not be duplicated with custom timezone (T437288)", function(assert) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4126,27 +4126,32 @@ QUnit.test("Long multiday appointment should have right position on timeline wee
});

QUnit.test("Appointment should have right width in workspace with timezone", function(assert) {
this.clock.restore();
this.createInstance({
dataSource: [],
currentDate: new Date(2016, 4, 1),
currentView: "month",
firstDayOfWeek: 1,
startDayHour: 3,
endDayHour: 24,
timeZone: "Asia/Ashkhabad"
});
var tzOffsetStub = sinon.stub(subscribes, "getClientTimezoneOffset").returns(-10800000);
try {
this.clock.restore();
this.createInstance({
dataSource: [],
currentDate: new Date(2017, 4, 1),
currentView: "month",
firstDayOfWeek: 1,
startDayHour: 3,
endDayHour: 24,
timeZone: "Asia/Ashkhabad"
});

this.instance.addAppointment({
text: "Task 1",
startDate: new Date(2016, 4, 4),
endDate: new Date(2016, 4, 5)
});
this.instance.addAppointment({
text: "Task 1",
startDate: new Date(2017, 4, 4),
endDate: new Date(2017, 4, 5)
});

var $appointment = this.instance.element().find(".dx-scheduler-work-space .dx-scheduler-appointment").eq(0),
$cell = this.instance.element().find(".dx-scheduler-work-space .dx-scheduler-date-table-cell").eq(9);
var $appointment = this.instance.element().find(".dx-scheduler-work-space .dx-scheduler-appointment").eq(0),
$cell = this.instance.element().find(".dx-scheduler-work-space .dx-scheduler-date-table-cell").eq(9);

assert.roughEqual($appointment.outerWidth(), $cell.outerWidth(), 1.001, "Task has a right width");
assert.roughEqual($appointment.outerWidth(), $cell.outerWidth(), 1.001, "Task has a right width");
} finally {
tzOffsetStub.restore();
}
});

QUnit.test("Appointment with zero-duration should be rendered correctly(T443143)", function(assert) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,6 @@ var $ = require("jquery"),
dateUtils = require("core/utils/date"),
config = require("core/config");

function getDaylightSavingsOffset(date1, date2) {
return date1.getTimezoneOffset() - date2.getTimezoneOffset();
}

QUnit.testStart(function() {
$("#qunit-fixture").html('<div id="scheduler"></div>');
});
Expand Down Expand Up @@ -701,8 +697,6 @@ QUnit.test("'convertDateByTimezone' should return date according to the custom t
var date = new Date(2015, 6, 3, 3),
timezoneDifference = date.getTimezoneOffset() * 60000 + timezoneValue * 3600000;

timezoneDifference -= getDaylightSavingsOffset(date, new Date()) * 60000;

var convertedDate = this.instance.fire("convertDateByTimezone", date);

assert.deepEqual(convertedDate, new Date(date.getTime() + timezoneDifference), "'convertDateByTimezone' works fine");
Expand All @@ -720,8 +714,6 @@ QUnit.test("'convertDateByTimezone' should return date according to the custom t
var date = new Date(2015, 6, 3, 3),
timezoneDifference = date.getTimezoneOffset() * 60000 + timezone.value * 3600000;

timezoneDifference -= getDaylightSavingsOffset(date, new Date()) * 60000;

var convertedDate = this.instance.fire("convertDateByTimezone", date);

assert.deepEqual(convertedDate, new Date(date.getTime() + timezoneDifference), "'convertDateByTimezone' works fine");
Expand Down

0 comments on commit a208ab4

Please sign in to comment.