|
21 | 21 | end |
22 | 22 |
|
23 | 23 | 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') } |
26 | 27 |
|
27 | | - before { stub_spree_preferences(default_country_iso: uk.iso) } |
| 28 | + before { |
| 29 | + stub_spree_preferences(default_country_iso: has_states_country.iso) |
28 | 30 |
|
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 | + } |
32 | 33 |
|
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 |
54 | 36 |
|
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' |
57 | 39 |
|
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) |
62 | 42 |
|
63 | | - page.find(@state_name_css).set('Toscana') |
| 43 | + page.find(@state_name_css).set('Devon') |
64 | 44 |
|
65 | | - select france.name, from: 'Country' |
66 | | - end |
| 45 | + select "Canada", from: 'Country' |
67 | 46 |
|
| 47 | + expect(page).to have_css("#{@state_select_css}.required") |
68 | 48 | 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') } |
76 | 49 |
|
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' |
82 | 51 |
|
83 | | - expect(page).to have_no_css(@state_name_css) |
84 | 52 | expect(page).to have_css("#{@state_select_css}[disabled]", visible: false) |
| 53 | + expect(page).to have_no_css(@state_name_css) |
85 | 54 | end |
86 | 55 | end |
87 | 56 | end |
|
0 commit comments