Skip to content

Commit

Permalink
test: date range of date questions
Browse files Browse the repository at this point in the history
  • Loading branch information
MitanOmar committed Oct 4, 2023
1 parent 4f98eb9 commit 9a56087
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 2 deletions.
8 changes: 6 additions & 2 deletions packages/form/tests/integration/components/cf-content-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,8 @@ module("Integration | Component | cf-content", function (hooks) {
this.server.create("question", {
formIds: [form.id],
type: "DATE",
minDate: "2023-01-01",
maxDate: "2030-12-31",
}),
this.server.create("question", {
formIds: [form.id],
Expand Down Expand Up @@ -181,6 +183,8 @@ module("Integration | Component | cf-content", function (hooks) {
formIds: [form.id],
slug: "date-question",
type: "DATE",
minDate: "2023-01-01",
maxDate: null,
});
this.server.create("question", {
formIds: [form.id],
Expand Down Expand Up @@ -229,7 +233,7 @@ module("Integration | Component | cf-content", function (hooks) {
);
await setFlatpickrDate(
`[name="Document:${document.id}:Question:date-question"]`,
new Date(2019, 2, 25), // month is zero based
new Date(2023, 2, 25), // month is zero based
);

await triggerEvent(
Expand Down Expand Up @@ -272,7 +276,7 @@ module("Integration | Component | cf-content", function (hooks) {
},
{
slug: "date-question",
value: "2019-03-25",
value: "2023-03-25",
},
{
slug: "files-question",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,40 @@ module("Integration | Component | cf-field/input/date", function (hooks) {
.hasValue("25.03.2021");
assert.dom(".ember-flatpickr-input[type='hidden']").hasValue("2021-03-25");
});

test("the date accept min date and max date", async function (assert) {
this.value = null;
this.field = {
question: {
raw: {
minDate: "2023-01-01",
maxDate: "2024-01-01",
},
},
};

await render(
hbs`<CfField::Input::Date @field={{this.field}} @onSave={{fn (mut this.value)}} />`,
);

await setLocale("en-us");
await setFlatpickrDate("input", new Date(2023, 6, 10)); // month is zero based
assert.strictEqual(this.value, "2023-07-10");
assert
.dom(".ember-flatpickr-input:not([type='hidden'])")
.hasValue("07/10/2023");
assert.dom(".ember-flatpickr-input[type='hidden']").hasValue("2023-07-10");

// the date here is less then the min dafined date
await setFlatpickrDate("input", new Date(2022, 6, 10)); // month is zero based
assert.strictEqual(this.value, null);
assert.dom(".ember-flatpickr-input:not([type='hidden'])").hasValue("");
assert.dom(".ember-flatpickr-input[type='hidden']").hasValue("");

// the date here is more then the max defined date
await setFlatpickrDate("input", new Date(2024, 6, 10)); // month is zero based
assert.strictEqual(this.value, null);
assert.dom(".ember-flatpickr-input:not([type='hidden'])").hasValue("");
assert.dom(".ember-flatpickr-input[type='hidden']").hasValue("");
});
});
2 changes: 2 additions & 0 deletions packages/testing/addon/scenarios/distribution.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,8 @@ export function createBlueprint(server) {
label: "Deadline",
isRequired: "true",
formIds: [inquiryForm.id],
minDate: null,
maxDate: null,
type: "DATE",
});

Expand Down

0 comments on commit 9a56087

Please sign in to comment.