mirror of
https://github.com/apache/superset.git
synced 2024-09-19 20:19:37 -04:00
9fe30ab71e
* getting rid of weird focus/active outline ring
* Buttons... buttons _everywhere_
* linting
* Nixing views/CRUD/dataset/Button component
* fixing 2 typing errors
* fixing more TS errors
* prefer src path for include
* one more real button, one less CSS class
* one more "button" to "Button"
* Published Status is now a proper clickable Label
* nixing the CRUD button again
* touching up stories, with SupersetButton story
* SIP-34 button colors
* adding polished package to mix colors
* updating button colors to match Superset theme
* abstracting away from bootstrap-specific props (might pivot libraries soon!)
* more abstraction from bsStyle/bsSize props
* exchanging styles for a prop
* linting
* restoring feature flag to stock
* using src alias
* last <button> replacement
* this classname would never be applied
* more linting action
* fixing unsupported bsSize 'medium', and cta typing error
* more cta action
* unnecessary styles
* errant bsSize prop
* cleanup
* tweaks to make new New button work
* Linting
* fixing a couple tests
* fixing theme based test failure
* margin tweak for NEW button
* another fixed test
* another fixed test
* fixing two more tests
* fixing last broken tests.
* always be linting
* Adding tertiary/dashed buttons
* cleaning up QueryAndSave buttons
* fixing "link" button styles
* fixing/updating link button styles
* cta buttons on Modal component
* linting.
* exporting button story knobs, making ALL knobs safe for export.
* capitalizing a file... no big whoop
* Basic button tests
* renaming button - temporarily
* renaming file to fix capitalization issue
* passing theme through to a difficult popover.
* fixin' a newly busted unit test
* lint fixin'
* oops, shouldn't have changed this prop!
* adding a dive() to themedShallow, and fixing a cypress/jest test
* addressing lint stuff
* touching up stories, with SupersetButton story
* SIP-34 button colors
* updating button colors to match Superset theme
* abstracting away from bootstrap-specific props (might pivot libraries soon!)
* linting
* restoring feature flag to stock
* cleanup
* Linting
* renaming button - temporarily
* renaming file to fix capitalization issue
* oops, shouldn't have changed this prop!
* adding a dive() to themedShallow, and fixing a cypress/jest test
* addressing lint stuff
* nixing new modal button
* Fixing another popover/button issue that should break cypress
* lint ✨
* passing classNames through to new button (should fix some tests)
* cleaning unused classes, making cypress tests use data attrs
* fixin' the test
* fixing another class-based test with data-test attr
* no longer passing theme as prop to buttons in popovers... themeprovider is better
* outline/border tweaks!
137 lines
5.1 KiB
JavaScript
137 lines
5.1 KiB
JavaScript
/**
|
|
* 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.
|
|
*/
|
|
/* eslint-disable no-unused-expressions */
|
|
import React from 'react';
|
|
import sinon from 'sinon';
|
|
import { shallow } from 'enzyme';
|
|
import { FormGroup, Popover } from 'react-bootstrap';
|
|
import Button from 'src/components/Button';
|
|
|
|
import AdhocMetric, { EXPRESSION_TYPES } from 'src/explore/AdhocMetric';
|
|
import AdhocMetricEditPopover from 'src/explore/components/AdhocMetricEditPopover';
|
|
import { AGGREGATES } from 'src/explore/constants';
|
|
|
|
const columns = [
|
|
{ type: 'VARCHAR(255)', column_name: 'source' },
|
|
{ type: 'VARCHAR(255)', column_name: 'target' },
|
|
{ type: 'DOUBLE', column_name: 'value' },
|
|
];
|
|
|
|
const sumValueAdhocMetric = new AdhocMetric({
|
|
expressionType: EXPRESSION_TYPES.SIMPLE,
|
|
column: columns[2],
|
|
aggregate: AGGREGATES.SUM,
|
|
});
|
|
|
|
const sqlExpressionAdhocMetric = new AdhocMetric({
|
|
expressionType: EXPRESSION_TYPES.SQL,
|
|
sqlExpression: 'COUNT(*)',
|
|
});
|
|
|
|
function setup(overrides) {
|
|
const onChange = sinon.spy();
|
|
const onClose = sinon.spy();
|
|
const props = {
|
|
adhocMetric: sumValueAdhocMetric,
|
|
onChange,
|
|
onClose,
|
|
columns,
|
|
...overrides,
|
|
};
|
|
const wrapper = shallow(<AdhocMetricEditPopover {...props} />);
|
|
return { wrapper, onChange, onClose };
|
|
}
|
|
|
|
describe('AdhocMetricEditPopover', () => {
|
|
it('renders a popover with edit metric form contents', () => {
|
|
const { wrapper } = setup();
|
|
expect(wrapper.find(Popover)).toExist();
|
|
expect(wrapper.find(FormGroup)).toHaveLength(3);
|
|
expect(wrapper.find(Button)).toHaveLength(2);
|
|
});
|
|
|
|
it('overwrites the adhocMetric in state with onColumnChange', () => {
|
|
const { wrapper } = setup();
|
|
wrapper.instance().onColumnChange(columns[0]);
|
|
expect(wrapper.state('adhocMetric')).toEqual(
|
|
sumValueAdhocMetric.duplicateWith({ column: columns[0] }),
|
|
);
|
|
});
|
|
|
|
it('overwrites the adhocMetric in state with onAggregateChange', () => {
|
|
const { wrapper } = setup();
|
|
wrapper.instance().onAggregateChange(AGGREGATES.AVG);
|
|
expect(wrapper.state('adhocMetric')).toEqual(
|
|
sumValueAdhocMetric.duplicateWith({ aggregate: AGGREGATES.AVG }),
|
|
);
|
|
});
|
|
|
|
it('overwrites the adhocMetric in state with onSqlExpressionChange', () => {
|
|
const { wrapper } = setup({ adhocMetric: sqlExpressionAdhocMetric });
|
|
wrapper.instance().onSqlExpressionChange('COUNT(1)');
|
|
expect(wrapper.state('adhocMetric')).toEqual(
|
|
sqlExpressionAdhocMetric.duplicateWith({ sqlExpression: 'COUNT(1)' }),
|
|
);
|
|
});
|
|
|
|
it('overwrites the adhocMetric in state with onLabelChange', () => {
|
|
const { wrapper } = setup();
|
|
wrapper.instance().onLabelChange({ target: { value: 'new label' } });
|
|
expect(wrapper.state('adhocMetric').label).toBe('new label');
|
|
expect(wrapper.state('adhocMetric').hasCustomLabel).toBe(true);
|
|
});
|
|
|
|
it('returns to default labels when the custom label is cleared', () => {
|
|
const { wrapper } = setup();
|
|
wrapper.instance().onLabelChange({ target: { value: 'new label' } });
|
|
wrapper.instance().onLabelChange({ target: { value: '' } });
|
|
expect(wrapper.state('adhocMetric').label).toBe('SUM(value)');
|
|
expect(wrapper.state('adhocMetric').hasCustomLabel).toBe(false);
|
|
});
|
|
|
|
it('prevents saving if no column or aggregate is chosen', () => {
|
|
const { wrapper } = setup();
|
|
expect(wrapper.find(Button).find({ disabled: true })).not.toExist();
|
|
wrapper.instance().onColumnChange(null);
|
|
expect(wrapper.find(Button).find({ disabled: true })).toExist();
|
|
wrapper.instance().onColumnChange({ column: columns[0] });
|
|
expect(wrapper.find(Button).find({ disabled: true })).not.toExist();
|
|
wrapper.instance().onAggregateChange(null);
|
|
expect(wrapper.find(Button).find({ disabled: true })).toExist();
|
|
});
|
|
|
|
it('highlights save if changes are present', () => {
|
|
const { wrapper } = setup();
|
|
expect(wrapper.find(Button).find({ buttonStyle: 'primary' })).not.toExist();
|
|
wrapper.instance().onColumnChange({ column: columns[1] });
|
|
expect(wrapper.find(Button).find({ buttonStyle: 'primary' })).toExist();
|
|
});
|
|
|
|
it('will initiate a drag when clicked', () => {
|
|
const { wrapper } = setup();
|
|
wrapper.instance().onDragDown = sinon.spy();
|
|
wrapper.instance().forceUpdate();
|
|
|
|
expect(wrapper.find('i.fa-expand')).toExist();
|
|
expect(wrapper.instance().onDragDown.calledOnce).toBe(false);
|
|
wrapper.find('i.fa-expand').simulate('mouseDown');
|
|
expect(wrapper.instance().onDragDown.calledOnce).toBe(true);
|
|
});
|
|
});
|