54 lines
1.6 KiB
Ruby
54 lines
1.6 KiB
Ruby
module SpecEmberHelpers
|
|
def ember_store
|
|
h = page.evaluate_script <<-SCRIPT
|
|
$s = App.__container__.lookup('store:main');
|
|
JSON.stringify({
|
|
lists: $s.all('list').invoke('serialize'),
|
|
orders: $s.all('order').invoke('serialize'),
|
|
product_orders: $s.all('product_order').invoke('serialize'),
|
|
product_categories: $s.all('product_category').invoke('serialize'),
|
|
products: $s.all('product').invoke('serialize'),
|
|
sections: $s.all('section').invoke('serialize'),
|
|
tables: $s.all('table').invoke('serialize')
|
|
})
|
|
SCRIPT
|
|
JSON.parse(h)
|
|
end
|
|
|
|
def assert_element_class(selector, class_name)
|
|
find selector # capybara wait for element
|
|
time = 0
|
|
classes = page.evaluate_script("$('#{selector}').attr('class')")
|
|
while !classes.include?(class_name) and time < 10
|
|
sleep 0.1
|
|
classes = page.evaluate_script("$('#{selector}').attr('class')")
|
|
time += 1
|
|
end
|
|
classes.should include class_name
|
|
end
|
|
|
|
def js_set_field(selector, value)
|
|
page.execute_script("$('#{selector}').val('#{value}').trigger('change')")
|
|
end
|
|
|
|
def ember_find(typeKey, id)
|
|
h = page.evaluate_script <<-SCRIPT
|
|
App.__container__.lookup('store:main').all('#{typeKey}').findBy('id', '#{id}').serialize()
|
|
SCRIPT
|
|
end
|
|
|
|
def ember_all(typeKey)
|
|
h = page.evaluate_script <<-SCRIPT
|
|
App.__container__.lookup('store:main').all('#{typeKey}').invoke('serialize')
|
|
SCRIPT
|
|
end
|
|
|
|
def js_path
|
|
page.evaluate_script 'location.pathname + location.hash'
|
|
end
|
|
|
|
def faye_log
|
|
JSON.parse(page.evaluate_script(%|JSON.stringify(window.faye_log)|))
|
|
end
|
|
end
|