Skip to content

Commit

Permalink
Fix annotation layer test
Browse files Browse the repository at this point in the history
  • Loading branch information
ktmud committed Feb 26, 2021
1 parent e4e6172 commit 891fadc
Show file tree
Hide file tree
Showing 3 changed files with 81 additions and 57 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,44 +55,3 @@ describe('Advanced analytics', () => {
.contains('1 year');
});
});

describe('Annotations', () => {
beforeEach(() => {
cy.login();
cy.intercept('GET', '/superset/explore_json/**').as('getJson');
cy.intercept('POST', '/superset/explore_json/**').as('postJson');
});

it('Create formula annotation y-axis goal line', () => {
cy.visitChartByName('Num Births Trend');
cy.verifySliceSuccess({ waitAlias: '@postJson' });

cy.get('[data-test=annotation_layers]').within(() => {
cy.get('button').click();
});

cy.get('[data-test="popover-content"]').within(() => {
cy.get('[data-test=annotation-layer-name-header]')
.siblings()
.first()
.within(() => {
cy.get('input').type('Goal line');
});
cy.get('[data-test=annotation-layer-value-header]')
.siblings()
.first()
.within(() => {
cy.get('input').type('y=1400000');
});
cy.get('button').contains('OK').click({ force: true });
});

cy.get('button[data-test="run-query-button"]').click();
cy.verifySliceSuccess({
waitAlias: '@postJson',
chartSelector: 'svg',
});

cy.get('.nv-legend-text').should('have.length', 2);
});
});
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/**
* 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.
*/
describe('Annotations', () => {
beforeEach(() => {
cy.login();
cy.intercept('GET', '/superset/explore_json/**').as('getJson');
cy.intercept('POST', '/superset/explore_json/**').as('postJson');
});

it('Create formula annotation y-axis goal line', () => {
cy.visitChartByName('Num Births Trend');
cy.verifySliceSuccess({ waitAlias: '@postJson' });

const layerLabel = 'Goal line';

cy.get('[data-test=annotation_layers] button').click();

cy.get('[data-test="popover-content"]').within(() => {
cy.get('[data-test=annotation-layer-name-header]')
.siblings()
.first()
.within(() => {
cy.get('input').type(layerLabel);
});
cy.get('[data-test=annotation-layer-value-header]')
.siblings()
.first()
.within(() => {
cy.get('input').type('y=1400000');
});
cy.get('button').contains('OK').click();
});

cy.get('button[data-test="run-query-button"]').click();
cy.get('[data-test=annotation_layers]').contains(layerLabel);

cy.verifySliceSuccess({
waitAlias: '@postJson',
chartSelector: 'svg',
});
cy.get('.nv-legend-text').should('have.length', 2);
});
});
38 changes: 22 additions & 16 deletions superset-frontend/src/explore/reducers/exploreReducer.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,32 +62,38 @@ export default function exploreReducer(state = {}, action) {
delete newFormData.time_grain_sqla;
}
}

const controls = { ...state.controls };
if (
action.datasource.id !== state.datasource.id ||
action.datasource.type !== state.datasource.type
) {
// reset time range filter to default
newFormData.time_range = DEFAULT_TIME_RANGE;
// if a control use datasource columns, reset it to default
// TODO: filter out only invalid columns and keep others
Object.entries(state.controls).forEach(
([controlName, controlState]) => {
if (
// for direct column select controls
controlState.valueKey === 'column_name' ||
// for all other controls
'columns' in controlState
) {
// reset to `undefined`, let `getControlsState` to pick up the default
controlState.value = undefined;
newFormData[controlName] = undefined;
}
},
);

// reset control values for column/metric related controls
Object.entries(controls).forEach(([controlName, controlState]) => {
if (
// for direct column select controls
controlState.valueKey === 'column_name' ||
// for all other controls
'columns' in controlState
) {
// if a control use datasource columns, reset its value to `undefined`,
// then `getControlsState` will pick up the default.
// TODO: filter out only invalid columns and keep others
controls[controlName] = {
...controlState,
value: undefined,
};
newFormData[controlName] = undefined;
}
});
}

const newState = {
...state,
controls,
datasource: action.datasource,
datasource_id: action.datasource.id,
datasource_type: action.datasource.type,
Expand Down

0 comments on commit 891fadc

Please sign in to comment.