|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +RSpec.describe 'Dynamic fields', type: :system do |
| 4 | + let(:author) { Author.create!(email: 'some_email@example.com', name: 'John Doe', age: 30) } |
| 5 | + let(:post) { Post.create!(title: 'Test', author: author, description: '') } |
| 6 | + |
| 7 | + before do |
| 8 | + post |
| 9 | + end |
| 10 | + |
| 11 | + after do |
| 12 | + post.destroy |
| 13 | + author.destroy |
| 14 | + end |
| 15 | + |
| 16 | + context 'with some dynamic fields' do |
| 17 | + it 'toggles the .group1 elements when clicking on the checkbox' do |
| 18 | + visit "/admin/posts/#{post.id}/edit" |
| 19 | + |
| 20 | + expect(page).to have_css('#post_published[data-if="not_checked"][data-action="hide"][data-target=".group1"]') |
| 21 | + |
| 22 | + expect(find('#post_published')).not_to be_checked |
| 23 | + expect(page).to have_css('#post_dt_input', visible: :hidden) |
| 24 | + expect(page).to have_css('#post_position_input', visible: :hidden) |
| 25 | + |
| 26 | + find('#post_published').set(true) |
| 27 | + expect(page).to have_css('#post_dt_input', visible: :visible) |
| 28 | + expect(page).to have_css('#post_position_input', visible: :visible) |
| 29 | + |
| 30 | + find('#post_published').set(false) |
| 31 | + expect(page).to have_css('#post_dt_input', visible: :hidden) |
| 32 | + expect(page).to have_css('#post_position_input', visible: :hidden) |
| 33 | + end |
| 34 | + |
| 35 | + it 'changes the value of target when the source element is blank' do |
| 36 | + visit "/admin/posts/#{post.id}/edit" |
| 37 | + |
| 38 | + expect(page).to have_css('#post_description[data-if="blank"][data-action="setValue no title"][data-target="#post_category"]') |
| 39 | + expect(find('#post_category').value).to eq 'no title' |
| 40 | + find('#post_category').set('...') |
| 41 | + find('#post_description').set('...') |
| 42 | + expect(find('#post_category').value).to eq '...' |
| 43 | + find('#post_description').set('') |
| 44 | + expect(find('#post_category').value).to eq 'no title' |
| 45 | + end |
| 46 | + end |
| 47 | +end |
0 commit comments