step "I provide a new supplier email address" do
  find('#supplier_email').set 'new-supplier-mail@qwaiter.com'
end

step "the supplier submits the supplier settings form" do
  find('.submit-supplier-settings').click
end

step "the supplier email should not have been changed" do
  @supplier.reload
  @supplier.email.should == 'supplier@qwaiter.com'
end

step "the supplier unconfirmed email should have been set to the new supplier email" do
  @supplier.reload
  @supplier.unconfirmed_email.should == 'new-supplier-mail@qwaiter.com'
end

step "an email should have been sent to the original supplier email with email confirmation instructions" do
  mail = ActionMailer::Base.deliveries.last
  mail.to.should == ['supplier@qwaiter.com']
  mail.body.should include I18n.t('devise.mailer.confirmation_instructions.supplier.salutation', email: @supplier.email)
  mail.body.should_not include 'translation' # indicating a translation issue
  confirmation_link_match = mail.body.match(/http:\/\/www.qwaiter.com(\/suppliers\/confirmation[^"]+)"/)
  confirmation_link_match.should be_present
  @confirmation_link = confirmation_link_match[1]
end

step "the supplier clicks on the new email confirmation link" do
  visit @confirmation_link
end

step "the supplier gets redirected to the supplier settings path" do
  route_should_be 'supplier#edit'
end

step "the supplier email is the new email and the unconfirmed email is empty" do
  @supplier.reload
  @supplier.email.should == 'new-supplier-mail@qwaiter.com'
  @supplier.unconfirmed_email.should be_blank
end

step "the supplier selects :time_zone as Time Zone" do |visual_time_zone|
  page.select visual_time_zone, from: 'supplier_time_zone'
end

step "the supplier timezone should be :time_zone" do |time_zone|
  @supplier.reload
  @supplier.time_zone.should == time_zone
end
