diff --git a/zkdoc/release-note b/zkdoc/release-note index b4e884a9b0..915d8e649a 100644 --- a/zkdoc/release-note +++ b/zkdoc/release-note @@ -2,6 +2,7 @@ ZK 10.0.0 * Features ZK-5221: Show websocket close reason ZK-5517: change the current year with a keyboard + ZK-5516: change the current month with a keyboard * Bugs ZK-5393: Update ZK jars to jakarta-friendly uploads diff --git a/zktest/src/main/webapp/test2/F100-ZK-5516.zul b/zktest/src/main/webapp/test2/F100-ZK-5516.zul new file mode 100644 index 0000000000..bf00471f2f --- /dev/null +++ b/zktest/src/main/webapp/test2/F100-ZK-5516.zul @@ -0,0 +1,21 @@ + + + + + + \ No newline at end of file diff --git a/zktest/src/main/webapp/test2/config.properties b/zktest/src/main/webapp/test2/config.properties index dfd584601a..bb142bf841 100644 --- a/zktest/src/main/webapp/test2/config.properties +++ b/zktest/src/main/webapp/test2/config.properties @@ -3791,6 +3791,7 @@ F86-ZK-4235.zul=A,E,datefmt,library-property ##manually##F100-ZK-4494.zul=A,E,Tree,CSS ##manually##F100-ZK-4494-1.zul=A,E,Tree,CSS ##zats##F100-ZK-5517.zul=A,E,calendar,year,keyboard +##zats##F100-ZK-5516.zul=A,E,calendar,month,keyboard # Complex Test Case # diff --git a/zktest/src/test/java/org/zkoss/zktest/zats/test2/F100_ZK_5516Test.java b/zktest/src/test/java/org/zkoss/zktest/zats/test2/F100_ZK_5516Test.java new file mode 100644 index 0000000000..3c04b1c160 --- /dev/null +++ b/zktest/src/test/java/org/zkoss/zktest/zats/test2/F100_ZK_5516Test.java @@ -0,0 +1,87 @@ +/* F100_ZK_5516Test.java + + Purpose: + + Description: + + History: + Sun Dec 10 23:07:36 CST 2023, Created by jamson + +Copyright (C) 2023 Potix Corporation. All Rights Reserved. +*/ +package org.zkoss.zktest.zats.test2; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.Test; +import org.openqa.selenium.Keys; +import org.openqa.selenium.interactions.Actions; + +import org.zkoss.test.webdriver.ztl.Widget; + +public class F100_ZK_5516Test extends F100_ZK_5517Test { + int[] toLastDate = new int[] {31, 28, 31, 30, 31, 30 ,31, 31, 30, 31, 30, 31}; + String[] toMonth = new String[] {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"}; + int date; + Widget cld; + @Test + public void test() { + connect(); + + click(jq(".z-calendar-selected")); + waitResponse(); + + Actions actions = getActions(); + cld = jq("@calendar").toWidget(); + String month = getMonth(cld); + date = getDate(); + + actions.keyDown(Keys.PAGE_UP).perform(); + waitResponse(); + + assertEquals(toMonth(month, -1), getMonth(cld)); + assertEquals(verifyDate(), getDate()); + + actions.keyDown(Keys.PAGE_DOWN).perform(); + waitResponse(); + + actions.keyDown(Keys.PAGE_DOWN).perform(); + waitResponse(); + + assertEquals(toMonth(month, 1), getMonth(cld)); + assertEquals(verifyDate(), getDate()); + + actions.keyDown(Keys.PAGE_UP).perform(); + waitResponse(); + + assertEquals(month, getMonth(cld)); + assertEquals(verifyDate(), getDate()); + } + + public int toMonthNum(String month) { + if ("Jan".equals(month)) return 0; + else if ("Feb".equals(month)) return 1; + else if ("Mar".equals(month)) return 2; + else if ("Apr".equals(month)) return 3; + else if ("May".equals(month)) return 4; + else if ("Jun".equals(month)) return 5; + else if ("Jul".equals(month)) return 6; + else if ("Aug".equals(month)) return 7; + else if ("Sep".equals(month)) return 8; + else if ("Oct".equals(month)) return 9; + else if ("Nov".equals(month)) return 10; + else return 11; + } + + public String toMonth(String month, int offset) { + return toMonth[(toMonthNum(month) + offset + 12) % 12]; + } + + public int verifyDate() { + String month = getMonth(cld); + int year = getYear(cld), + lastDate = (year % 4 == 0) && ("Feb".equals(month)) ? 29 : toLastDate[toMonthNum(month)]; + date = Math.min(date, lastDate); + return date; + } +} diff --git a/zul/src/main/resources/web/js/zul/db/Calendar.ts b/zul/src/main/resources/web/js/zul/db/Calendar.ts index e6106cd394..77370ddc2d 100644 --- a/zul/src/main/resources/web/js/zul/db/Calendar.ts +++ b/zul/src/main/resources/web/js/zul/db/Calendar.ts @@ -683,6 +683,12 @@ export class Calendar extends zul.Widget { } else if (evt.shiftKey && evt.key === 'PageDown') { // Shift + PageDown: next year this._setView('year'); this._shift(1); + } else if (evt.key === 'PageUp') { // PageUp: prev month + this._setView('month'); + this._shift(-1); + } else if (evt.key === 'PageDown') { // PageUp: next month + this._setView('month'); + this._shift(1); } this._setView(currentView);