   constructor: (options) ->
     @$el = options.el
 
-  $: (selector) ->
+  $: (selector) =>
     @$el.find(selector)
 
-  hasCategoryList: ->
+  hasCategoryList: =>
     @$("option").length > 0
 
-  hasProductList: ->
+  hasProductList: =>
     @$(".epages-shop-product").length > 0
 
-  variationsLoaded: ->
+  isReady: =>
+    @hasCategoryList() && @hasProductList()
+
+  variationsLoaded: =>
     $(".pico-content").find(".epages-shop-variation").length > 0
 
-  hasCategoryOption: (name) ->
+  hasCategoryOption: (name) =>
     @$("option:contains(#{name})").length > 0
 
-  selectCategory: (name) ->
+  selectCategory: (name) =>
     value = @$("option:contains(#{name})").val()
     @$("select").val(value).change()
 
-  hasProduct: (name) ->
+  hasProduct: (name) =>
     @$(".epages-shop-product-name:contains(#{name})").length == 1
 
-  productLink: (name) ->
+  productLink: (name) =>
     @$("a .epages-shop-product-name:contains(#{name})")
 
 

  afterEach ->
    @$container.remove()

  it "loads site.js from another server", (done) ->
    widget = new TestWidget(el: $(".epages-shop-widget:first"))

    widgetLoaded = ->
      widget.hasCategoryList() && widget.hasProductList()

    waitFor widgetLoaded, ->
      expect(widget.hasCategoryOption("Shoes")).toBeTruthy()
      widget.selectCategory("Shoes")

      categoryLoaded = ->
        widget.hasProduct("Meindl RFS Tibet")

      waitFor categoryLoaded, ->
        widget.productLink("Meindl RFS Tibet").click()

        waitFor widget.variationsLoaded, ->
          expect( $("label[for='epages-shop-variation-USSize']").is(':visible') ).toBeTruthy()
          done()


waitUntil = (condition, args..., next) ->
  interval = setInterval ->
    if condition(args...)
      clearInterval(interval)
      next()
  , 10
