Skip to content
This repository
Browse code

refactor disabled_test

separate expectations to own test cases
use assert_no_select instead of css selector
  • Loading branch information...
commit d444d6ceefd9d72555e1782a8b796473c4478ef3 1 parent ece4dca
Vasiliy Ermolovich nashby authored

Showing 1 changed file with 51 additions and 11 deletions. Show diff stats Hide diff stats

  1. +51 11 test/inputs/disabled_test.rb
62 test/inputs/disabled_test.rb
... ... @@ -1,38 +1,78 @@
1 1 require 'test_helper'
2 2
3 3 class DisabledTest < ActionView::TestCase
4   - test 'input should generate disabled elements based on the disabled option' do
  4 + test 'string input should be disabled when disabled option is true' do
5 5 with_input_for @user, :name, :string, :disabled => true
6 6 assert_select 'input.string.disabled[disabled]'
  7 + end
  8 +
  9 + test 'text input should be disabled when disabled option is true' do
7 10 with_input_for @user, :description, :text, :disabled => true
8 11 assert_select 'textarea.text.disabled[disabled]'
  12 + end
  13 +
  14 + test 'numeric input should be disabled when disabled option is true' do
9 15 with_input_for @user, :age, :integer, :disabled => true
10 16 assert_select 'input.integer.disabled[disabled]'
  17 + end
  18 +
  19 + test 'date input should be disabled when disabled option is true' do
11 20 with_input_for @user, :born_at, :date, :disabled => true
12 21 assert_select 'select.date.disabled[disabled]'
  22 + end
  23 +
  24 + test 'datetime input should be disabled when disabled option is true' do
13 25 with_input_for @user, :created_at, :datetime, :disabled => true
14 26 assert_select 'select.datetime.disabled[disabled]'
  27 + end
15 28
  29 + test 'string input should not be disabled when disabled option is false' do
16 30 with_input_for @user, :name, :string, :disabled => false
17   - assert_select 'input.string:not(.disabled[disabled])'
  31 + assert_no_select 'input.string.disabled[disabled]'
  32 + end
  33 +
  34 + test 'text input should not be disabled when disabled option is false' do
18 35 with_input_for @user, :description, :text, :disabled => false
19   - assert_select 'textarea.text:not(.disabled[disabled])'
  36 + assert_no_select 'textarea.text.disabled[disabled]'
  37 + end
  38 +
  39 + test 'numeric input should not be disabled when disabled option is false' do
20 40 with_input_for @user, :age, :integer, :disabled => false
21   - assert_select 'input.integer:not(.disabled[disabled])'
  41 + assert_no_select 'input.integer.disabled[disabled]'
  42 + end
  43 +
  44 + test 'date input should not be disabled when disabled option is false' do
22 45 with_input_for @user, :born_at, :date, :disabled => false
23   - assert_select 'select.date:not(.disabled[disabled])'
  46 + assert_no_select 'select.date.disabled[disabled]'
  47 + end
  48 +
  49 + test 'datetime input should not be disabled when disabled option is false' do
24 50 with_input_for @user, :created_at, :datetime, :disabled => false
25   - assert_select 'select.datetime:not(.disabled[disabled])'
  51 + assert_no_select 'select.datetime.disabled[disabled]'
  52 + end
26 53
  54 + test 'string input should not be disabled when disabled option is not present' do
27 55 with_input_for @user, :name, :string
28   - assert_select 'input.string:not(.disabled[disabled])'
  56 + assert_no_select 'input.string.disabled[disabled]'
  57 + end
  58 +
  59 + test 'text input should not be disabled when disabled option is not present' do
29 60 with_input_for @user, :description, :text
30   - assert_select 'textarea.text:not(.disabled[disabled])'
  61 + assert_no_select 'textarea.text.disabled[disabled]'
  62 + end
  63 +
  64 + test 'numeric input should not be disabled when disabled option is not present' do
31 65 with_input_for @user, :age, :integer
32   - assert_select 'input.integer:not(.disabled[disabled])'
  66 + assert_no_select 'input.integer.disabled[disabled]'
  67 + end
  68 +
  69 + test 'date input should not be disabled when disabled option is not present' do
33 70 with_input_for @user, :born_at, :date
34   - assert_select 'select.date:not(.disabled[disabled])'
  71 + assert_no_select 'select.date.disabled[disabled]'
  72 + end
  73 +
  74 + test 'datetime input should not be disabled when disabled option is not present' do
35 75 with_input_for @user, :created_at, :datetime
36   - assert_select 'select.datetime:not(.disabled[disabled])'
  76 + assert_no_select 'select.datetime.disabled[disabled]'
37 77 end
38 78 end

0 comments on commit d444d6c

Please sign in to comment.
Something went wrong with that request. Please try again.