Given(/^I visit the ([A-Za-z-0-9]*) page with params of "(.+)"$/) do |url, params|
  @context.given_visit_page(url, params)
end

When("I sign up using the following information:") do |table|
  @context.fill_new_account_info(table)
end

When(/^I (enter|sign up with) the following information:$/) do |action, table|
  @context.fill_in_fields_v2(table.rows)
  if action != 'enter'
    @context.press_purchase_v2
  else
    page.execute_script("$('input:focus').blur()")
  end
end

When "I fill my credit card information:" do |table|
  @context.fill_in_stripe_field(table)
end

When("I enter {string} as my email address") do |email|
  @context.fill_email_address_field(email)
end

When("I verify my existing account") do
  @context.verify_existing_account
end

When("I am verifying my existing account") do
  @context.verify_existing_account_v2
end

When(/^I click the purchase button$/) do
  @context.click_purchase
  @context.wait_for_redirect
end

When(/^I press the purchase button$/) do
  @context.press_purchase_v2
end

When("I try to click the purchase button") do
  @context.find_purchase_btn
end

Then("I should see the purchase button disabled") do
  @context.expect_purchase_btn_disabled
end

Then("I should see the purchase button still disabled") do
  @context.expect_purchase_btn_disabled
end

When "I change school name to {string}" do |name|
  @context.change_school_name(name)
end

When "I create new school {string}" do |name|
  @context.create_new_school(name)
end

When("I select {string} in the list") do |name|
  @context.change_school_name(name)
end

When("I sign up with the existing information") do
  @context.expect_payment_info_exist
  @context.click_purchase
  @context.wait_for_redirect
end

When("I choose new payment method") do
  @context.click_new_payment_method
end

When("I select new payment method") do
  @context.click_new_payment_method_v2
end

When(/^I enter an? (\w+) "(.*)" coupon for the "(.+)" plan$/) do |valid_or_invalid, coupon, plan|
  @context.enter_coupon_code(valid_or_invalid, coupon, plan)
end

When(/^I add an? (\w+) "(.*)" coupon for the "(.+)" plan$/) do |valid_or_invalid, coupon, plan|
  @context.enter_coupon_code_v2(valid_or_invalid, coupon, plan)
end

When(/^I fill in the coupon box with "(.+)"$/) do |coupon|
  @context.fill_in_coupon_box(coupon)
end

When(/^I re-fill in the coupon box with "(.+)"$/) do |coupon|
  @context.fill_in_coupon_code_v2(coupon)
end

When("I select create new school {word}") do |name|
  @context.choose_create_new_school(name)
end

Then "my {word} school in the list is disabled" do |school_name|
  @context.expect_not_to_see_schools_with_name(school_name)
end

Then(/^I should see the correct plan information$/) do
  @context.expect_correct_information
end

Then(/^the coupon code box (should|should not) be visible$/) do |should_or_not|
  id = '#spc-coupon-code'
  if should_or_not == 'should'
    expect(page).to have_css(id)
  else
    expect(page).to_not have_css(id)
  end
end

Then(/^(?:.*) should be on a page with the title "(.*?)"$/) do |text|
  expect(page).to have_text text
end

Then(/^I should see the correct billing cycle start date$/) do
  @context.expect_correct_order_summar_plan_start_date
end

Then(/^my billing cycle should start immediately$/) do
  @context.expect_no_order_summary_plan_start_date
end

Then(/^I will not see the billing cycle start date in the order summary information$/) do
  @context.expect_no_order_summary_plan_start_date
end

Then("the plan's price should be ${float}") do |total|
  @context.expect_correct_plan_price(total)
end

Then(/^the coupon code should be "(.+)"$/) do |code|
  @context.expect_correct_coupon(code)
end

Then(/^the coupon code field should show "(.+)"$/) do |code|
  @context.expect_correct_coupon_code_v2(code)
end

Then(/^the apply button should be enabled$/) do
  @context.expect_enabled_apply_button
end

Then(/^the code apply button should be enabled$/) do
  @context.expect_enabled_apply_button_v2
end

Then(/^the plan's price should be ([0-9]+\.?[0-9]*)$/) do |total|
  @context.expect_correct_plan_price(total)
end

Then(/^the total price should be ([0-9]+\.?[0-9]*)$/) do |total|
  @context.expect_correct_total_price_v2(total)
end

Then(/my school with plan id (\d+) in the list is disabled/) do |plan_id|
  @context.expect_not_to_see_schools_with_plan_id(plan_id)
end

When("I select the first school in the list") do
  @context.select_existing_school_v2(0)
end

When("I select create new school") do
  @context.choose_create_new_school_v2
end
