Skip to content

Commit 5f26eb9

Browse files
forkataAlistairNorman
authored andcommitted
Fix and amalgamate flaky address state specs
These tests were periodically failing. They test various different country/state requirements. These requirements can all be amalgamated for the sake of speed and simplicity. I think having the positive checks on css before the negative checks will eliminate the flaky failures.
1 parent c5a9794 commit 5f26eb9

1 file changed

Lines changed: 18 additions & 49 deletions

File tree

templates/spec/system/address_spec.rb

Lines changed: 18 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -21,67 +21,36 @@
2121
end
2222

2323
context 'country requires state', js: true do
24-
let!(:canada) { create(:country, name: 'Canada', states_required: true, iso: 'CA') }
25-
let!(:uk) { create(:country, name: 'United Kingdom', states_required: true, iso: 'GB') }
24+
let!(:has_states_country) { create(:country, name: 'Canada', states_required: true, iso: 'CA') }
25+
let!(:no_states_country) { create(:country, name: 'United Kingdom', states_required: true, iso: 'GB') }
26+
let!(:states_not_required_country) { create(:country, name: 'France', states_required: false, iso: 'FR') }
2627

27-
before { stub_spree_preferences(default_country_iso: uk.iso) }
28+
before {
29+
stub_spree_preferences(default_country_iso: has_states_country.iso)
2830

29-
context 'but has no state' do
30-
it 'shows the state input field' do
31-
checkout_as_guest
31+
create(:state, name: 'Ontario', country: has_states_country)
32+
}
3233

33-
within('#billing') do
34-
select canada.name, from: 'Country'
35-
expect(page).to have_no_css(@state_select_css)
36-
expect(page).to have_css("#{@state_name_css}.required")
37-
end
38-
end
39-
end
40-
41-
context 'and has state' do
42-
before { create(:state, name: 'Ontario', country: canada) }
43-
44-
it 'shows the state collection selection' do
45-
checkout_as_guest
46-
47-
within('#billing') do
48-
select canada.name, from: 'Country'
49-
expect(page).to have_no_css(@state_name_css)
50-
expect(page).to have_css("#{@state_select_css}.required")
51-
end
52-
end
53-
end
34+
scenario 'switching between countries with and without states and states required' do
35+
checkout_as_guest
5436

55-
context 'user changes to country without states required' do
56-
let!(:france) { create(:country, name: 'France', states_required: false, iso: 'FR') }
37+
within('#billing') do
38+
select "United Kingdom", from: 'Country'
5739

58-
it 'clears the state name' do
59-
checkout_as_guest
60-
within('#billing') do
61-
select canada.name, from: 'Country'
40+
expect(page).to have_css("#{@state_name_css}.required")
41+
expect(page).to have_no_css(@state_select_css)
6242

63-
page.find(@state_name_css).set('Toscana')
43+
page.find(@state_name_css).set('Devon')
6444

65-
select france.name, from: 'Country'
66-
end
45+
select "Canada", from: 'Country'
6746

47+
expect(page).to have_css("#{@state_select_css}.required")
6848
expect(page).to have_no_css(@state_name_css)
69-
expect(page).to have_no_css(@state_select_css)
70-
end
71-
end
72-
end
73-
74-
context 'country does not require state', js: true do
75-
let!(:france) { create(:country, name: 'France', states_required: false, iso: 'FR') }
7649

77-
it 'shows a disabled state input field' do
78-
checkout_as_guest
79-
80-
within('#billing') do
81-
select france.name, from: 'Country'
50+
select "France", from: 'Country'
8251

83-
expect(page).to have_no_css(@state_name_css)
8452
expect(page).to have_css("#{@state_select_css}[disabled]", visible: false)
53+
expect(page).to have_no_css(@state_name_css)
8554
end
8655
end
8756
end

0 commit comments

Comments
 (0)