How to Write Test Cases for Date Picker (With Examples)
How to Write Test Cases for Date Picker (With Examples)
How to Write Test Cases for Date Picker (With Examples)
Date pickers are ubiquitous UI components that allow users to select a single date, a date range, or a date and time. Despite their apparent simplicity, date pickers hide a multitude of implementation details that can cause functional defects, accessibility barriers, and localization failures. Writing effective test cases for a date picker requires a systematic approach that covers normal usage, invalid input, boundary conditions, accessibility, and internationalization. This guide walks you through the anatomy of a test case, provides a concrete matrix of 25+ test cases, shows how to prioritize and trace them to requirements, and explains how combining manual design with autonomous exploration (e.g., using a platform like SUSA) yields real‑world coverage. Each section includes practical examples, code snippets for automation, and a short checklist you can bookmark.
How to Write Test Cases for Date Picker (With Examples): Foundations
Before diving into individual test ideas, it is useful to clarify what makes a date picker testable and why generic UI test advice often falls short. A date picker typically consists of:
- An input field that may display a formatted date.
- A trigger (icon or button) that opens a calendar popup or inline view.
- Navigation controls for month/year (arrows, dropdowns, fast‑forward buttons).
- A grid of day cells, each representing a selectable date.
- Optional time selection controls (hour/minute/second spinners).
- Confirmation and cancellation buttons (OK, Apply, Clear).
Testability hinges on being able to observe the component’s state after each interaction: the displayed value, the underlying model (e.g., a JavaScript Date object), and any side effects such as form validation triggers. When writing test cases, you must consider:
- Input modalities – touch, mouse, keyboard, assistive technology.
- Data formats – ISO 8601, locale‑specific patterns, timestamps.
- State persistence – does the picker close after selection? Does it retain the last opened month?
- Error handling – how does the component react to out‑of‑range or malformed values?
- Cross‑cutting concerns – accessibility (WCAG 2.1 AA), right‑to‑left layouts, timezone shifts, leap years.
Understanding these dimensions helps you move beyond “click a date and verify it appears” and toward a test suite that catches regressions before they reach production.
How to Write Test Cases for Date Picker (With Examples): Anatomy of a Test Case
A well‑structured test case makes it easy to review, automate, and trace to requirements. The following fields are recommended:
| Field | Description |
|---|---|
| ID | Unique identifier (e.g., DP‑001). Use a prefix that indicates the feature area. |
| Title | Short, readable summary (e.g., “Select a valid date using the mouse”). |
| Preconditions | System state required before execution (e.g., “Date picker component is rendered on the page with minDate = 2020‑01‑01 and maxDate = 2025‑12‑31”). |
| Steps | Numbered actions performed by the tester or automation script. Include input values and any waits. |
| Expected Result | Observable outcome after the final step (e.g., “Input field displays ‘2023‑07‑15’ and the underlying model holds a Date object for 2023‑07‑15”). |
| Postconditions | Any cleanup or state verification needed to leave the system ready for the next test (e.g., “Date picker is closed”). |
| Priority | Typically P0 (critical), P1 (high), P2 (medium), P3 (low). Based on risk and business impact. |
| Tags | Keywords for filtering (e.g., positive, keyboard, accessibility, locale‑fr). |
| Trace | Link to the requirement or user story (e.g., US‑1234: Date picker must allow selection of any date within the allowed range). |
Using this template ensures consistency across manual test sheets, test management tools, and automated test code. When you later convert a manual case to an automated script, you can map each step directly to a command in your test framework.
How to Write Test Cases for Date Picker (With Examples): Positive Test Cases
Positive test cases verify that the date picker behaves correctly when users provide valid input through the supported interaction methods. Below are representative scenarios; you can expand them based on your product’s specific features (e.g., range selection, time‑of‑day).
| ID | Title | Preconditions | Steps | Expected Result |
|---|---|---|---|---|
| DP‑001 | Select a date via mouse click | Date picker inline, minDate=2020‑01‑01, maxDate=2025‑12‑31, today=2023‑08‑15 | 1. Click the day cell for 2023‑08‑20 | Input shows “2023‑08‑20”; model date = 2023‑08‑20; picker closes (if modal). |
| DP‑002 | Select a date via keyboard navigation (arrow keys) | Same as DP‑001, focus on the input field | 1. Press Alt+Down to open picker 2. Press Right five times to move from today to 2023‑08‑20 3. Press Enter | Input shows “2023‑08‑20”; model updated; picker closes. |
| DP‑003 | Type a valid date directly into the input field | Input accepts manual entry, format yyyy‑MM‑dd | 1. Click the input field 2. Type 2022‑12‑31 3. Press Tab or click outside | Input shows 2022‑12‑31; model date = 2022‑12‑31; no validation error shown. |
| DP‑004 | Select a date range (start and end) | Range picker enabled, minDate=2020‑01‑01, maxDate=2025‑12‑31 | 1. Click start date 2023‑09‑01 2. Click end date 2023‑09‑10 | Input shows “2023‑09‑01 – 2023‑09‑10”; model contains start=2023‑09‑01, end=2023‑09‑10. |
| DP‑005 | Clear the selected date using the clear button | A date is already selected (e.g., 2023‑07‑15) | 1. Click the clear (×) button inside the picker or input field | Input becomes empty; model date = null; any dependent validation messages disappear. |
| DP‑006 | Navigate months using the next/prev arrows | Picker opened, displaying August 2023 | 1. Click the “Next month” arrow twice 2. Observe month header | Month header changes to October 2023; day grid updates accordingly; selected date (if any) stays unchanged. |
| DP‑007 | Jump to a specific year via year dropdown | Picker opened, year dropdown visible | 1. Click the year dropdown 2. Select 2021 3. Verify month grid | Month grid shows January 2021; navigation respects the new year. |
| DP‑008 | Select today using the “Today” shortcut button | Picker opened, today button present | 1. Click the “Today” button | Input shows today’s date (2023‑08‑15); model updated; picker closes. |
| DP‑009 | Select a date via swipe gesture on touch device | Touch‑enabled device, picker displayed as a modal | 1. Swipe left on the month header to go to September 2023 2. Tap day 15 | Input shows 2023‑09‑15; model updated; picker closes. |
| DP‑010 | Validate that selecting a date updates a bound form field | Form with a date field bound to the picker via v-model (Vue) or useState (React) | 1. Choose 2024‑02‑10 in the picker | Bound form field reflects 2024‑02‑10; any form‑level validation runs without error. |
These ten cases already cover mouse, keyboard, direct entry, range, clear, navigation, shortcuts, touch, and framework binding. Feel free to add variations for time selection (hour/minute spinners) or for disabling specific weekdays.
How to Write Test Cases for Date Picker (With Examples): Negative and Invalid Input Cases
Negative test cases ensure the component gracefully handles data that should not be accepted. The goal is to verify that invalid input does not corrupt the model, does not crash the component, and provides clear feedback to the user.
| ID | Title | Preconditions | Steps | Expected Result |
|---|---|---|---|---|
| DP‑011 | Enter a date before the minimum allowed date | minDate=2020‑01‑01, maxDate=2025‑12‑31 | 1. Click input 2. Type 2019‑12‑31 3. Press Tab | Input shows an error (e.g., red border, tooltip “Date must be on or after 2020‑01‑01”); model remains unchanged (still at previous valid value or null. |
| DP‑012 | Enter a date after the maximum allowed date | Same as DP‑011 | 1. Type 2026‑01‑01 2. Press Tab | Same validation error as DP‑011, but with upper bound message. |
| DP‑013 | Enter a non‑date string (letters) | Input accepts manual entry | 1. Type abcd 2. Press Tab | Input shows validation error “Please enter a valid date”; model unchanged. |
| DP‑014 | Enter a date with wrong separator (e.g., slash) | Expected format yyyy‑MM‑dd | 1. Type 2023/08/15 2. Press Tab | Depending on implementation: either auto‑correct to 2023‑08‑15 or show error “Invalid format”. |
| DP‑015 | Enter a date with missing leading zeros | Format expects two‑digit month/day | 1. Type 2023‑8‑5 2. Press Tab | Either auto‑pads to 2023‑08‑05 or shows format error. |
| DP‑016 | Enter a date that is not a real calendar date (e.g., Feb 30) | Input accepts manual entry | 1. Type 2023‑02‑30 2. Press Tab | Validation error “Invalid date”; model unchanged. |
| DP‑017 | Attempt to select a disabled date in the grid | Certain dates are disabled (e.g., weekends, holidays) | 1. Open picker 2. Try to click a disabled cell (e.g., a Saturday) | Click is ignored; selected date does not change; no error message needed (just no action). |
| DP‑018 | Open picker and press Escape to cancel without selection | Picker opened, a date may be pre‑selected | 1. Press Esc | Picker closes; input retains any previously selected date (or remains empty if none). |
| DP‑019 | Paste a malformed date from clipboard | Input field supports paste | 1. Copy string not-a-date 2. Focus input 3. Paste (Ctrl+V) | Input shows validation error; model unchanged. |
| DP‑020 | Rapidly toggle month navigation causing UI glitch | Picker opened, fast clicking allowed | 1. Repeatedly click next/previous month arrows 10 times within 1 second | Calendar updates correctly each time; no duplicate month headers, no missing days, no JS errors in console. |
These cases probe boundary validation, format enforcement, disabled state handling, and interaction robustness. When automating, you can assert that the component’s error state (e.g., aria-invalid="true") appears and that the model value does not change.
How to Write Test Cases for Date Picker (With Examples): Boundary and Edge Cases
Boundary testing focuses on values at the limits of accepted ranges, as well as special calendar quirks like leap years, month transitions, and timezone shifts. Edge cases often involve uncommon user behaviors or device conditions that surface only in production.
| ID | Title | Preconditions | Steps | Expected Result |
|---|---|---|---|---|
| DP‑021 | Select the minimum allowed date | minDate=2020‑01‑01, maxDate=2025‑12‑31 | 1. Open picker 2. Navigate to January 2020 3. Click day 1 | Input shows 2020‑01‑01; model updated; picker closes. |
| DP‑022 | Select the maximum allowed date | Same as DP‑021 | 1. Navigate to December 2025 2. Click day 31 | Input shows 2025‑12‑31; model updated; picker closes. |
| DP‑023 | Select February 29 on a leap year | minDate=2020‑01‑01, maxDate=2028‑12‑31 (includes 2024‑02‑29) | 1. Navigate to February 2024 2. Click day 29 | Input shows 2024‑02‑29; model updated; no error. |
| DP‑024 | Attempt to select February 29 on a non‑leap year | Same range, but year 2023 is not a leap year | 1. Navigate to February 2023 2. Try to click day 29 | Day 29 is either hidden or disabled; clicking does nothing; model unchanged. |
| DP‑025 | Select date after crossing year boundary via fast‑forward | Picker opened showing December 2023 | 1. Click the year dropdown 2. Choose 2025 3. Click day 15 | Input shows 2025‑01‑15 (if month stayed January) or 2025‑12‑15 depending on implementation; model updated correctly. |
| DP‑026 | Change system timezone while picker is open | Picker displaying a date; user’s timezone set to UTC | 1. Change OS timezone to UTC+5 2. Observe picker display | Displayed dates adjust to reflect the new offset if the component uses local time; otherwise, dates stay same but underlying UTC value shifts. |
| DP‑027 | Select a date when the device locale uses a different calendar (e.g., Persian) | Locale set to fa-IR (Persian calendar) | 1. Open picker 2. Observe that grid shows Persian months/days 3. Select a date | Selected date is correctly converted to Gregorian for the model (e.g., selecting 1 Farvardin 1402 yields 2023‑03‑21). |
| DP‑028 | Test with font size scaling (200%) for accessibility | Browser/OS set to 200% text scaling | 1. Open picker 2. Verify that all touch targets are at least 48 dp | All day cells, navigation arrows, and buttons are easily tappable; no clipping or overlap. |
| DP‑029 | Simulate a slow network while loading month data via AJAX | Picker loads month data lazily from an API | 1. Throttle network to 50 kbps 2. Open picker 3. Navigate to next month | A loading indicator appears; once data loads, the grid shows correct days; no UI freeze or duplicate requests. |
| DP‑030 | Perform a long press on a day cell to trigger a context menu (if supported) | Picker supports long‑press for “add note” | 1. Long‑press on day 10 | Context menu appears with appropriate actions; selecting an action does not change the selected date unless intended. |
These cases push the component to its limits and verify correct handling of calendar peculiarities, accessibility scaling, locale‑specific calendars, and asynchronous data loading. Documenting the expected behavior for each edge case prevents regressions when the underlying date‑handling library is upgraded.
How to Write Test Cases for Date Picker (With Examples): Accessibility and Internationalization Tests
Accessibility (a11y) and localization (i18n) are not optional extras; they are integral to a usable date picker. WCAG 2.1 AA success criteria that apply include keyboard operability, label association, sufficient contrast, and error identification. Internationalization covers locale‑specific formats, right‑to‑left (RTL) layouts, and calendar systems.
| ID | Title | Preconditions | Steps | Expected Result |
|---|---|---|---|---|
| DP‑031 | Verify that each day cell has an accessible name | Picker opened, inspect DOM | 1. Use axe or manual inspection to check aria-label or aria-labelledby on a day cell (e.g., day 15) | aria-label contains a readable date string, e.g., “August 15, 2023”. |
| DP‑032 | Ensure keyboard focus order is logical | Focus on the input field | 1. Press Tab to move focus into the picker 2. Press Tab repeatedly to traverse day cells, navigation buttons, OK/Cancel | Focus moves predictably left‑to‑right, top‑to‑bottom (or RTL equivalent) without jumps or traps. |
| DP‑033 | Check contrast of selected day background | Selected day styled with a background color | 1. Use a contrast analyzer on the selected day cell vs. its background text | Contrast ratio ≥ 4.5:1 for AA text (or ≥ 3:1 for large text). |
| DP‑034 | Validate error message is announced by screen readers | Input shows validation error after entering an invalid date | 1. Run a screen reader (NVDA, VoiceOver) 2. Focus the input | Screen reader reads the error message (e.g., “Invalid date. Please enter a date between Jan 1 2020 and Dec 31 2025”). |
| DP‑035 | Test date picker in a right‑to‑left locale (e.g., Arabic) | Locale set to ar-SA, direction rtl | 1. Open picker 2. Observe layout | Month navigation arrows are mirrored; day grid starts on the right side; input text aligns right. |
| DP‑036 | Verify localized date format matches locale preferences | Locale fr-FR expects dd/MM/yyyy | 1. Select a date 2. Read the input field | Input displays 15/08/2023 (or the pattern defined for fr-FR). |
| DP‑037 | Ensure that the picker works with zoom level 400% | Browser zoom set to 400% | 1. Open picker 2. Interact with all controls | All controls remain visible, usable, and not clipped; no horizontal scrolling required to reach essential elements. |
| DP‑038 | Check that date value is correctly announced when using voice input | Voice control software active | 1. Say “Select August fifteenth twenty twenty‑three” | Picker opens, navigates to August 2023, selects day 15, and closes; the transcribed text matches the selected date. |
| DP‑039 | Validate that disabling the picker removes it from the tab order | Picker has a disabled attribute | 1. Tab through the form | Disabled picker is skipped; focus moves to the next focusable element. |
| DP‑040 | Test that date range selection conveys both start and end to assistive tech | Range picker with aria-label on the input | 1. Choose start 2023‑09‑01 and end 2023‑09‑10 | Screen reader reads something like “From September 1, 2023 to September 10, 2023”. |
Incorporating these checks early prevents costly redesigns later. Automated a11y tools (axe, pa11y, @testing-library/jest-dom) can catch many of these issues in CI, while manual screen‑reader testing validates the experience.
How to Write Test Cases for Date Picker (With Examples): Test Data Preparation and Prioritization
Even the best‑designed test suite can become unwieldy if test data is not managed systematically. For date pickers, data preparation involves defining valid ranges, invalid values, locale strings, and timezone offsets. Prioritization helps you focus on high‑risk areas first, especially when time is limited.
Data‑Driven Approach
Create a JSON or CSV file that feeds both manual test scripts and automated tests. Example snippet:
{
"valid": [
{"value":"2023-01-01","description":"min boundary"},
{"value":"2023-06-15","description":"mid‑year"},
{"value":"2025-12-31","description":"max boundary"}
],
"invalid": [
{"value":"2019-12-31","reason":"below min"},
{"value":"2026-01-01","reason":"above max"},
{"value":"2023-02-30","reason":"non‑existent date"},
{"value":"not-a-date","reason":"wrong format"}
],
"locales": [
{"code":"en-US","format":"MM/dd/yyyy"},
{"code":"fr-FR","format":"dd/MM/yyyy"},
{"code":"ja-JP","format":"yyyy/MM/dd"}
]
}
Automated tests can loop over these entries, drastically reducing duplication.
Risk‑Based Prioritization
Use a simple 2‑dimensional matrix: Impact (how severe a defect would be) vs. Likelihood (how probable the defect is to occur). Assign each test case a score (e.g., Impact 1‑3, Likelihood 1‑3) and compute Priority = Impact × Likelihood. Higher scores get P0/P1.
| Test ID | Impact (1‑3) | Likelihood (1‑3) | Score | Priority |
|---|---|---|---|---|
| DP‑001 | 3 | 3 | 9 | P0 |
| DP‑011 | 3 | 2 | 6 | P1 |
| DP‑023 | 2 | 2 | 4 | P2 |
| DP‑031 | 3 | 1 | 3 | P2 |
| DP‑040 | 2 | 1 | 2 | P3 |
In practice, you would involve product owners, developers, and support staff to agree on impact levels (e.g., data loss, security, compliance). Likelihood can be informed by historical defect data or by the complexity of the code path.
Traceability to Requirements
Link each test case to a requirement ID in your tracking system (Jira, Azure DevOps, etc.). This enables impact analysis when a requirement changes. Example traceability matrix:
| Requirement ID | Description | Covered Test IDs |
|---|---|---|
| REQ‑DATE‑01 | User can select any date within allowed range | DP‑001, DP‑002, DP‑003, DP‑021, DP‑022 |
| REQ‑DATE‑02 | Invalid input shows clear error message | DP‑011, DP‑012, DP‑013, DP‑014, DP‑015, DP‑016, DP‑019 |
| REQ‑DATE‑03 | Picker is navigable via keyboard | DP‑002, DP‑032 |
| REQ‑DATE‑04 | Picker respects locale-specific format | DP‑036, DP‑035 |
| REQ‑DATE‑05 | Picker is WCAG AA compliant | DP‑031, DP‑033, DP‑034, DP‑037, DP‑038 |
Maintaining this matrix in a spreadsheet or as markdown in your repo ensures that no requirement slips through the cracks.
How to Write Test Cases for Date Picker (With Examples): Combining Manual Design with Autonomous Exploration
Manual test case design excels at targeting known risks and verifying specific requirements. Autonomous exploration complements this by exercising the component in ways that a human might not think of, uncovering issues that only appear under varied user behaviors, device states, or long‑running sessions.
How Autonomous Platforms Like SUSA Augment Coverage
SUSA (SUSATest) is an autonomous QA agent that, given an APK or a web URL, explores the application using a set of simulated user personas. Each persona has distinct behavior patterns:
- Curious – taps every visible element, tries long presses, swipes in unexpected directions.
- Impatient – rapid taps, rapid navigation, attempts to skip steps.
- Novice – relies heavily on labels and hints, avoids ambiguous icons.
- Adversarial – inputs malformed data, attempts to break validation, forces errors.
- Elderly – slower interactions, prefers larger touch targets.
- Accessibility – uses screen‑reader navigation, keyboard-only mode.
- Power user – uses shortcuts, tries to perform multiple actions quickly.
- Others – e.g., left‑handed, low‑vision, high‑contrast modes.
When you point SUSA at a web page containing your date picker, it will:
- Discover all reachable states – open the picker, navigate months, try direct entry, attempt to paste, etc., without any pre‑written script.
- Apply persona‑specific heuristics – the Adversarial persona will try to submit
2023-02-30or paste JavaScript snippets; the Impatient persona will spam the next‑month button 50 times in a second. - Detect observable failures – crashes, ANRs (for Android), dead buttons, validation messages that do not appear, accessibility violations (missing
aria-label, insufficient contrast), and unexpected navigation (e.g., picker closes unexpectedly). - Generate regression scripts – after a run, SUSA outputs Appium (Android) or Playwright (Web) scripts that reproduce the discovered flows, enabling you to add them to your CI pipeline.
Example: Cross‑Session Learning in Practice
Suppose your date picker disables weekends. During the first SUSA run, the Curious persona repeatedly taps on Saturday and Sunday cells, observes that nothing happens, and logs those interactions as “no‑effect”. On a subsequent run, SUSA remembers that Saturday/Sunday taps are ineffective and shifts focus to trying to enable those dates via the URL query param (if your picker supports a disabledDates parameter). If the implementation incorrectly enables a disabled date when a certain query string is present, SUSA will flag it as a defect.
This learning loop means that over time the agent runs, the test suite evolves from a static set of cases to a living specification that adapts to new code paths and edge conditions you may not have anticipated.
Practical Steps to Combine Both Approaches
- Start with your manual test matrix (the tables above) as your baseline.
- Run SUSA in discovery mode on a staging build. Export the generated Appium/Playwright scripts.
- Review the scripts – they often represent realistic user flows that you can convert into additional manual test cases (e.g., “Rapidly toggle month while the picker is loading data via AJAX”).
- Add the new cases to your test management tool, prioritize them using the risk matrix, and link them to requirements.
- **Integrate the scripts
Test Your App Autonomously
Upload your APK or URL. SUSA explores like 10 real users — finds bugs, accessibility violations, and security issues. No scripts.
Try SUSA Free