Skip to content

Commit

Permalink
ZK-5517: change the current year with a keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
JamsonChan committed Dec 12, 2023
1 parent e964513 commit 35fcb8b
Show file tree
Hide file tree
Showing 5 changed files with 107 additions and 0 deletions.
1 change: 1 addition & 0 deletions zkdoc/release-note
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ ZK 10.0.0
ZK-5221: Show websocket close reason
ZK-5018: Enhance simplified MVVM syntax
ZK-5516: change the current month with a keyboard
ZK-5517: change the current year with a keyboard

* Bugs
ZK-5393: Update ZK jars to jakarta-friendly uploads
Expand Down
21 changes: 21 additions & 0 deletions zktest/src/main/webapp/test2/F100-ZK-5517.zul
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
F100-ZK-5517.zul
Purpose:
Description:
History:
Fri Dec 08 18:18:11 CST 2023, Created by jamson
Copyright (C) 2023 Potix Corporation. All Rights Reserved.
-->
<zk>
<label multiline="true">
Click [Shift + PageUp], check whether it switched to the same month and date previous year.
Click [Shift + PageDown], check whether it switched to the same month and date next year.
note : If current date is 2/29 in a leap year, switching the year would go to the last day of February (2/28).
</label>
<calendar/>
</zk>
1 change: 1 addition & 0 deletions zktest/src/main/webapp/test2/config.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3796,6 +3796,7 @@ F86-ZK-4235.zul=A,E,datefmt,library-property
##zats##F100-ZK-5018-command.zul=A,E,MVVM,Syntax,simplified
##zats##F100-ZK-5018-syntax-exception.zul=A,E,MVVM,Syntax,simplified
##zats##F100-ZK-5516.zul=A,E,calendar,month,keyboard
##zats##F100-ZK-5517.zul=A,E,calendar,year,keyboard

# Complex Test Case
#
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/* F100_ZK_5517Test.java
Purpose:
Description:
History:
Fri Dec 08 18:44:37 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.WebDriverTestCase;
import org.zkoss.test.webdriver.ztl.Widget;

public class F100_ZK_5517Test extends WebDriverTestCase {
@Test
public void test() {
connect();

Actions actions = getActions();
Widget cld = jq("@calendar").toWidget();
String month = getMonth(cld);
int year = getYear(cld),
date = getDate();

click(jq(".z-calendar-selected"));
waitResponse();

if ("Feb".equals(month) && date == 29) {
date = 28;
actions.keyDown(Keys.ARROW_LEFT).perform();
}

actions.keyDown(Keys.SHIFT).keyDown(Keys.PAGE_UP).perform();
waitResponse();

assertEquals(year, getYear(cld) + 1);
assertEquals(month, getMonth(cld));
assertEquals(date, getDate());

actions.keyDown(Keys.SHIFT).keyDown(Keys.PAGE_DOWN).perform();
waitResponse();

actions.keyDown(Keys.SHIFT).keyDown(Keys.PAGE_DOWN).perform();
waitResponse();

assertEquals(year, getYear(cld) - 1);
assertEquals(month, getMonth(cld));
assertEquals(date, getDate());

actions.keyDown(Keys.SHIFT).keyDown(Keys.PAGE_UP).perform();
waitResponse();

assertEquals(year, getYear(cld));
assertEquals(month, getMonth(cld));
assertEquals(date, getDate());
}

public int getYear(Widget calendar) {
return Integer.parseInt(calendar.$n("ty").get("innerHTML"));
}

public String getMonth(Widget calendar) {
return calendar.$n("tm").get("innerHTML");
}

public int getDate() {
return Integer.parseInt(jq(".z-calendar-selected").toElement().get("innerHTML"));
}
}
6 changes: 6 additions & 0 deletions zul/src/main/resources/web/js/zul/db/Calendar.ts
Original file line number Diff line number Diff line change
Expand Up @@ -683,6 +683,12 @@ export class Calendar extends zul.Widget {
} else if (evt.key === 'PageDown') { // PageDown: next month
this._setView('month');
this._shift(1);
} else if (evt.shiftKey && evt.key === 'PageUp') { // Shift + PageUp: prev year
this._setView('year');
this._shift(-1);
} else if (evt.shiftKey && evt.key === 'PageDown') { // Shift + PageDown: next year
this._setView('year');
this._shift(1);
}
this._setView(currentView);

Expand Down

0 comments on commit 35fcb8b

Please sign in to comment.