|
| 1 | +# frozen_string_literal: true |
| 2 | + |
| 3 | +#-- copyright |
| 4 | +# OpenProject is an open source project management software. |
| 5 | +# Copyright (C) the OpenProject GmbH |
| 6 | +# |
| 7 | +# This program is free software; you can redistribute it and/or |
| 8 | +# modify it under the terms of the GNU General Public License version 3. |
| 9 | +# |
| 10 | +# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows: |
| 11 | +# Copyright (C) 2006-2013 Jean-Philippe Lang |
| 12 | +# Copyright (C) 2010-2013 the ChiliProject Team |
| 13 | +# |
| 14 | +# This program is free software; you can redistribute it and/or |
| 15 | +# modify it under the terms of the GNU General Public License |
| 16 | +# as published by the Free Software Foundation; either version 2 |
| 17 | +# of the License, or (at your option) any later version. |
| 18 | +# |
| 19 | +# This program is distributed in the hope that it will be useful, |
| 20 | +# but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 | +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 | +# GNU General Public License for more details. |
| 23 | +# |
| 24 | +# You should have received a copy of the GNU General Public License |
| 25 | +# along with this program; if not, write to the Free Software |
| 26 | +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 27 | +# |
| 28 | +# See COPYRIGHT and LICENSE files for more details. |
| 29 | +#++ |
| 30 | + |
| 31 | +require "spec_helper" |
| 32 | + |
| 33 | +RSpec.describe Filters::Inputs::DateForm, type: :forms do |
| 34 | + include_context "with rendered filter input form" |
| 35 | + |
| 36 | + let!(:date_field) { create(:user_custom_field, field_format: "date") } |
| 37 | + let(:query) { UserQuery.new } |
| 38 | + let(:filter) do |
| 39 | + f = query.available_advanced_filters.detect { |af| af.name == :"cf_#{date_field.id}" } |
| 40 | + f.operator = operator |
| 41 | + f.values = values |
| 42 | + f |
| 43 | + end |
| 44 | + |
| 45 | + it_behaves_like "rendering filter row" do |
| 46 | + let(:operator) { "=d" } |
| 47 | + let(:values) { [Date.current.iso8601] } |
| 48 | + end |
| 49 | + |
| 50 | + it_behaves_like "rendering operator select" do |
| 51 | + let(:operator) { "=d" } |
| 52 | + let(:values) { [Date.current.iso8601] } |
| 53 | + end |
| 54 | + |
| 55 | + it_behaves_like "hidden when inactive" do |
| 56 | + let(:operator) { "=d" } |
| 57 | + let(:values) { [Date.current.iso8601] } |
| 58 | + end |
| 59 | + |
| 60 | + context "with a days operator (>t-)" do |
| 61 | + let(:operator) { ">t-" } |
| 62 | + let(:values) { ["7"] } |
| 63 | + |
| 64 | + it "renders a days number input" do |
| 65 | + expect(rendered_form).to have_element :input, |
| 66 | + "data-filter--filters-form-target": "days", |
| 67 | + type: "number", |
| 68 | + visible: :all |
| 69 | + end |
| 70 | + end |
| 71 | + |
| 72 | + context "with an on-date operator (=d)" do |
| 73 | + let(:operator) { "=d" } |
| 74 | + let(:values) { [Date.current.iso8601] } |
| 75 | + |
| 76 | + it "renders the value container with the filter name" do |
| 77 | + expect(rendered_form).to have_element "data-filter--filters-form-target": /filterValueContainer/, |
| 78 | + "data-filter-name": filter.name.to_s, |
| 79 | + visible: :all |
| 80 | + end |
| 81 | + |
| 82 | + it "hides the days input" do |
| 83 | + days_input = rendered_form.find(:element, "data-filter--filters-form-target": "days", visible: :all) |
| 84 | + expect(days_input["hidden"]).to eq("hidden") |
| 85 | + end |
| 86 | + end |
| 87 | + |
| 88 | + context "with a between-dates operator (<>d)" do |
| 89 | + let(:operator) { "<>d" } |
| 90 | + let(:values) { [1.week.ago.to_date.iso8601, Date.current.iso8601] } |
| 91 | + |
| 92 | + it "renders the value container with the filter name" do |
| 93 | + expect(rendered_form).to have_element "data-filter--filters-form-target": /filterValueContainer/, |
| 94 | + "data-filter-name": filter.name.to_s, |
| 95 | + visible: :all |
| 96 | + end |
| 97 | + |
| 98 | + it "hides the days input" do |
| 99 | + days_input = rendered_form.find(:element, "data-filter--filters-form-target": "days", visible: :all) |
| 100 | + expect(days_input["hidden"]).to eq("hidden") |
| 101 | + end |
| 102 | + end |
| 103 | +end |
0 commit comments