step "there is an other employee" do
  @other_employee = create :employee, :confirmed, name: 'Other employee'
  @supplier.add_employee @other_employee
end

step "the supplier employee clicks on the other employee table edit button" do
  find 'table.table'
  all('tr').last.find('.table-edit').click
end

step "the supplier employee should see content :content" do |content|
  page.should have_content content
end

step "the supplier employee clicks on the existing employee table destroy button" do
  find 'table.table'
  sleep 0.2
  all('tr').last.find('.table-destroy').click
end

step "the supplier emloyee sets the :attribute to :value in the employee popup" do |attribute, value|
  js_set_field ".form-row.#{attribute} input", value
end

step "the supplier emloyee clicks the active switch to deactivate the employee" do
  js_click '.form-row.active label'
end

step "the other employee should no longer be active for the current supplier" do
  sleep 1
  @supplier.reload
  @supplier.settings_for(@other_employee).active?.should be false
end

step "the new employee should be added to the supplier" do
  @new_employee = Employee.find_by_email('new-employee@example.com')
  @new_employee.should be_present
  @new_employee.name.should eq 'New employee'
  @supplier.reload
  settings = @supplier.settings_for @new_employee
  settings.is_manager?.should be true
  settings.is_active?.should be true
end

step "the new employee should be re-added to the supplier as non manager non active" do
  # Non active for a non default setting change to be recorded
  @existing_employee = Employee.find_by_email('existing-employee@example.com')
  @existing_employee.should be_present
  @existing_employee.name.should eq 'Existing employee readded'
  @supplier.reload
  settings = @supplier.settings_for @existing_employee
  settings.is_manager?.should be false
  settings.is_active?.should be false
end
