01: // Copyright (C) 2003,2004,2005 by Object Mentor, Inc. All rights reserved.
02: // Released under the terms of the GNU General Public License version 2 or later.
03: package fitnesse.wikitext.widgets;
04:
05: import fitnesse.wikitext.WikiWidget;
06: import junit.framework.TestCase;
07: import junit.swingui.TestRunner;
08:
09: public class TableRowWidgetTest extends TestCase {
10: public static void main(String[] args) {
11: TestRunner
12: .main(new String[] { "fitnesse.wikitext.widgets.TableRowWidgetTest" });
13: }
14:
15: public void setUp() throws Exception {
16: }
17:
18: public void tearDown() throws Exception {
19: }
20:
21: public void testSimpleRow() throws Exception {
22: TableWidget table = new TableWidget(new MockWidgetRoot(), "");
23: TableRowWidget row = new TableRowWidget(table, "|a", false);
24: assertEquals(1, row.numberOfChildren());
25: WikiWidget child = row.nextChild();
26: assertEquals(TableCellWidget.class, child.getClass());
27: TableCellWidget cell = (TableCellWidget) child;
28: assertEquals(1, cell.numberOfChildren());
29: child = cell.nextChild();
30: assertEquals(TextWidget.class, child.getClass());
31: assertEquals("a", ((TextWidget) child).getText());
32: }
33:
34: public void testDifferentSizeRows() throws Exception {
35: TableRowWidget row;
36: TableCellWidget cell;
37:
38: TableWidget table = new TableWidget(new MockWidgetRoot(),
39: "|a|\n|a|b|c|d|e|f|\n|a|b|c|d|\n");
40: assertEquals(3, table.numberOfChildren());
41: assertEquals(6, table.getColumns());
42:
43: row = (TableRowWidget) table.children.get(0);
44: assertEquals(1, row.getColumns());
45: row = (TableRowWidget) table.children.get(1);
46: assertEquals(6, row.getColumns());
47: row = (TableRowWidget) table.children.get(2);
48: assertEquals(4, row.getColumns());
49:
50: cell = (TableCellWidget) row.getChildren().get(0);
51: assertEquals("a", ((TextWidget) cell.children.get(0)).getText());
52: cell = (TableCellWidget) row.getChildren().get(3);
53: assertEquals("d", ((TextWidget) cell.children.get(0)).getText());
54: }
55:
56: public void testColspanRows() throws Exception {
57: TableRowWidget row;
58: TableCellWidget cell;
59: // make sure first column of first row isn't affected
60:
61: TableWidget table = new TableWidget(new MockWidgetRoot(),
62: "|a|\n|a|b|c|d|e|f|\n|a|b|c|d|\n");
63: assertEquals(3, table.numberOfChildren());
64: assertEquals(6, table.getColumns());
65:
66: row = (TableRowWidget) table.children.get(2);
67: assertEquals(4, row.getColumns());
68:
69: // int currentColumn = row.children.indexOf(this) + 1;
70: int maxTableColumn = row.getParentTable().getColumns();
71: int maxColumnThisRow = row.numberOfChildren();
72:
73: assertEquals(maxTableColumn, 6);
74: assertEquals(maxColumnThisRow, 4);
75:
76: cell = (TableCellWidget) row.getChildren().get(3);
77: assertEquals("d", ((TextWidget) cell.children.get(0)).getText());
78:
79: String renderedCell = cell.render();
80: assertFalse(renderedCell
81: .indexOf("<td colspan=\"3\" class=\"column4\">d</td>") == -1);
82: }
83: }
|