summaryrefslogtreecommitdiff
path: root/fake-service/features/step_definitions
diff options
context:
space:
mode:
authorOla Bini <ola.bini@gmail.com>2014-07-31 19:35:40 -0300
committerOla Bini <ola.bini@gmail.com>2014-07-31 19:35:40 -0300
commite54e5ee931b3991cbb5e427e7e5d27b3f6c75e6e (patch)
tree1e0da33d22874c0ea5576818fe45958611ebda29 /fake-service/features/step_definitions
parent04cf441c5ae18400c6b4865b0b37a71718dc9d46 (diff)
Add fake-service
Diffstat (limited to 'fake-service/features/step_definitions')
-rw-r--r--fake-service/features/step_definitions/compose.rb27
-rw-r--r--fake-service/features/step_definitions/mail_list.rb55
-rw-r--r--fake-service/features/step_definitions/mail_view.rb67
-rw-r--r--fake-service/features/step_definitions/search.rb12
-rw-r--r--fake-service/features/step_definitions/tag_list.rb15
5 files changed, 176 insertions, 0 deletions
diff --git a/fake-service/features/step_definitions/compose.rb b/fake-service/features/step_definitions/compose.rb
new file mode 100644
index 00000000..e92d16f6
--- /dev/null
+++ b/fake-service/features/step_definitions/compose.rb
@@ -0,0 +1,27 @@
+Given /^I compose a message with$/ do |table|
+ find('#compose-mails-trigger').click
+ data = table.hashes.first
+ fill_in('Subject', with: data['subject'])
+ fill_in('Body', with: data['body'])
+end
+
+Given /^for the '(.*)' field I type '(.*)' and chose the first contact that shows$/ do |recipients_field, to_type|
+ recipients_field.downcase!
+ within("#recipients-#{recipients_field}-area") do
+ find('.tt-input').native.send_keys(to_type)
+ sleep 1
+ first('.tt-dropdown-menu div div').click
+ end
+end
+
+Given /^I save the draft$/ do
+ click_button("Save Draft")
+end
+
+When /^I open the saved draft and send it$/ do
+ step "I select the tag 'drafts'"
+ step "I open the first mail in the mail list"
+ page.should_not have_css("#send-button[disabled]")
+ click_button('Send')
+ find('#user-alerts').should have_content("Your message was sent!")
+end
diff --git a/fake-service/features/step_definitions/mail_list.rb b/fake-service/features/step_definitions/mail_list.rb
new file mode 100644
index 00000000..d41a62a0
--- /dev/null
+++ b/fake-service/features/step_definitions/mail_list.rb
@@ -0,0 +1,55 @@
+When(/^I open the first mail in the '(.*)'$/) do |tag|
+ page.execute_script("window.scrollBy(0, -200)")
+ step "I select the tag '#{tag}'"
+ step 'I open the first mail in the mail list'
+end
+
+When(/^I open the first mail in the mail list$/) do
+ within('#mail-list') do
+ mail_link = first('a')
+ @current_mail_id = mail_link.native.attribute('href').scan(/\/(\d+)$/).flatten.first
+ begin
+ mail_link.click
+ rescue # in Chrome, the 'a' in mail_list is not clickable because it's hidden inside the 'li'
+ mail_link_parent_li = mail_link.find(:xpath, '../..')
+ mail_link_parent_li.click
+ end
+ end
+end
+
+When(/I see that mail under the '(.*)' tag/) do |tag|
+ step "I select the tag '#{tag}'"
+ check_current_mail_is_visible
+end
+
+And(/^I open the mail I previously tagged$/) do
+ open_current_mail
+end
+
+When(/^I open that mail$/) do
+ open_current_mail
+end
+
+Then(/^I see the mail I sent$/) do
+ check_current_mail_is_visible
+end
+
+Then(/^the deleted mail is there$/) do
+ check_current_mail_is_visible
+end
+
+def open_current_mail
+ within('#mail-list') do
+ begin
+ first("#mail-#{@current_mail_id} a").click
+ rescue # in Chrome, the 'a' in mail_list is not clickable because it's hidden inside the 'li'
+ first("#mail-#{@current_mail_id}").click
+ end
+ end
+end
+
+def check_current_mail_is_visible
+ within('#mail-list') do
+ have_selector?("#mail-#{@current_mail_id}").should be_true
+ end
+end
diff --git a/fake-service/features/step_definitions/mail_view.rb b/fake-service/features/step_definitions/mail_view.rb
new file mode 100644
index 00000000..19ca5736
--- /dev/null
+++ b/fake-service/features/step_definitions/mail_view.rb
@@ -0,0 +1,67 @@
+A_MAIL = /[^\s@]+@[^\s@]+\.[^\s@]+/
+
+Then(/^I see the mail has a cc and a bcc recipient$/) do
+ within('.msg-header') do
+ first('.cc').text.should =~ A_MAIL
+ first('.bcc').text.should =~ A_MAIL
+ end
+end
+
+Then(/^that email has the '(.*)' tag$/) do |tag|
+ within('#mail-view') do |e|
+ all('.tagsArea .tag').map(&:text).map(&:downcase).to_a.should include(tag)
+ end
+end
+
+When(/I add the tag '(.*)' to that mail/) do |tag|
+ page.execute_script("$('#new-tag-button').click();")
+ page.execute_script("$('#new-tag-input').val('#{tag}');")
+ find('#new-tag-input').native.send_keys [:return]
+end
+
+And(/^I reply to it$/) do
+ click_button('Reply')
+ click_button('Send')
+end
+
+Then(/^I choose to forward this mail$/) do
+ click_button('Forward')
+end
+
+Then(/^I forward this mail$/) do
+ click_button('Send')
+end
+
+
+Then(/^I remove all tags$/) do
+ within('.tagsArea') do
+ all('.tag').each do |tag|
+ tag.click
+ end
+ end
+end
+
+Then(/^I choose to trash$/) do
+ click_button('Trash message')
+end
+
+When(/^I try to delete the first mail$/) do
+ step 'I open the first mail in the mail list'
+ within('#mail-view') do
+ page.driver.find_css('#view-more-actions')[0].click
+ page.driver.execute_script("$('#delete-button-top').click();")
+ end
+ find('#user-alerts').text.should == 'Your message was moved to trash!'
+end
+
+Then(/^I see that the subject reads '(.*)'$/) do |expected_subject|
+ find('#mail-view .subject').text.should == expected_subject
+end
+
+Then(/^I see that the body reads '(.*)'$/) do |expected_body|
+ find('#mail-view .bodyArea').text.should == expected_body
+end
+
+Then(/^I see if the mail has html content/) do
+ find('#mail-view .bodyArea').should have_css('h2[style*=\'color: #3f4944\']', :text => "cborim")
+end
diff --git a/fake-service/features/step_definitions/search.rb b/fake-service/features/step_definitions/search.rb
new file mode 100644
index 00000000..de89759c
--- /dev/null
+++ b/fake-service/features/step_definitions/search.rb
@@ -0,0 +1,12 @@
+When(/^I search for a mail with the words "(.*)"$/) do |search_term|
+ search_field = find('#search-trigger input[type="search"]').native
+ search_field.send_keys(search_term)
+ search_field.send_keys(:return)
+end
+
+Then(/^I see one or more mails in the search results$/) do
+ within('#mail-list') do
+ all('li').length.should >= 1
+ end
+end
+
diff --git a/fake-service/features/step_definitions/tag_list.rb b/fake-service/features/step_definitions/tag_list.rb
new file mode 100644
index 00000000..678f5ce9
--- /dev/null
+++ b/fake-service/features/step_definitions/tag_list.rb
@@ -0,0 +1,15 @@
+When(/^I select the tag '(.*)'$/) do |tag|
+ wait_for_user_alert_to_disapear # in Chrome, the 'flash message is on top of the toggle
+ first('.left-off-canvas-toggle').click
+ page.execute_script("window.scrollBy(0, -200)")
+ within('#tag-list') { find('li', text: /#{tag}/i).click }
+end
+
+def wait_for_user_alert_to_disapear
+ begin
+ while find('#user-alerts')
+ sleep 0.1
+ end
+ rescue #if it couldn't find it, go ahead
+ end
+end