When(/^I (unsubscribe|resubscribe) (?:from|to) the following messages:$/) do |action, table|
  @context.send(action, table.raw.flatten)
end

When(/^I unsubscribe from all messages$/) do
  @context.unsubscribe_from_all_messages
end

When(/^I (unsubscribe|resubscribe) (?:from|to) the channel$/) do |action|
  title = ['Please unsubscribe me from all marketing emails']
  @context.send(action, title)
end

When(/^I submit my preferences$/) do
  find('.orange-button', text: 'Submit').click
end

When (/^I resubscribe to "(.+)"$/) do |title|
  @context.resubscribe([title])
end

Then(/^I should see all message and channel preferences$/) do
  @context.expect_all_preferences
end

Then(/^I should be (unsubscribed|resubscribed) (?:from|to) only those messages$/) do |preference|
  @context.send("expect_correct_#{preference}_images")
end

Then(/^I should be (unsubscribed|subscribed) (?:from|to) the channel$/) do |preference|
  @context.expect_correct_image(find('.iterable-channels h3'), preference == 'unsubscribed')
end

Then(/^I should be (unsubscribed|subscribed) (?:from|to) all messages$/) do |preference|
  @context.expect_correct_image_for_all_messages(preference == 'subscribed')
end

Then(/^I should be unsubscribed from the following messages:$/) do |table|
  @context.expect_correct_unsubscribed_images(table.raw.flatten)
end

Then(/^I should be resubscribed to the message$/) do
  @context.expect_resubscribed
end
