import aiviro

URLS = [
    "http://todomvc.com/examples/vanillajs/",
    "http://todomvc.com/examples/backbone/",
    "http://todomvc.com/examples/angularjs/#/",
    "http://todomvc.com/examples/emberjs/",
    "http://todomvc.com/examples/knockoutjs/",
    "http://todomvc.com/examples/dojo/",
    "http://todomvc.com/examples/knockback/",
    "http://todomvc.com/examples/canjs/",
    "http://todomvc.com/examples/polymer/index.html",
    "http://todomvc.com/examples/react/#/",
    "http://todomvc.com/examples/mithril/#/",
    "http://todomvc.com/examples/vue/",
    "http://todomvc.com/examples/backbone_marionette/",
]


if __name__ == "__main__":
    # init aiviro logger
    aiviro.init_logging()

    #################
    # Test case
    #################
    # create web-robot
    r = aiviro.create_web_robot(headless=True)

    for url in URLS:
        r.go_to_url_in_new_tab(url)

        # create Input search-object & wait until it appears on the website
        input_object = aiviro.Or(
            aiviro.Button("What needs to be done?", element_index=0),
            aiviro.Input("What needs to be done?", element_index=0),
        )
        input_box = r.wait_for(input_object, timeout=15)

        # add 3 tasks into list
        r.type_text(input_box, "Do the laundry\n")
        r.type_text(input_box, "Go shopping\n")
        r.type_text(input_box, "Pay the bills\n")

        # wait until the last task appears in the list
        r.wait_for(aiviro.Text("Pay the bills"), timeout=10)
        do_the_laundry_label = aiviro.Text("Do the laundry")
        go_shopping_label = aiviro.Text("Go shopping")
        pay_the_bills_label = aiviro.Text("Pay the bills")

        # check different alignment of the elements
        r.check_are_in_column(
            do_the_laundry_label,
            go_shopping_label,
            pay_the_bills_label,
            anchor=aiviro.layout_anchor.LEFT,
            tolerance=10,
        )
        r.check_is_positioned(
            do_the_laundry_label,
            go_shopping_label,
            direction_type=aiviro.layout_positions.IS_ABOVE,
        )
        r.check_is_positioned(
            pay_the_bills_label,
            go_shopping_label,
            direction_type=aiviro.layout_positions.IS_BELOW,
        )

    # close the web-robot
    r.close()
