scinote-web/features/step_definitions/shared_steps.rb

99 lines
2.5 KiB
Ruby
Raw Normal View History

2017-10-10 15:17:55 +08:00
When(/^I click "(.+)" button$/) do |button|
click_on(button)
2017-07-06 15:07:05 +08:00
end
Given(/^Show me the page$/) do
save_and_open_page
end
2017-07-06 15:07:05 +08:00
Then(/^I should be redirected to the homepage$/) do
current_path.should =~ /^\/$/
end
2017-10-10 15:17:55 +08:00
Given(/^I click "(.+)" link$/) do |link|
2017-07-06 15:07:05 +08:00
click_link link
end
2017-10-11 15:51:20 +08:00
Given(/^I click "(.+)" link within "(.+)"$/) do |link, element|
within(element) do
2017-10-11 15:51:20 +08:00
click_link link
end
end
2017-10-10 15:17:55 +08:00
Then(/^I should see "(.+)"$/) do |text|
wait_for_ajax
2017-07-06 15:07:05 +08:00
expect(page).to have_content(text)
end
Then(/^I should be on homepage$/) do
expect(page).to have_current_path(root_path)
end
2017-10-10 15:17:55 +08:00
Given(/^the "([^"]*)" team exists$/) do |team_name|
FactoryGirl.create(:team, name: team_name)
end
Given(/^I'm on the home page of "([^"]*)" team$/) do |team_name|
team = Team.find_by_name(team_name)
@current_user.update_attribute(:current_team_id, team.id)
visit root_path
end
Given(/^"([^"]*)" is in "([^"]*)" team as a "([^"]*)"$/) do |user_email, team_name, role|
team = Team.find_by_name(team_name)
user = User.find_by_email(user_email)
2017-10-11 15:51:20 +08:00
FactoryGirl.create( :user_team, user: user,
team: team,
role: UserTeam.roles.fetch(role))
2017-10-10 15:17:55 +08:00
end
Then(/^I attach a "([^"]*)" file to "([^"]*)" field$/) do |file, field_id|
wait_for_ajax
attach_file(field_id, Rails.root.join('features', 'assets', file))
# "expensive" operation needs some time :=)
sleep(0.3)
2017-10-10 15:17:55 +08:00
end
Then(/^I should see "([^"]*)" error message under "([^"]*)" field$/) do |message, field_id|
parent = find_by_id(field_id).first(:xpath, './/..')
2017-10-11 15:51:20 +08:00
expect(parent).to have_content(message)
2017-10-10 15:17:55 +08:00
end
2017-10-11 15:51:20 +08:00
Then(/^I click on "([^"]*)"$/) do |button|
click_on button
2017-10-10 15:17:55 +08:00
end
2017-10-11 15:51:20 +08:00
Then(/^I click on image within "([^"]*)" element$/) do |container|
within(container) do
find('img').click
end
wait_for_ajax
2017-10-10 15:17:55 +08:00
end
Then(/^I should see "([^"]*)" flash message$/) do |message|
wait_for_ajax
expect(find_by_id('alert-flash')).to have_content(message)
2017-10-10 15:17:55 +08:00
end
Then(/^I click on Edit on "([^"]*)" input field$/) do |container_id|
wait_for_ajax
container = page.find_by_id(container_id)
within(container) do
find('button').click
end
2017-10-10 15:17:55 +08:00
end
Then(/^I fill in "([^"]*)" in "([^"]*)" input field$/) do |text, container_id|
container = page.find_by_id(container_id)
container.find('input').set(text)
2017-10-10 15:17:55 +08:00
end
Then(/^I should see "([^"]*)" in "([^"]*)" input field$/) do |text, container_id|
container = page.find_by_id(container_id)
expect(container).to have_xpath("//input[@value='#{text}']")
2017-10-10 15:17:55 +08:00
end
Given("I click {string} icon") do |id|
find(:css, id).click
end