2019-10-30 22:43:06 +08:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-12-17 18:21:49 +08:00
|
|
|
Given(/^the following users are registered:$/) do |table|
|
|
|
|
table.hashes.each do |hash|
|
|
|
|
team_name = hash.delete "team"
|
|
|
|
team_role = hash.delete "role"
|
|
|
|
user = FactoryBot.create(:user, hash)
|
|
|
|
team = FactoryBot.create(:team, {name: team_name, users: [user]})
|
|
|
|
UserTeam.where(user: user, team: team).first.update role: team_role
|
|
|
|
User.find_by_email(hash.fetch('email')).confirm
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
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
|
|
|
|
|
2019-10-30 22:43:06 +08:00
|
|
|
Then('I click {string} Scinote button') do |button|
|
2020-07-06 21:06:19 +08:00
|
|
|
find('.btn', text: button).click
|
|
|
|
end
|
|
|
|
|
2019-12-17 18:21:49 +08:00
|
|
|
Then('I click on {string} button') do |button|
|
|
|
|
find('.btn', text: button).click
|
|
|
|
end
|
|
|
|
|
|
|
|
Given("I click on {string} class button") do |button6|
|
|
|
|
find('.btn',class: button6, match: :first).click
|
|
|
|
end
|
|
|
|
|
|
|
|
Given("I click on {string} id button") do |button1|
|
|
|
|
find('.btn', id: button1).click
|
|
|
|
end
|
|
|
|
|
2019-10-30 22:43:06 +08:00
|
|
|
Then('I trigger click {string}') do |string|
|
2019-08-22 19:38:02 +08:00
|
|
|
page.execute_script("$('#{string}').trigger('click')")
|
2019-05-31 21:44:27 +08:00
|
|
|
end
|
|
|
|
|
2017-07-06 15:07:05 +08:00
|
|
|
Then(/^I should be redirected to the homepage$/) do
|
2019-10-30 22:43:06 +08:00
|
|
|
current_path.should =~ %r{^/$}
|
2017-07-06 15:07:05 +08:00
|
|
|
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
|
|
|
|
|
2019-09-03 21:14:37 +08:00
|
|
|
Given(/^I click first "(.+)" link$/) do |link_text|
|
|
|
|
first(:link, link_text).click
|
|
|
|
end
|
|
|
|
|
2017-10-11 15:51:20 +08:00
|
|
|
Given(/^I click "(.+)" link within "(.+)"$/) do |link, element|
|
2017-10-27 22:37:42 +08:00
|
|
|
within(element) do
|
2017-10-11 15:51:20 +08:00
|
|
|
click_link link
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-11-08 00:18:41 +08:00
|
|
|
Then(/^I click "(.+)" link within dropdown menu$/) do |link|
|
|
|
|
within('.dropdown-menu') do
|
|
|
|
click_link link
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-12-17 18:21:49 +08:00
|
|
|
Then(/^I click on "(.+)" within dropdown menu$/) do |link1|
|
|
|
|
within('.inner') do
|
|
|
|
find('.text', text: link1).click
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2017-10-10 15:17:55 +08:00
|
|
|
Then(/^I should see "(.+)"$/) do |text|
|
2017-10-24 21:39:06 +08:00
|
|
|
wait_for_ajax
|
2017-07-06 15:07:05 +08:00
|
|
|
expect(page).to have_content(text)
|
|
|
|
end
|
|
|
|
|
2019-12-17 18:21:49 +08:00
|
|
|
Then("I should not see {string}") do |text6|
|
|
|
|
wait_for_ajax
|
|
|
|
expect(page).not_to have_content(text6)
|
|
|
|
end
|
|
|
|
|
2017-07-06 15:07:05 +08:00
|
|
|
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|
|
2018-01-23 21:54:15 +08:00
|
|
|
FactoryBot.create(:team, name: team_name)
|
2017-10-10 15:17:55 +08:00
|
|
|
end
|
|
|
|
|
2019-09-03 21:14:37 +08:00
|
|
|
Given(/^Demo project exists for the "([^"]*)" team$/) do |team_name|
|
2019-10-30 22:43:06 +08:00
|
|
|
team = Team.find_by(name: team_name)
|
2019-09-03 21:14:37 +08:00
|
|
|
user = team.user_teams.where(role: :admin).take.user
|
|
|
|
seed_demo_data(user, team)
|
|
|
|
end
|
|
|
|
|
2017-10-10 15:17:55 +08:00
|
|
|
Given(/^I'm on the home page of "([^"]*)" team$/) do |team_name|
|
2019-10-30 22:43:06 +08:00
|
|
|
team = Team.find_by(name: team_name)
|
|
|
|
@current_user.update(current_team_id: team.id)
|
2017-10-10 15:17:55 +08:00
|
|
|
visit root_path
|
|
|
|
end
|
|
|
|
|
|
|
|
Given(/^"([^"]*)" is in "([^"]*)" team as a "([^"]*)"$/) do |user_email, team_name, role|
|
2019-10-30 22:43:06 +08:00
|
|
|
team = Team.find_by(name: team_name)
|
|
|
|
user = User.find_by(email: user_email)
|
2018-01-23 21:54:15 +08:00
|
|
|
FactoryBot.create(:user_team, user: user,
|
|
|
|
team: team, role:
|
|
|
|
UserTeam.roles.fetch(role))
|
2017-10-10 15:17:55 +08:00
|
|
|
end
|
|
|
|
|
2017-10-16 22:21:52 +08:00
|
|
|
Then(/^I attach a "([^"]*)" file to "([^"]*)" field$/) do |file, field_id|
|
2017-10-24 21:39:06 +08:00
|
|
|
wait_for_ajax
|
2019-10-30 22:43:06 +08:00
|
|
|
find(field_id, visible: false).attach_file(Rails.root.join('features', 'assets', file))
|
2017-10-24 21:39:06 +08:00
|
|
|
# "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
|
2017-10-24 21:39:06 +08:00
|
|
|
wait_for_ajax
|
2017-10-10 15:17:55 +08:00
|
|
|
end
|
|
|
|
|
2017-10-16 22:21:52 +08:00
|
|
|
Then(/^I should see "([^"]*)" flash message$/) do |message|
|
2017-10-24 21:39:06 +08:00
|
|
|
wait_for_ajax
|
2017-11-08 00:18:41 +08:00
|
|
|
expect(find('.alert')).to have_content(message)
|
2017-10-10 15:17:55 +08:00
|
|
|
end
|
|
|
|
|
2017-10-16 22:21:52 +08:00
|
|
|
Then(/^I click on Edit on "([^"]*)" input field$/) do |container_id|
|
2017-10-24 21:39:06 +08:00
|
|
|
wait_for_ajax
|
2018-01-31 19:05:45 +08:00
|
|
|
within(container_id) do
|
|
|
|
find('[data-action="edit"]').click
|
2017-10-16 22:21:52 +08:00
|
|
|
end
|
2017-10-10 15:17:55 +08:00
|
|
|
end
|
|
|
|
|
2019-12-17 18:21:49 +08:00
|
|
|
Then(/^I fill in "([^"]*)" in "([^"]*)" input fields$/) do |text, input_id|
|
2018-01-31 19:05:45 +08:00
|
|
|
page.find("#{input_id} input[type=\"text\"]").set(text)
|
|
|
|
end
|
|
|
|
|
2019-09-03 21:14:37 +08:00
|
|
|
Then(/^I fill in "([^"]*)" in "([^"]*)" rich text editor field$/) do |text, input_id|
|
|
|
|
within_frame(find(input_id + '_ifr')) do
|
|
|
|
find('#tinymce').set(text)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2019-10-30 22:43:06 +08:00
|
|
|
Then('I fill in {string} to {string} field of {string} modal window') do |value, field, modal|
|
2020-07-06 21:06:19 +08:00
|
|
|
page.find('.modal-content', text: modal).find_field(field, with: '').set(value)
|
|
|
|
end
|
|
|
|
|
2019-10-30 22:43:06 +08:00
|
|
|
Then('I change {string} with {string} of field {string} of {string} modal window') do |old_value, new_value, field, modal|
|
2020-07-06 21:06:19 +08:00
|
|
|
page.find('.modal-content', text: modal).find_field(field, with: old_value).set(new_value)
|
|
|
|
end
|
|
|
|
|
2018-01-31 19:05:45 +08:00
|
|
|
Then(/^I fill in "([^"]*)" in "([^"]*)" field$/) do |text, input_id|
|
2019-12-17 18:21:49 +08:00
|
|
|
page.find(input_id).set(text)
|
2017-10-10 15:17:55 +08:00
|
|
|
end
|
|
|
|
|
2017-10-16 22:21:52 +08:00
|
|
|
Then(/^I should see "([^"]*)" in "([^"]*)" input field$/) do |text, container_id|
|
2018-01-31 19:05:45 +08:00
|
|
|
container = page.find(container_id)
|
2017-10-16 22:21:52 +08:00
|
|
|
expect(container).to have_xpath("//input[@value='#{text}']")
|
2017-10-10 15:17:55 +08:00
|
|
|
end
|
2017-10-27 22:37:42 +08:00
|
|
|
|
2019-10-30 22:43:06 +08:00
|
|
|
Given('I click {string} icon') do |id|
|
2017-10-27 22:37:42 +08:00
|
|
|
find(:css, id).click
|
|
|
|
end
|
2017-11-09 15:35:39 +08:00
|
|
|
|
2017-11-03 17:48:09 +08:00
|
|
|
Then(/^(?:|I )click on "([^"]*)" element$/) do |selector|
|
|
|
|
find(selector).click
|
|
|
|
end
|
|
|
|
|
2019-09-03 21:14:37 +08:00
|
|
|
Then(/^I attach file "([^"]*)" to the drag-n-drop field$/) do |file_name|
|
|
|
|
find('#drag-n-drop-assets', visible: false).send_keys(Rails.root.join('features', 'assets', file_name))
|
|
|
|
end
|
|
|
|
|
2017-11-03 17:48:09 +08:00
|
|
|
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
|
2017-11-03 17:48:09 +08:00
|
|
|
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
|
|
|
|
|
2019-01-21 22:06:39 +08:00
|
|
|
Then(/^I should not see "([^"]*)" on "([^"]*)" element$/) do |text, element|
|
|
|
|
wait_for_ajax
|
|
|
|
expect(find(element)).not_to have_content(text)
|
|
|
|
end
|
|
|
|
|
2017-11-03 17:48:09 +08:00
|
|
|
Then(/^I should see "([^"]*)" on "([^"]*)" element$/) do |text, element|
|
2017-11-09 16:00:00 +08:00
|
|
|
wait_for_ajax
|
2017-11-03 17:48:09 +08:00
|
|
|
expect(find(element)).to have_content(text)
|
|
|
|
end
|
2017-11-20 16:41:14 +08:00
|
|
|
|
2019-10-30 22:43:06 +08:00
|
|
|
Then('I wait for {int} sec') do |sec|
|
2017-11-20 16:41:14 +08:00
|
|
|
sleep sec
|
|
|
|
end
|
2019-11-13 23:24:19 +08:00
|
|
|
|
2019-12-17 18:21:49 +08:00
|
|
|
Then('I click button with icon and label {string}') do |label|
|
|
|
|
find('.btn', text: label).click
|
|
|
|
end
|
|
|
|
|
2019-11-13 23:24:19 +08:00
|
|
|
Given('default screen size') do
|
|
|
|
page.driver.browser.manage.window.resize_to(1920, 1080) if defined?(page.driver.browser.manage)
|
|
|
|
end
|
2020-07-06 21:06:19 +08:00
|
|
|
|
2019-12-17 18:21:49 +08:00
|
|
|
Given('default screen size2') do
|
|
|
|
page.driver.browser.manage.window.resize_to(1600, 900) if defined?(page.driver.browser.manage)
|
|
|
|
end
|
|
|
|
|
2020-07-06 21:06:19 +08:00
|
|
|
Then('I make screenshot') do
|
2019-12-17 18:21:49 +08:00
|
|
|
page.execute_script "window.scrollTo(0,0)"
|
|
|
|
page.driver.save_screenshot 'screenshot.png'
|
2020-07-06 21:06:19 +08:00
|
|
|
end
|
2019-10-30 22:43:06 +08:00
|
|
|
|
|
|
|
Given('I click to Cancel on confirm dialog') do
|
|
|
|
page.driver.browser.switch_to.alert.dismiss
|
|
|
|
end
|
|
|
|
|
|
|
|
Given('I click to OK on confirm dialog') do
|
|
|
|
page.driver.browser.switch_to.alert.accept
|
|
|
|
end
|
2019-12-17 18:21:49 +08:00
|
|
|
|
|
|
|
Then("confirm with ENTER key to {string}") do |element|
|
|
|
|
page.find("#{element}").native.send_keys(:enter)
|
|
|
|
end
|
|
|
|
|
|
|
|
Then("I hover over comment") do
|
|
|
|
find('.content-placeholder').hover
|
|
|
|
end
|
|
|
|
|
|
|
|
Then("I click on {string} sign") do |string1|
|
|
|
|
find("#{string1}").click
|
|
|
|
end
|
|
|
|
|
|
|
|
Then("WAIT") do
|
|
|
|
wait_for_ajax
|
|
|
|
end
|