On Wed, 11 Feb 2009, ray bon wrote:
> I am trying to test the case where a user is changing the set of checked
> options for a CheckBoxMultipleChoice. When using FormTester.selectMultiple
> the new values are added rather than replacing the existing values.
...
> How do I get FormTester to unselect values?
Sounds like a fair enough feature, could you please add a
Jira issue?
Meanwhile you can do
formTester.setValue("checkBoxMultipleChoice", "");
in between to get the values reset.
E.g. this works in FormTesterTest as far as I can tell:
public void
testSelectingMultipleCheckboxesAfterSubmitResetsPreviousSelections()
{
assertBooksEquals(new Book[0],
choicePage.checkBoxMultipleChoice);
formTester.selectMultiple("checkBoxMultipleChoice", new int[] {
1, 0, 3 });
formTester.submit();
assertBooksEquals(new Book[] { books[0], books[1], books[3] },
choicePage.checkBoxMultipleChoice);
formTester = tester.newFormTester("choiceForm");
formTester.setValue("checkBoxMultipleChoice", "");
formTester.selectMultiple("checkBoxMultipleChoice", new int[] {
2 });
formTester.submit();
assertBooksEquals(new Book[] { books[2] },
choicePage.checkBoxMultipleChoice);
}
> I know I can look at the source code and extend this class, but this seems
> like an awkward solution for what appears to me to be a very common use
> case.
I don't think that it's so common, though. With WicketTester
tests, it's more normal to have the very small and focused
and not submit different selections.
If you're doing something on each selection, it should typically
be Ajax and then you should be doing executeAjaxEvent()s anyway.
Best wishes,
Timo
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]