This repository has been archived by the owner on Jul 9, 2022. It is now read-only.
forked from apache/superset
/
filter.test.js
103 lines (88 loc) · 3.25 KB
/
filter.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
import { WORLD_HEALTH_DASHBOARD } from './dashboard.helper';
describe('Dashboard filter', () => {
let filterId;
let aliases;
const getAlias = id => {
return `@slice_${id}`;
};
beforeEach(() => {
cy.server();
cy.login();
cy.visit(WORLD_HEALTH_DASHBOARD);
cy.get('#app').then(data => {
const bootstrapData = JSON.parse(data[0].dataset.bootstrap);
const dashboard = bootstrapData.dashboard_data;
const sliceIds = dashboard.slices.map(slice => slice.slice_id);
filterId = dashboard.slices.find(
slice => slice.form_data.viz_type === 'filter_box',
).slice_id;
aliases = sliceIds.map(id => {
const alias = getAlias(id);
const url = `/superset/explore_json/?*{"slice_id":${id}}*`;
cy.route('POST', url).as(alias.slice(1));
return alias;
});
// wait the initial page load requests
cy.wait(aliases);
});
});
it('should apply filter', () => {
cy.get('.Select__control input[type=text]').first().focus();
// should open the filter indicator
cy.get('.filter-indicator.active')
.should('be.visible')
.should(nodes => {
expect(nodes).to.have.length(9);
});
cy.get('.Select__control input[type=text]').first().focus().blur();
// should hide the filter indicator
cy.get('.filter-indicator')
.not('.active')
.should(nodes => {
expect(nodes).to.have.length(18);
});
cy.get('.Select__control input[type=text]')
.first()
.focus({ force: true })
.type('So', { force: true });
cy.get('.Select__menu').first().contains('Create "So"');
// Somehow Input loses focus after typing "So" while in Cypress, so
// we refocus the input again here. The is not happening in real life.
cy.get('.Select__control input[type=text]')
.first()
.focus({ force: true })
.type('uth Asia{enter}', { force: true });
// by default, need to click Apply button to apply filter
cy.get('.filter_box button').click({ force: true });
// wait again after applied filters
cy.wait(aliases.filter(x => x !== getAlias(filterId))).then(requests => {
requests.forEach(xhr => {
const requestFormData = xhr.request.body;
const requestParams = JSON.parse(requestFormData.get('form_data'));
expect(requestParams.extra_filters[0]).deep.eq({
col: 'region',
op: 'in',
val: ['South Asia'],
});
});
});
});
});