dataviz: clear subfilters on statistics change (#72315)
This commit is contained in:
parent
a281481885
commit
19e0685d11
|
@ -201,6 +201,7 @@ class ChartNgForm(ChartFiltersMixin, forms.ModelForm):
|
|||
if 'statistic' in self.changed_data:
|
||||
self.instance.filter_params.clear()
|
||||
self.instance.time_range = ''
|
||||
self.instance.subfilters.clear()
|
||||
for filter_ in self.instance.available_filters:
|
||||
if 'default' in filter_:
|
||||
self.instance.filter_params[filter_['id']] = filter_['default']
|
||||
|
|
|
@ -1723,15 +1723,25 @@ def test_chartng_cell_manager_subfilters(app, admin_user, new_api_statistics):
|
|||
manager_submit_cell(resp.form)
|
||||
|
||||
assert len(new_api_mock.call['requests']) == 4
|
||||
assert 'menu' not in resp.form.fields
|
||||
assert field_prefix + 'menu' not in resp.form.fields
|
||||
cell.refresh_from_db()
|
||||
assert cell.get_filter_params() == {'form': 'contact'}
|
||||
|
||||
# changing another filter doesn't trigger request
|
||||
resp.form[field_prefix + 'other'] = 'one'
|
||||
resp = resp.form.submit()
|
||||
manager_submit_cell(resp.form)
|
||||
assert len(new_api_mock.call['requests']) == 4
|
||||
|
||||
# again, choice with subfilter
|
||||
resp.form[field_prefix + 'form'] = 'food-request'
|
||||
manager_submit_cell(resp.form)
|
||||
assert field_prefix + 'menu' in resp.form.fields
|
||||
|
||||
# changing statistics clears subfilters
|
||||
resp.form[field_prefix + 'statistic'] = Statistic.objects.get(slug='one-serie').pk
|
||||
manager_submit_cell(resp.form)
|
||||
assert field_prefix + 'menu' not in resp.form.fields
|
||||
|
||||
|
||||
@with_httmock(new_api_mock)
|
||||
@pytest.mark.freeze_time('2021-10-06')
|
||||
|
|
Loading…
Reference in New Issue