forked from fixin.me/fixin.me
Refine Unit tests
This commit is contained in:
parent
8dbc07ea1f
commit
7cfa3a0af0
@ -19,6 +19,7 @@ class ApplicationSystemTestCase < ActionDispatch::SystemTestCase
|
|||||||
fill_in User.human_attribute_name(:email).capitalize, with: user.email
|
fill_in User.human_attribute_name(:email).capitalize, with: user.email
|
||||||
fill_in User.human_attribute_name(:password).capitalize, with: password
|
fill_in User.human_attribute_name(:password).capitalize, with: password
|
||||||
click_on t(:sign_in)
|
click_on t(:sign_in)
|
||||||
|
user
|
||||||
end
|
end
|
||||||
|
|
||||||
def inject_button_to(after, *button_options)
|
def inject_button_to(after, *button_options)
|
||||||
|
40
test/fixtures/units.yml
vendored
Normal file
40
test/fixtures/units.yml
vendored
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
g:
|
||||||
|
user: admin
|
||||||
|
symbol: g
|
||||||
|
name: gram
|
||||||
|
kg:
|
||||||
|
user: admin
|
||||||
|
symbol: kg
|
||||||
|
name: kilogram
|
||||||
|
multiplier: 1000
|
||||||
|
base: g
|
||||||
|
1:
|
||||||
|
user: admin
|
||||||
|
symbol: 1
|
||||||
|
name: one
|
||||||
|
s:
|
||||||
|
user: admin
|
||||||
|
symbol: s
|
||||||
|
name: second
|
||||||
|
percent:
|
||||||
|
user: admin
|
||||||
|
symbol: '%'
|
||||||
|
name: percent
|
||||||
|
multiplier: 0.01
|
||||||
|
base: 1
|
||||||
|
µg:
|
||||||
|
user: admin
|
||||||
|
symbol: µg
|
||||||
|
name: microgram
|
||||||
|
multiplier: 0.000001
|
||||||
|
base: g
|
||||||
|
mg:
|
||||||
|
user: admin
|
||||||
|
symbol: mg
|
||||||
|
name: milligram
|
||||||
|
multiplier: 0.001
|
||||||
|
base: g
|
||||||
|
g:
|
||||||
|
user: alice
|
||||||
|
symbol: g
|
||||||
|
name: gram
|
@ -2,14 +2,22 @@ require "application_system_test_case"
|
|||||||
|
|
||||||
class UnitsTest < ApplicationSystemTestCase
|
class UnitsTest < ApplicationSystemTestCase
|
||||||
setup do
|
setup do
|
||||||
@admin = users(:admin)
|
@user = sign_in
|
||||||
sign_in
|
|
||||||
visit units_path
|
visit units_path
|
||||||
end
|
end
|
||||||
|
|
||||||
test "index" do
|
test "index" do
|
||||||
assert_selector 'tbody > tr', count: Unit.count
|
# Wait for the table to appear first, only then check row count
|
||||||
assert_current_path units_path
|
within 'tbody' do
|
||||||
|
assert_selector 'tr', count: @user.units.count
|
||||||
|
end
|
||||||
|
|
||||||
|
Unit.destroy_all
|
||||||
|
visit units_path
|
||||||
|
within 'tbody' do
|
||||||
|
assert_selector 'tr', count: 1
|
||||||
|
assert_text t('units.index.no_items')
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
test "add unit" do
|
test "add unit" do
|
||||||
@ -28,9 +36,10 @@ class UnitsTest < ApplicationSystemTestCase
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
assert_current_path units_path
|
||||||
within('tbody') do
|
within('tbody') do
|
||||||
assert_no_selector :fillable_field
|
assert_no_selector :fillable_field
|
||||||
assert_selector 'tr', count: Unit.count
|
assert_selector 'tr', count: @user.units.count
|
||||||
end
|
end
|
||||||
assert_selector :link_or_button, text: t('units.index.add_unit')
|
assert_selector :link_or_button, text: t('units.index.add_unit')
|
||||||
|
|
||||||
@ -40,6 +49,8 @@ class UnitsTest < ApplicationSystemTestCase
|
|||||||
test "close new unit form with escape" do
|
test "close new unit form with escape" do
|
||||||
click_on t('units.index.add_unit')
|
click_on t('units.index.add_unit')
|
||||||
first('tbody > tr').all(:field).sample.send_keys :escape
|
first('tbody > tr').all(:field).sample.send_keys :escape
|
||||||
within('tbody') { assert_no_selector :fillable_field }
|
within('tbody') do
|
||||||
|
assert_no_selector :fillable_field
|
||||||
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user