Thanks for your answer, I'll try this out today.
On Feb 14, 2013, at 11:53 AM, Ernesto Reinaldo Barreiro reier...@gmail.com
wrote:
Hi,
On Thu, Feb 14, 2013 at 10:12 AM, Ulf Gitschthaler
ulf.gitschtha...@comsysto.com wrote:
In most cases I want to simulate a user typing something in and selecting
one of the offered choices. Afterwards I'd also like to submit the form and
check if the model object of the Select2Choice field contains the right
value, respectively I want to be able to submit the form if a Select2Choice
field is a required field.
Mind that this component do is:
1- It implements IResourceListener to be able to stream back JSON like:
{results:[{id:2,text:Air Show},{id:180,text:American
Football},{id:4,text:Anniversary
},{id:6,text:Aquarium},{id:116,text:Babies},{id:8,text:Bar},{id:10,text:Baseball},{id:12,text:Basketball},{id:14,text:Beach
Volleyball},{id:16,text:Beergarden},{id
:18,text:Billard},{id:22,text:Botellón},{id:20,text:Bowling},{id:24,text:Bullfight},{id:36,text:Cafeteria},{id:26,text:Casino},{id:28,text:Child
Museum},{id:176,text
:Childrem},{id:30,text:Cinema},{id:32,text:Circus},{id:34,text:Climbing},{id:38,text:Comedy
Club},{id:110,text:Concert},{id:40,text:Cricket},{id:42,text:DanceClass},{id:44,text:Dancing},{id:46,text:Daycare},{id:48,text:Deep
Sea Fishing},{id
:50,text:Dinopark},{id:52,text:Diving},{id:54,text:Fair},{id:206,text:Family},
{id:208,text:Female},{id:56,text:Fireworks},{id:58,text:Fishing},{id:182,text:Forest
},{id:60,text:Gay-Female},{id:62,text:Gay-Male},{id:64,text:Golfing},{id:66,text:Handball},{id:68,text:Hang
Gliding},{id:70,text:Hiking},{id:108,text:Hiphop
Concert},{id:72,text:Historical
Museum},{id:74,text:Horse
Riding},{id:76,text:Hunting},{id:78,text:Jazz
Club},{id:80,text:Kayaking},{id:82,text:Kitesurfing},{id:84,text:Library},{id:184,text:Love},{id:86,text:Magic
Show},{id:178,text:Male},{id:88,text:Mountainbiking
},{id:90,text:Museum-Archeological},{id:92,text:Museum-Art},{id:94,text:Museum-Crafts
},{id:96,text:Museum-Industry},{id:98,text:Museum-Naval},{id:100,text:Museum-Science
},{id:102,text:Museum-War},{id:104,text:Music-choral},{id:106,text:Music-Classical
},{id:114,text:Nanny},{id:118,text:Paintball},{id:120,text:Paragliding},{id:122,text
:Parasailing},{id:124,text:Party},{id:126,text:Planetarium},{id:128,text:Playground},{id:130,text:Poker},{id:132,text:Public
Art},{id:112,text:Rock Concert},{id:134,text:Ropes
course},{id:136,text:Row Boat},{id:138,text:Rugby
field},{id:140,text:Sailing},{id:142,text:Scout
group},{id:144,text:Scuba
Diving},{id:146,text:Snorkeling},{id:148,text:soccer},{id:150,text:Speed
riding},{id:152,text:spelunking},{id:154,text:Squash},{id:156,text:Strip
Club},{id:160,text:Surf
Paddle},{id:158,text:Surfing},{id:162,text:Swimming},{id:166,text:Table
Tennis},{id:164,text:Tea
House},{id:168,text:Tennis},{id:170,text:Terrace},{id:172,text:Theater},{id:174,text:Theme
Park},{id:186,text:Video
Games},{id:188,text:Volleyball},{id:190,text:Walking
Tour},{id:194,text:Water Park},{id:196,text:Water
Skiing},{id:192,text:Watercraft},{id:198,text:Windsurfing},{id:200,text:Wine
bar},{id:202,text:Wine Tasting},{id:204,text:Zoo}],more:null}
For this it uses ChoiceProvider. So, you could test user typing directly
using ChoiceProvider or for instance
https://github.com/reiern70/wicket-select2/blob/master/wicket-select2/src/main/java/com/vaynberg/wicket/select2/AbstractSelect2Choice.java#L235
to test produced JSON. (This is not part of offcial select2 but it is a
pending pull request). Maybe I can factor out this a bit more and add a
method that receives int page and String term so that testing is even
easier.
2-On client side widget uses a hidden input to represent selections as
input id=what-input class=round-3-nopad type=hidden name=categories
value=2,4 style=display: none;
Those selected values are initially assigned via JSON when widget is
constructed. See method
https://github.com/reiern70/wicket-select2/blob/master/wicket-select2/src/main/java/com/vaynberg/wicket/select2/Select2MultiChoice.java#L114
So one way... to simulate this might be as in
TestMultiSelectPage testPage =tester.startPage(TestMultiSelectPage.class);
tester.assertRenderedPage(TestMultiSelectPage.class);
tester.getRequest().setParameter(countries, Country.CU.name()+,+
Country.CA.name());
tester.submitForm(testPage.getForm());
Assert.assertTrue(testPage.getCountries().contains(Country.CU));
Assert.assertTrue(testPage.getCountries().contains(Country.CA));
Assert.assertTrue(!testPage.getCountries().contains(Country.US));
So, you simulate client side working by passing a parameter with the
selected choices.
See
https://github.com/reiern70/wicket-select2/blob/master/wicket-select2-examples/src/test/java/com/vaynberg/wicket/select2/SelectTest.java
--
Regards - Ernesto Reinaldo Barreiro
Antilia Soft
http://antiliasoft.com/