From 891fadcbd7ffec3bc5c3bcb7065667243a94dba5 Mon Sep 17 00:00:00 2001 From: Jesse Yang Date: Wed, 24 Feb 2021 16:22:14 -1000 Subject: [PATCH] Fix annotation layer test --- ...ced.test.ts => advanced_analytics.test.ts} | 41 ------------- .../integration/explore/annotations.test.ts | 59 +++++++++++++++++++ .../src/explore/reducers/exploreReducer.js | 38 +++++++----- 3 files changed, 81 insertions(+), 57 deletions(-) rename superset-frontend/cypress-base/cypress/integration/explore/{advanced.test.ts => advanced_analytics.test.ts} (63%) create mode 100644 superset-frontend/cypress-base/cypress/integration/explore/annotations.test.ts diff --git a/superset-frontend/cypress-base/cypress/integration/explore/advanced.test.ts b/superset-frontend/cypress-base/cypress/integration/explore/advanced_analytics.test.ts similarity index 63% rename from superset-frontend/cypress-base/cypress/integration/explore/advanced.test.ts rename to superset-frontend/cypress-base/cypress/integration/explore/advanced_analytics.test.ts index 066ae868a1954..77ebfbe7f9a47 100644 --- a/superset-frontend/cypress-base/cypress/integration/explore/advanced.test.ts +++ b/superset-frontend/cypress-base/cypress/integration/explore/advanced_analytics.test.ts @@ -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); - }); -}); diff --git a/superset-frontend/cypress-base/cypress/integration/explore/annotations.test.ts b/superset-frontend/cypress-base/cypress/integration/explore/annotations.test.ts new file mode 100644 index 0000000000000..ebbaddf72dbce --- /dev/null +++ b/superset-frontend/cypress-base/cypress/integration/explore/annotations.test.ts @@ -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); + }); +}); diff --git a/superset-frontend/src/explore/reducers/exploreReducer.js b/superset-frontend/src/explore/reducers/exploreReducer.js index 99cdf4db30a5d..7727049df9de3 100644 --- a/superset-frontend/src/explore/reducers/exploreReducer.js +++ b/superset-frontend/src/explore/reducers/exploreReducer.js @@ -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,