|
| 1 | +require 'spec_helper' |
| 2 | + |
| 3 | +describe 'authors index', type: :feature, js: true do |
| 4 | + before do |
| 5 | + add_author_resource |
| 6 | + end |
| 7 | + |
| 8 | + context 'index filters' do |
| 9 | + before do |
| 10 | + visit '/admin/authors' |
| 11 | + end |
| 12 | + |
| 13 | + context 'filter by Date column' do |
| 14 | + before do |
| 15 | + page.find('input#q_birthday_gteq').click |
| 16 | + |
| 17 | + page.find('.xdsoft_datetimepicker', visible: true) |
| 18 | + .find('.xdsoft_calendar td.xdsoft_date[data-date="1"]').click |
| 19 | + page.find('.xdsoft_datetimepicker', visible: true) |
| 20 | + .find('.xdsoft_timepicker.active .xdsoft_time.xdsoft_current').click |
| 21 | + |
| 22 | + page.find('input#q_birthday_lteq').click |
| 23 | + |
| 24 | + page.find('.xdsoft_datetimepicker', visible: true) |
| 25 | + .find('.xdsoft_calendar td.xdsoft_date[data-date="20"]').click |
| 26 | + page.find('.xdsoft_datetimepicker', visible: true) |
| 27 | + .find('.xdsoft_timepicker.active .xdsoft_time.xdsoft_current').click |
| 28 | + end |
| 29 | + |
| 30 | + it 'can set date from/to' do |
| 31 | + date_from = Date.today.beginning_of_month.strftime("%Y-%m-%d") |
| 32 | + date_to = (Date.today.beginning_of_month + 19.days).strftime("%Y-%m-%d") |
| 33 | + |
| 34 | + expect(page.find('input#q_birthday_gteq').value).to start_with(date_from) |
| 35 | + expect(page.find('input#q_birthday_lteq').value).to start_with(date_to) |
| 36 | + |
| 37 | + expect(page).to have_css('input#q_birthday_gteq[placeholder="From"]') |
| 38 | + expect(page).to have_css('input#q_birthday_lteq[placeholder="To"]') |
| 39 | + |
| 40 | + page.find('#sidebar input[type=submit]').click |
| 41 | + page.has_css?('h4', text: 'Current filters:') |
| 42 | + |
| 43 | + # birthday(Date type) is a Date column, should not contain H:M |
| 44 | + expect(page.find('#q_birthday_gteq').value).to match(/\A\d{4}-\d{2}-\d{2}\z/) |
| 45 | + end |
| 46 | + end |
| 47 | + |
| 48 | + context 'filter by DateTime/Timestamp column' do |
| 49 | + before do |
| 50 | + Author.create!(name: "Ren", |
| 51 | + last_name: "from-20-day-of-month", |
| 52 | + created_at: (Time.now.change(day: 20) - 1.hour).to_s(:db)) |
| 53 | + |
| 54 | + Author.create!(name: "Rey", |
| 55 | + last_name: "from-the-future", |
| 56 | + created_at: (Time.now.change(day: 20) + 2.hours).to_s(:db)) |
| 57 | + |
| 58 | + # chose 01 and 20 day of the current month |
| 59 | + |
| 60 | + page.find('input#q_created_at_gteq_datetime_picker').click |
| 61 | + |
| 62 | + page.find('.xdsoft_datetimepicker', visible: true) |
| 63 | + .find('.xdsoft_calendar td.xdsoft_date[data-date="1"]').click |
| 64 | + page.find('.xdsoft_datetimepicker', visible: true) |
| 65 | + .find('.xdsoft_timepicker.active .xdsoft_time.xdsoft_current').click |
| 66 | + |
| 67 | + page.find('input#q_created_at_lteq_datetime_picker').click |
| 68 | + |
| 69 | + page.find('.xdsoft_datetimepicker', visible: true) |
| 70 | + .find('.xdsoft_calendar td.xdsoft_date[data-date="20"]').click |
| 71 | + page.find('.xdsoft_datetimepicker', visible: true) |
| 72 | + .find('.xdsoft_timepicker.active .xdsoft_time.xdsoft_current').click |
| 73 | + |
| 74 | + page.find('#sidebar input[type=submit]').click |
| 75 | + page.has_css?('h4', text: 'Current filters:') |
| 76 | + end |
| 77 | + |
| 78 | + it 'q_created_at_lteq_datetime send correct value to SQL' do |
| 79 | + expect(page).to have_text('from-20-day-of-month') |
| 80 | + expect(page).not_to have_text('from-the-future') |
| 81 | + end |
| 82 | + |
| 83 | + it 'submit filter form' do |
| 84 | + # created_at(Timestamp type) should contain Hours:Minutes, as selected before submit |
| 85 | + expect(page.find('#q_created_at_gteq_datetime_picker').value).to match(/\A\d{4}-\d{2}-\d{2}\s\d{2}:\d{2}\z/) |
| 86 | + end |
| 87 | + end |
| 88 | + end |
| 89 | +end |
0 commit comments