/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package pizzaorderintl;

import java.util.Arrays;
import java.util.List;
import org.uispec4j.*;
import org.uispec4j.interception.*;
import pizzaorder.GUI;

/**
 *
 * @author Bryan McGuffin
 */
public class PizzaOrderIntlGUITest extends UISpecTestCase
{

    public PizzaOrderIntlGUITest(String testName)
    {
        super(testName);
    }

    public void testPizzaGUI()
    {
        GUI view = new GUI();

        Window win = new Window(view);

        ComboBox langBox = win.getComboBox();

        assertTrue(langBox.contains("en / English"));

        langBox.select("en / English");

        final List<String> tops = Arrays.asList("Onions", "Olives", "Peppers", "Tomatoes");

        for (String top : tops)
        {
            assertFalse(win.getCheckBox(top).isSelected());
            win.getCheckBox(top).select();
        }

        for (String top : tops)
        {
            assertTrue(win.getCheckBox(top).isSelected());
        }

        final List<String> nonTops = Arrays.asList("Mushrooms", "Pepperoni");
        
        for (String n : nonTops)
        {
            assertFalse(win.getCheckBox(n).isSelected());
        }
        
        Button submitButton = win.getButton("Submit");
        
        WindowInterceptor inter = WindowInterceptor.init(submitButton.triggerClick());
        
        
        inter.process(new WindowHandler()
        {

            @Override
            public Trigger process(Window window) throws Exception
            {
                String message1 = "You ordered a pizza with these toppings:";
                
                assertTrue(window.containsLabel(message1));
                
                for(String t: tops)
                {
                    assertTrue(window.containsLabel(t));
                }
                
                return window.getButton("OK").triggerClick();
            }
        }).run();
        
        
    }
    // TODO add test methods here. The name must begin with 'test'. For example:
    // public void testHello() {}
}
