When(/^I change the default language to (.*?)$/) do |language|
  on(Workstation::AccountPage) do |page|
    if page.language == language
      puts "Language is already #{language}... nothing to do here!"
    else
      page.language = language
      page.wait_until { page.language == language } # sometimes form change is delayed
      page.apply_language_element.click
    end
  end
end

When(/^I (.*?) the spike detector email setting$/) do |status|
  on(Workstation::AccountPage) do |page|
    if status == "enable"
      page.spike_checkbox_element.click unless page.spike_checked?
    else
      page.spike_checkbox_element.click while page.spike_checked?
    end
    page.apply_email_element.click
  end
end

Then(/^The language of Analytics should change to (.*?)$/) do |language|
  on(Workstation::AccountPage) do |page|
    eventually(timeout: 15) do
      page.language_verification(language)
    end
  end
end

Then(/^email settings saved successfully$/) do
  on(Workstation::AccountPage) do |page|
    eventually(timeout: 15) do
      expect(page.apply_email_message_element.text).to include "Your information has been updated"
    end
  end
end

And(/^the active subscription is (.*?) for (.*?)$/) do |feed_name, account_type|
  user = @users.workstation_user
  @subscriptions = user.check_user_subscriptions(account_type)
  expect(@subscriptions.to_s).to include feed_name
  expect(@subscriptions.to_s).to include account_type
end
