scinote-web/features/step_definitions/shared_steps.rb

148 lines
3.7 KiB
Ruby
Raw Normal View History

2017-10-10 15:17:55 +08:00
When(/^I click "(.+)" button$/) do |button|
2018-04-26 19:47:31 +08:00
click_button(button)
2017-07-06 15:07:05 +08:00
end
Then("I trigger click {string}") do |string|
page.execute_script("$('#{string}').trigger('click')")
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
Then(/^I click "(.+)" link within dropdown menu$/) do |link|
within('.dropdown-menu') do
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|
FactoryBot.create(:team, name: team_name)
2017-10-10 15:17:55 +08:00
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)
FactoryBot.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 :=)
2017-11-02 23:24:11 +08:00
sleep(0.5)
2017-10-10 15:17:55 +08:00
end
2018-01-31 19:05:45 +08:00
Then(/^I should see "([^"]*)" error message$/) do |message|
2017-10-24 15:45:35 +08:00
wait_for_ajax
2018-01-31 19:05:45 +08:00
expect(page).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|
2017-11-02 23:24:11 +08:00
sleep 0.5
2017-10-11 15:51:20 +08:00
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('.alert')).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
2018-01-31 19:05:45 +08:00
within(container_id) do
find('[data-action="edit"]').click
end
2017-10-10 15:17:55 +08:00
end
2017-11-02 23:24:11 +08:00
Then(/^I fill in "([^"]*)" in "([^"]*)" input field$/) do |text, input_id|
2018-01-31 19:05:45 +08:00
page.find("#{input_id} input[type=\"text\"]").set(text)
end
Then(/^I fill in "([^"]*)" in "([^"]*)" field$/) do |text, input_id|
page.find(input_id).set(text)
2017-10-10 15:17:55 +08:00
end
Then(/^I should see "([^"]*)" in "([^"]*)" input field$/) do |text, container_id|
2018-01-31 19:05:45 +08:00
container = page.find(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
Then(/^(?:|I )click on "([^"]*)" element$/) do |selector|
find(selector).click
end
Then(/^I change "([^"]*)" with "([^"]*)" in "([^"]*)" input field$/) do |old_text, new_text, container_id|
2018-01-31 19:05:45 +08:00
wait_for_ajax
container = page.find_by_id(container_id)
expect(container).to have_xpath("//input[@value='#{old_text}']")
container.find('input').set(new_text)
end
Then(/^I fill in "([^"]*)" in "([^"]*)" textarea field$/) do |text, textarea_id|
textarea = page.find_by_id(textarea_id)
textarea.set(text)
end
Then(/^I change "([^"]*)" with "([^"]*)" in "([^"]*)" textarea field$/) do |old_text, new_text, textarea_id|
textarea = page.find_by_id(textarea_id)
expect(textarea).to have_content(old_text)
textarea.set(new_text)
end
Then(/^I should not see "([^"]*)" on "([^"]*)" element$/) do |text, element|
wait_for_ajax
expect(find(element)).not_to have_content(text)
end
Then(/^I should see "([^"]*)" on "([^"]*)" element$/) do |text, element|
2017-11-09 16:00:00 +08:00
wait_for_ajax
expect(find(element)).to have_content(text)
end
2017-11-20 16:41:14 +08:00
Then("I wait for {int} sec") do |sec|
sleep sec
end