Unit Test ZK Spreadsheet Using ZATS
Sam Chuang, Engineer, Potix Corporation
August 22, 2012
ZATS Mimic 1.0.0, ZK Spreadsheet 2.3.0
Introduction
ZK Spreadsheet is a mega component contains toolbar, context menu etc... Using web browser testing framework to unit test will be a time-consuming task. Luckily, ZK has ZATS!
For ZATS introduction, please refer to ZATS Essentials or Shining ZATS Mimic. In ZATS, it doesn't provide a agent that perform ZK Spreadsheet action. Thus, we need to write a SpreadsheetAgent that send spreadsheet command.
Test cases
Let's start by consider two test cases that targeting ZK Spreadsheet App
Test case 1
- User input "1" in cell A1
- Input "2" in cell B1
- Input "=A1+B1" in cell C3
Test case 2
- User right click on a cell, then ZK Spreadsheet open a context menu.
- Click "Format Number" menuitem.
- ZK Spreadsheet App then popup a "Number Format" dialog
Post Command
We can use ClientCtrl.postUpdate to send command to ZK Spreadsheet. To observe the command name and arguments need to send to ZK Spreadsheet, we can use Firebug's Console Tab.
ZK Spreadsheet First Load
When browser first load a page contains ZK Spreadsheet, it will send "onZSSSyncBlock" command. This command is used for sync the client side information with Server.
private void syncBlock() {
//Note. "fake" client data. For example, client panel height
String desktopId = spreadsheet.getDesktop().getId();
Map<String, Object> syncBlockData = new HashMap<String, Object>();
syncBlockData.put("sheetId", spreadsheet.getUuid());
syncBlockData.put("dpWidth", 640); //pixel value of data panel width
syncBlockData.put("dpHeight", 380); //pixel value of data panel height
syncBlockData.put("viewWidth", 800);
syncBlockData.put("viewHeight", 500);
syncBlockData.put("blockLeft", 0);
syncBlockData.put("blockTop", 0);
syncBlockData.put("blockRight", 9);
syncBlockData.put("blockBottom", 19);
syncBlockData.put("fetchLeft", -1);
syncBlockData.put("fetchTop", -1);
syncBlockData.put("fetchWidth", -1);
syncBlockData.put("fetchHeight", -1);
syncBlockData.put("rangeLeft", 0);
syncBlockData.put("rangeTop", 0);
syncBlockData.put("rangeRight", 9);
syncBlockData.put("rangeBottom", 19);
((ClientCtrl)getClient()).postUpdate(desktopId, "onZSSSyncBlock", spreadsheet.getUuid(), syncBlockData, null);
}
Edit Cell
Click Context Menu Item
- Right click on a cell
- Click Menuitem