Repository navigation
Unit tests for QML Pickers and Selectors #380
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
Merged
suraj-yadav0
merged 4 commits into
CITOpenRep:release/v1.3.4
from
parvathyabnair:test-scripts
Oct 14, 2026
Merged
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
d3fe645
Unit tests for QML Pickers and Selectors
parvathyabnair 2cbb6b9
Merge branch 'release/v1.3.4' of https://github.com/CITOpenRep/timema…
parvathyabnair 6742c39
"merged"
parvathyabnair 49e1457
test: restore AssigneeFilterMenu tests and stabilize picker/selector …
parvathyabnair File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
suraj-yadav0 marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
|
suraj-yadav0 marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,121 @@ | ||
| import QtQuick 2.7 | ||
| import QtTest 1.0 | ||
| import Lomiri.Components 1.3 | ||
| import "../../qml/components/pickers" | ||
|
|
||
| MainView { | ||
| id: testRoot | ||
| width: units.gu(40) | ||
| height: units.gu(70) | ||
|
|
||
| DateRangeHeaderFilter { | ||
| id: testHeaderFilter | ||
| width: testRoot.width | ||
| } | ||
|
|
||
| SignalSpy { | ||
| id: dateRangeChangedSpy | ||
| target: testHeaderFilter | ||
| signalName: "dateRangeChanged" | ||
| } | ||
|
|
||
| TestCase { | ||
| name: "DateRangeHeaderFilterTests" | ||
| when: windowShown | ||
|
|
||
| function init() { | ||
| testHeaderFilter.clearFilter(); | ||
| testHeaderFilter.showClearButton = true; | ||
| dateRangeChangedSpy.clear(); | ||
| } | ||
|
|
||
| function cleanup() { | ||
| testHeaderFilter.clearFilter(); | ||
| dateRangeChangedSpy.clear(); | ||
| } | ||
|
|
||
| function test_initialProperties() { | ||
| compare(testHeaderFilter.presetId, -1); | ||
| compare(testHeaderFilter.startDate, ""); | ||
| compare(testHeaderFilter.endDate, ""); | ||
| compare(testHeaderFilter.isFiltered, false); | ||
| compare(testHeaderFilter.presetLabel, "No Filter (All Time)"); | ||
| compare(testHeaderFilter.showClearButton, true); | ||
| compare(dateRangeChangedSpy.count, 0); | ||
| } | ||
|
|
||
| function test_calculateDatesToday() { | ||
| var dates = testHeaderFilter.calculateDates(0); // Today | ||
| var todayStr = Qt.formatDate(new Date(), "yyyy-MM-dd"); | ||
| compare(dates.start, todayStr); | ||
| compare(dates.end, todayStr); | ||
| } | ||
|
|
||
| function test_calculateDatesThisMonth() { | ||
| var dates = testHeaderFilter.calculateDates(2); // This Month | ||
| var now = new Date(); | ||
| var expectedMonthPrefix = Qt.formatDate(now, "yyyy-MM"); | ||
| verify(dates.start.indexOf(expectedMonthPrefix + "-01") === 0); | ||
| verify(dates.end.indexOf(expectedMonthPrefix) === 0); | ||
| } | ||
|
|
||
| function test_calculateDatesThisYear() { | ||
| var dates = testHeaderFilter.calculateDates(4); // This Year | ||
| var y = new Date().getFullYear(); | ||
| compare(dates.start, y + "-01-01"); | ||
| compare(dates.end, y + "-12-31"); | ||
| } | ||
|
|
||
| function test_setFilterStateUpdatesPropertiesAndEmitsSignal() { | ||
| testHeaderFilter.setFilterState(1, "2026-10-12", "2026-10-18", "This Week"); | ||
|
|
||
| compare(testHeaderFilter.presetId, 1); | ||
| compare(testHeaderFilter.startDate, "2026-10-12"); | ||
| compare(testHeaderFilter.endDate, "2026-10-18"); | ||
| compare(testHeaderFilter.presetLabel, "This Week"); | ||
| compare(testHeaderFilter.isFiltered, true); | ||
|
|
||
| compare(dateRangeChangedSpy.count, 1); | ||
| var args = dateRangeChangedSpy.signalArguments[0]; | ||
| compare(args[0], 1); | ||
| compare(args[1], "2026-10-12"); | ||
| compare(args[2], "2026-10-18"); | ||
| compare(args[3], "This Week"); | ||
| } | ||
|
|
||
| function test_applyPresetTodayTogglesFilterAndRangeText() { | ||
| testHeaderFilter.applyPreset(0, "Today"); | ||
|
|
||
| compare(testHeaderFilter.isFiltered, true); | ||
| compare(testHeaderFilter.presetId, 0); | ||
| compare(testHeaderFilter.presetLabel, "Today"); | ||
| verify(testHeaderFilter.startDate !== ""); | ||
| verify(testHeaderFilter.endDate !== ""); | ||
| compare(dateRangeChangedSpy.count, 1); | ||
| } | ||
|
|
||
| function test_clearFilterResetsActiveFilterAndRangeText() { | ||
| testHeaderFilter.applyPreset(0, "Today"); | ||
| compare(testHeaderFilter.isFiltered, true); | ||
| dateRangeChangedSpy.clear(); | ||
|
|
||
| testHeaderFilter.clearFilter(); | ||
|
|
||
| compare(testHeaderFilter.isFiltered, false); | ||
| compare(testHeaderFilter.presetId, -1); | ||
| compare(testHeaderFilter.startDate, ""); | ||
| compare(testHeaderFilter.endDate, ""); | ||
| compare(testHeaderFilter.presetLabel, "No Filter (All Time)"); | ||
| compare(dateRangeChangedSpy.count, 1); | ||
| compare(dateRangeChangedSpy.signalArguments[0][0], -1); | ||
| } | ||
|
|
||
| function test_showClearButtonToggling() { | ||
| testHeaderFilter.showClearButton = false; | ||
| compare(testHeaderFilter.showClearButton, false); | ||
|
|
||
| testHeaderFilter.showClearButton = true; | ||
| compare(testHeaderFilter.showClearButton, true); | ||
| } | ||
| } | ||
| } |
|
suraj-yadav0 marked this conversation as resolved.
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,125 @@ | ||
| import QtQuick 2.7 | ||
| import QtTest 1.0 | ||
| import Lomiri.Components 1.3 | ||
| import "../../qml/components/pickers" | ||
|
|
||
| MainView { | ||
| id: testRoot | ||
| width: units.gu(40) | ||
| height: units.gu(70) | ||
|
|
||
| DateRangeSelector { | ||
| id: testDateRangeSelector | ||
| width: testRoot.width | ||
| } | ||
|
|
||
| SignalSpy { | ||
| id: rangeChangedSpy | ||
| target: testDateRangeSelector | ||
| signalName: "rangeChanged" | ||
| } | ||
|
|
||
| TestCase { | ||
| name: "DateRangeSelectorTests" | ||
| when: windowShown | ||
|
|
||
| function init() { | ||
| testDateRangeSelector.readOnly = false; | ||
| rangeChangedSpy.clear(); | ||
| } | ||
|
|
||
| function cleanup() { | ||
| testDateRangeSelector.readOnly = false; | ||
| rangeChangedSpy.clear(); | ||
| } | ||
|
|
||
| function test_initialProperties() { | ||
| verify(testDateRangeSelector.startDate instanceof Date); | ||
| verify(testDateRangeSelector.endDate instanceof Date); | ||
| compare(testDateRangeSelector.readOnly, false); | ||
| compare(testDateRangeSelector.isStartDateValid, true); | ||
| compare(testDateRangeSelector.isEndDateValid, true); | ||
| verify(testDateRangeSelector.presetSelector !== null); | ||
| } | ||
|
|
||
| function test_formattedDateStrings() { | ||
| var s = new Date(2026, 8, 15); // 2026-09-15 | ||
| var e = new Date(2026, 8, 20); // 2026-09-20 | ||
| testDateRangeSelector.setDateRange(s, e); | ||
|
|
||
| compare(testDateRangeSelector.formattedStartDate(), "2026-09-15"); | ||
| compare(testDateRangeSelector.formattedEndDate(), "2026-09-20"); | ||
| } | ||
|
|
||
| function test_setDateRangeWithDateObjects() { | ||
| var start = new Date(2026, 5, 1); | ||
| var end = new Date(2026, 5, 30); | ||
| rangeChangedSpy.clear(); | ||
|
|
||
| testDateRangeSelector.setDateRange(start, end); | ||
|
|
||
| compare(rangeChangedSpy.count, 1); | ||
| compare(testDateRangeSelector.isStartDateValid, true); | ||
| compare(testDateRangeSelector.isEndDateValid, true); | ||
| compare(testDateRangeSelector.startDate.getFullYear(), 2026); | ||
| compare(testDateRangeSelector.startDate.getMonth(), 5); | ||
| compare(testDateRangeSelector.startDate.getDate(), 1); | ||
| compare(testDateRangeSelector.endDate.getDate(), 30); | ||
| } | ||
|
|
||
| function test_setDateRangeWithStringInputs() { | ||
| rangeChangedSpy.clear(); | ||
| testDateRangeSelector.setDateRange("2026-11-05", "2026-11-25"); | ||
|
|
||
| compare(rangeChangedSpy.count, 1); | ||
| compare(testDateRangeSelector.isStartDateValid, true); | ||
| compare(testDateRangeSelector.isEndDateValid, true); | ||
| compare(testDateRangeSelector.formattedStartDate(), "2026-11-05"); | ||
| compare(testDateRangeSelector.formattedEndDate(), "2026-11-25"); | ||
| } | ||
|
|
||
| function test_setDateRangeInvalidBoundsHandling() { | ||
| testDateRangeSelector.setDateRange("not-a-date", null); | ||
|
|
||
| compare(testDateRangeSelector.isStartDateValid, false); | ||
| compare(testDateRangeSelector.isEndDateValid, false); | ||
| } | ||
|
|
||
| function test_updateDatesPresetToday() { | ||
| verify(testDateRangeSelector.presetSelector !== null, "presetSelector alias should be accessible"); | ||
|
|
||
| testDateRangeSelector.presetSelector.selectedId = 0; // Today | ||
| rangeChangedSpy.clear(); | ||
| testDateRangeSelector.updateDates(); | ||
|
|
||
| compare(rangeChangedSpy.count, 1); | ||
| compare(testDateRangeSelector.isStartDateValid, true); | ||
| compare(testDateRangeSelector.isEndDateValid, true); | ||
| var today = new Date(); | ||
| compare(testDateRangeSelector.startDate.getDate(), today.getDate()); | ||
| compare(testDateRangeSelector.endDate.getDate(), today.getDate()); | ||
| } | ||
|
|
||
| function test_updateDatesPresetThisMonth() { | ||
| verify(testDateRangeSelector.presetSelector !== null, "presetSelector alias should be accessible"); | ||
|
|
||
| testDateRangeSelector.presetSelector.selectedId = 3; // This Month | ||
| rangeChangedSpy.clear(); | ||
| testDateRangeSelector.updateDates(); | ||
|
|
||
| compare(rangeChangedSpy.count, 1); | ||
| var today = new Date(); | ||
| compare(testDateRangeSelector.startDate.getMonth(), today.getMonth()); | ||
| compare(testDateRangeSelector.endDate.getMonth(), today.getMonth()); | ||
| verify(testDateRangeSelector.endDate.getDate() >= 26); | ||
| } | ||
|
|
||
| function test_readOnlyStateToggling() { | ||
| testDateRangeSelector.readOnly = true; | ||
| compare(testDateRangeSelector.readOnly, true); | ||
|
|
||
| testDateRangeSelector.readOnly = false; | ||
| compare(testDateRangeSelector.readOnly, false); | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.