GithubHelp home page GithubHelp logo

activeadmin-plugins / capybara_active_admin Goto Github PK

View Code? Open in Web Editor NEW
13.0 5.0 7.0 1.6 MB

Capybara DSL for fast and easy testing Active Admin applications.

Home Page: https://activeadmin-plugins.github.io/capybara_active_admin

License: MIT License

Ruby 99.51% Shell 0.29% JavaScript 0.07% SCSS 0.13%
activeadmin capybara rspec

capybara_active_admin's Introduction

Capybara Active Admin

Build Status Gem Version Downloads License: MIT

Capybara DSL for fast and easy testing Active Admin applications.

Check out our docs at activeadmin-plugins.github.io/capybara_active_admin

Installation

Add this line to your application's Gemfile:

group :test do
  gem 'capybara_active_admin'
end

And then execute:

$ bundle install

Or install it yourself as:

$ gem install capybara_active_admin

Note: capybara_active_admin should be required after capybara.

Usage

rails_helper.rb

require 'capybara/active_admin/rspec'

spec/system/users_spec.rb

RSpec.describe 'Users', js: true do
  subject do
    visit admin_users_path
  end

  let!(:john) { User.create!(full_name: 'John Doe') }
  let!(:jane) { User.create!(full_name: 'Jane Air') }

  it 'have john and jane in users table' do
    subject

    expect(page).to have_action_item('New User')
    expect(page).to_not have_action_item('Edit User')

    within_table_for('users') do
      expect(page).to have_table_row(count: 2)
      expect(page).to have_table_cell('John Doe')

      within_table_row(id: john.id) do
        expect(page).to have_table_cell('John Doe', row_id: john.id)
        expect(page).to have_table_cell('John Doe', row_id: john.id, col_name: 'Full Name')
        expect(page).to_not have_table_cell('John Doe', row_id: john.id, col_name: 'Id')
      end

      within_table_row(id: jane.id) do
        expect(page).to_not have_table_cell('John Doe')
        expect(page).to_not have_table_cell('John Doe', col_name: 'Full Name')
      end
    end
  end

  it 'creates user' do
    subject

    click_action_item('New User')
    expect(page).to have_current_path(new_admin_user_path)

    within_form_for(User) do
      fill_in 'Full name', with: 'Johny Cage'
      click_submit 'Create User'
    end

    expect(page).to have_flash_message('User was successfully created.', type: :notice)
    user = User.last!
    expect(page).to have_current_path admin_user_path(user.id)

    expect(User.count).to eq(1)
    expect(user).to have_attributes(full_name: 'Johny Cage')
  end
end

See spec/support for more user examples. See capybara/active_admin/test_helpers.rb for available DSL methods.

Development

After checking out the repo, run bin/setup to install dependencies. Then, run rake spec to run the tests. You can also run bin/console for an interactive prompt that will allow you to experiment.

To install this gem onto your local machine, run bundle exec rake install. To release a new version, update the version number in version.rb, and then run bundle exec rake release, which will create a git tag for the version, push git commits and tags, and push the .gem file to rubygems.org.

Contributing

Bug reports and pull requests are welcome on GitHub at https://github.com/activeadmin-plugins/capybara_active_admin. This project is intended to be a safe, welcoming space for collaboration, and contributors are expected to adhere to the code of conduct.

License

The gem is available as open source under the terms of the MIT License.

Code of Conduct

Everyone interacting in the Capybara::ActiveAdmin project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the code of conduct.

Notes

Project uses Keep a Changelog convention. Project adheres to Semantic Versioning.

capybara_active_admin's People

Contributors

dependabot[bot] avatar fivell avatar gigorok avatar senid231 avatar timoschilling avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

capybara_active_admin's Issues

add helpers

# @example
#   expect(page).to have_submit_input('Submit') # check that submit input is present
#   expect(page).to have_submit_input('Submit', disabled: true) # check that submit input is disabled
#   expect(page).to have_submit_input('Submit', disabled: true, count: 0) # check that submit input is enabled
#
def have_submit_input(text, options = {})
  selector = "#{form_submit_selector(text)}#{options.delete(:selector)}"
  selector += '[disabled="disabled"].disabled' if options.delete(:disabled)
  have_selector(selector, options)
end

add #have_fields_date_range and #within_table_footer helpers

  def have_fields_date_range(label, options = {})
    exact = options[:exact]
    satisfy do |actual|
      expect(actual).to have_selector('div.filter_date_range label', text: label)
      container = actual.find('div.filter_date_range label', text: label).first(:xpath, './/..')
      expect(container.has_css?('.filter_date_range label')).to eq(true)
      base_name = container[:id].gsub(/_input\z/, '')
      expect(container).to have_field("#{base_name}_gteq_datetime", with: options[:from].to_s, exact: exact)
      expect(container).to have_field("#{base_name}_lteq_datetime", with: options[:to].to_s, exact: exact)
    end
  end

  def within_table_footer
    within('tfoot > tr') { yield }
  end

  def click_table_scope(text)
    selector = "#{table_scopes_container_selector} > #{table_scope_selector}"
    page.find(selector, exact_text: text).click
  end

  def table_header_selector(text, options = {})
    column = (options[:column] || text).to_s.tr(' ', '_').downcase
    selector = "th.col.col-#{column}"
    selector += '.sortable' if options[:sortable]
    selector += ".sorted-#{options[:sort_direction].to_s.downcase}" if options[:sort_direction].present?
    "thead > tr > #{selector}"
  end

  def have_table_header(text, options = {})
    selector = table_header_selector text, options
    opts = options.except(:column, :sortable, :sort_direction).merge(exact_text: text)
    have_selector(selector, opts)
  end

  def find_table_header(text, options = {})
    selector = table_header_selector text, options
    opts = options.except(:column, :sortable, :sort_direction).merge(exact_text: text)
    page.find(selector, opts)
  end

  def click_table_header(text, options = {})
    find_table_header(text, options).find('a').click
  end

TODO for version 1.0

  • click on row actions
  • check row action present
  • check specific filter present
  • fill filters
  • click filter button
  • select rows in table
  • click on batch actions
  • accept/decline confirmation modal
  • check data in attributes_table
  • check status_tag (color class, text)
  • fill nested has_many form
  • switch tabs
  • check sidebar content
  • wiki for usecases
  • documentation for all methods of DSL

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.