Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

i107: Don't error if the user enters a partial date range #115

Merged
merged 1 commit into from
Mar 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/components/LuxDatePicker.vue
Original file line number Diff line number Diff line change
Expand Up @@ -245,7 +245,7 @@ function updateInput(value) {
}
}
function updateRangeInput(value) {
if (value.includes(" - ")) {
if (stringSeemsLikeDateRange(value)) {
let r = value.split(" - ")
if (isValidFormat(r[0]) && isValidFormat(r[1])) {
if (!range.value) {
Expand All @@ -268,6 +268,10 @@ function isValidFormat(d) {
let date_regex = /^\d{1,2}\/\d{1,2}\/\d{4}$/
return date_regex.test(d)
}

function stringSeemsLikeDateRange(possibleRange) {
return possibleRange.includes(" - ") && !possibleRange.endsWith(" - ")
}
</script>

<style lang="scss">
Expand Down
12 changes: 12 additions & 0 deletions tests/unit/specs/components/luxDatePicker.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,18 @@ describe("LuxDatePicker.vue", () => {
expect(wrapper.vm.range).toBe(null)
})

it("should not update the date range value when the input is a partial date range", async () => {
wrapper.setProps({ mode: "range" })
await nextTick()
expect(wrapper.vm.range).toBe(null)

wrapper.get("input").setValue("10/22/2023 - ")

await nextTick()
expect(wrapper.vm.range).toBe(null)
expect(wrapper.get("input").element.value).toEqual("10/22/2023 - ")
})

it("has the expected html structure", () => {
expect(wrapper.element).toMatchSnapshot()
})
Expand Down
Loading