/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
"use strict";
// Create a list of abbreviations for calendar class names
const W = "weekend",
O = "outside",
S = "selection",
R = "out-of-range",
T = "today",
P = "off-step";
// Calendar classlist for 2016-12. Used to verify the classNames are correct.
const calendarClasslist_201612 = [
[W, O],
[O],
[O],
[O],
[],
[],
[W],
[W],
[],
[],
[],
[],
[],
[W],
[W],
[],
[],
[],
[S],
[],
[W],
[W],
[],
[],
[],
[],
[],
[W],
[W],
[],
[],
[],
[],
[],
[W],
[W, O],
[O],
[O],
[O],
[O],
[O],
[W, O],
];
/**
* Test that date picker opens to today's date when input field is blank
*/
add_task(async function test_datepicker_today() {
info("Test that date picker opens to today's date when input field is blank");
const date = new Date();
await helper.openPicker("data:text/html, ");
if (date.getMonth() === new Date().getMonth()) {
Assert.equal(
helper.getElement(MONTH_YEAR).textContent,
DATE_FORMAT_LOCAL(date),
"Today's date is opened"
);
Assert.equal(
helper.getElement(DAY_TODAY).getAttribute("aria-current"),
"date",
"Today's date is programmatically current"
);
Assert.equal(
helper.getElement(DAY_TODAY).getAttribute("tabindex"),
"0",
"Today's date is included in the focus order, when nothing is selected"
);
} else {
Assert.ok(
true,
"Skipping datepicker today test if month changes when opening picker."
);
}
await helper.tearDown();
});
/**
* Test that date picker opens to the correct month, with calendar days
* displayed correctly, given a date value is set.
*/
add_task(async function test_datepicker_open() {
info("Test the date picker markup with a set input date value");
const inputValue = "2016-12-15";
await helper.openPicker(
`data:text/html, `
);
Assert.equal(
helper.getElement(MONTH_YEAR).textContent,
DATE_FORMAT(new Date(inputValue)),
"2016-12-15 date is opened"
);
Assert.deepEqual(
getCalendarText(),
[
"27",
"28",
"29",
"30",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
"8",
"9",
"10",
"11",
"12",
"13",
"14",
"15",
"16",
"17",
"18",
"19",
"20",
"21",
"22",
"23",
"24",
"25",
"26",
"27",
"28",
"29",
"30",
"31",
"1",
"2",
"3",
"4",
"5",
"6",
"7",
],
"Calendar text for 2016-12 is correct"
);
Assert.deepEqual(
getCalendarClassList(),
calendarClasslist_201612,
"2016-12 classNames of the picker are correct"
);
Assert.equal(
helper.getElement(DAY_SELECTED).getAttribute("aria-selected"),
"true",
"Chosen date is programmatically selected"
);
Assert.equal(
helper.getElement(DAY_SELECTED).getAttribute("tabindex"),
"0",
"Selected date is included in the focus order"
);
await helper.tearDown();
});
/**
* Ensure that the datepicker popup appears correctly positioned when
* the input field has been transformed.
*/
add_task(async function test_datepicker_transformed_position() {
const inputValue = "2016-12-15";
const style =
"transform: translateX(7px) translateY(13px); border-top: 2px; border-left: 5px; margin: 30px;";
const iframeContent = ``;
await helper.openPicker(
"data:text/html,