Greetings,
I'm interested to learn how folks approach TDDing views which contain
tables. I've read about using various styles of presenters (Supervising
Controller, Passive View, etc.) and was interested to hear what experiences
folks have had. I've just been reading Jeremy D. Miller's series on TDDing
GUIs
<http://codebetter.com/blogs/jeremy.miller/archive/2007/07/25/the-build-your-own\
-cab-series-table-of-contents.aspx>and
they were quite good.
In my particular case, I'm using the Google Web Toolkit (GWT) and need to
display a table of data. The interesting bits are:
- The table has a variable number of columns based on the data set being
displayed
- The table only shows certain columns (and variations of widgets) based
upon the user's permissions
- Each row contains widgets which may have different states (for example,
one cell might contain a combobox with a button, or might be a string with
no widgets)
So far I've started to try out a Passive View approach, where the controller
tells the view to add each cell individually. This is fairly verbose, and
one way requires the controller to tell the view the specific row and
column, e.g.
...
view.addLabelWithTextAt(5, 10, "Hello"); // row 5, column 10
view.addTitleSelectBoxAt(5, 11, listOfStringTitles, indexOfSelectedItem);
view.setReadOnlyList(5, 12, anotherListOfOptions);
...
This feels fairly chatty, and sometimes slightly awkward --- e.g. creating a
Select Box with a list of all valid options and the index/value selected in
one call. The advantage here is that it's very explicit in the view and I
could test this behavior.
Then, the view calls back to the controller with an index of the row that
received an event, so the controller can find the corresponding model in its
list. e.g. in the view
checkbox.addChangeListener() {
...
controller.titleChanged(11); // the Title Select Box widget is created
with a row # index
..
}
I know an alternative to Passive View would be a Supervising Controller,
where the View could take the set of model objects and explicitly map and
create all the columns needed. e.g. in the controller:
view.setPeopleList(people);
Since there are requirements that the table column length varies based upon
the data set, and some controls vary based upon permissions, this seems to
encode a lot of responsibility in the view... and that responsibility will
be trickier to test. (However, GWT does provide a test case which lets you
instantiate widgets in isolation, so perhaps this is another way to test.)
Can anyone comment on their experiences with this kind of work?
Thanks,
Dan
[Non-text portions of this message have been removed]