Skip to content

Commit

Permalink
ZK-5516: unable to change the current month with a keyboard
Browse files Browse the repository at this point in the history
  • Loading branch information
JamsonChan committed Dec 10, 2023
1 parent 751975a commit 3f3ba31
Show file tree
Hide file tree
Showing 5 changed files with 116 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 @@ -11,6 +11,7 @@ ZK 10.0.0
ZK-5037: invisible first column hides checkmarks in a listbox
ZK-5535: TrackerImplEx#removeAllReference accesses map value by iteration instead of key, lowers performance
ZK-5517: unable to change the current year with a keyboard
ZK-5516: unable to change the current month with a keyboard

* Upgrade Notes
+ Upgrade commons-fileupload to commons-fileupload2-javax 2.0.0-M1 and commons-io to 2.13.0 to support jakarta-friendly uploads
Expand Down
21 changes: 21 additions & 0 deletions zktest/src/main/webapp/test2/B100-ZK-5516.zul
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
B100-ZK-5516.zul
Purpose:
Description:
History:
Sun Dec 10 23:03:30 CST 2023, Created by jamson
Copyright (C) 2023 Potix Corporation. All Rights Reserved.
-->
<zk>
<label multiline="true">
Click [PageUp], check whether it switched to the same date previous month.
Click [PageDown], check whether it switched to the same date next month.
note : If current date exceed the last date of prev or next month, the date would go to the last day of the month.
</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 @@ -3165,6 +3165,7 @@ B90-ZK-4431.zul=A,E,Multislider
##zats##B100-ZK-5393.zul=A,E,FileUpload,JakartaEE
##zats##B100-ZK-5535.zul=A,E,performance,tree,mvvm,trackerNode,treeModel
##zats##B100-ZK-5517.zul=A,E,calendar,year,keyboard
##zats##B100-ZK-5516.zul=A,E,calendar,month,keyboard

##
# Features - 3.0.x version
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
/* B100_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 B100_ZK_5516Test extends B100_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;
}
}
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.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);

Expand Down

0 comments on commit 3f3ba31

Please sign in to comment.