On filters reseting , set dates to undefined: range is not mandatory

+ send flatpickr event to reset the component

+ update specs as well
This commit is contained in:
Jean-Baptiste Bellet
2023-01-05 15:02:52 +01:00
parent b75b123cba
commit 121a4a08af
4 changed files with 8 additions and 21 deletions

View File

@@ -13,22 +13,14 @@ angular.module("admin.lineItems").controller 'LineItemsCtrl', ($scope, $timeout,
$scope.confirmRefresh = ->
LineItems.allSaved() || confirm(t("unsaved_changes_warning"))
$scope.initStartAndEnDate = ->
$scope.startDate = moment().startOf('day').subtract(7, 'days').format('YYYY-MM-DD')
$scope.endDate = moment().startOf('day').format('YYYY-MM-DD')
$scope.resetFilters = ->
$scope.distributorFilter = ''
$scope.supplierFilter = ''
$scope.orderCycleFilter = ''
$scope.quickSearch = ''
$scope.initStartAndEnDate()
event = new CustomEvent('flatpickr:change', {
detail: {
startDate: $scope.startDate,
endDate: $scope.endDate
}
})
$scope.startDate = undefined
$scope.endDate = undefined
event = new CustomEvent('flatpickr:clear')
window.dispatchEvent(event)
$scope.resetSelectFilters = ->

View File

@@ -55,6 +55,7 @@ export default class extends Flatpickr {
mode,
};
window.addEventListener("flatpickr:change", this.onChangeEvent.bind(this));
window.addEventListener("flatpickr:clear", this.clear.bind(this));
}
clear(e) {

View File

@@ -49,7 +49,7 @@ describe "LineItemsCtrl", ->
return Promise.resolve()
allSaved: jasmine.createSpy('allSaved').and.returnValue(true)
httpBackend.expectGET("/api/v0/orders.json?q%5Bcompleted_at_gteq%5D=SomeDate&q%5Bcompleted_at_lt%5D=SomeDate&q%5Bcompleted_at_not_null%5D=true&q%5Bdistributor_id_eq%5D=&q%5Border_cycle_id_eq%5D=&q%5Bshipment_state_not_eq%5D=shipped&q%5Bstate_not_eq%5D=canceled").respond {orders: [order], pagination: {page: 1, pages: 1, results: 1}}
httpBackend.expectGET("/api/v0/orders.json?q%5Bcompleted_at_not_null%5D=true&q%5Bdistributor_id_eq%5D=&q%5Border_cycle_id_eq%5D=&q%5Bshipment_state_not_eq%5D=shipped&q%5Bstate_not_eq%5D=canceled").respond {orders: [order], pagination: {page: 1, pages: 1, results: 1}}
httpBackend.expectGET("/admin/enterprises/visible.json?ams_prefix=basic&q%5Bsells_in%5D%5B%5D=own&q%5Bsells_in%5D%5B%5D=any").respond [distributor]
httpBackend.expectGET("/admin/order_cycles.json?ams_prefix=basic&as=distributor&q%5Borders_close_at_gt%5D=SomeDate").respond [orderCycle]
httpBackend.expectGET("/admin/enterprises/visible.json?ams_prefix=basic&q%5Bis_primary_producer_eq%5D=true").respond [supplier]

View File

@@ -625,17 +625,11 @@ describe '
visit_bulk_order_management
end
it "displays date fields for filtering orders, with default values set" do
# use Date.current since Date.today is without timezone
one_week_ago = today.prev_day(7).strftime("%F")
expect(find("input.datepicker").value).to eq "#{one_week_ago} to #{today.strftime('%F')}"
end
it "only loads line items whose orders meet the date restriction criteria", retry: 3 do
expect(page).to have_no_selector "tr#li_#{li1.id}"
it "loads all line items because no date restriction on first load" do
expect(page).to have_selector "tr#li_#{li1.id}"
expect(page).to have_selector "tr#li_#{li2.id}"
expect(page).to have_selector "tr#li_#{li3.id}"
expect(page).to have_no_selector "tr#li_#{li4.id}"
expect(page).to have_selector "tr#li_#{li4.id}"
end
it "displays only line items whose orders meet the date restriction criteria, when changed", retry: 3 do