You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by rt...@apache.org on 2024/08/02 23:53:58 UTC

(superset) branch master updated: refactor(controls): Migrate MetricDefinitionValue.test to RTL (#29845)

This is an automated email from the ASF dual-hosted git repository.

rtmabbz pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/superset.git


The following commit(s) were added to refs/heads/master by this push:
     new 27c08d0e0e refactor(controls): Migrate MetricDefinitionValue.test to RTL (#29845)
27c08d0e0e is described below

commit 27c08d0e0eca215a1dc6e08b9392177661d278bf
Author: Ross Mabbett <92...@users.noreply.github.com>
AuthorDate: Fri Aug 2 19:53:52 2024 -0400

    refactor(controls): Migrate MetricDefinitionValue.test to RTL (#29845)
---
 .../MetricControl/MetricDefinitionValue.test.jsx   | 50 +++++++++++-----------
 1 file changed, 26 insertions(+), 24 deletions(-)

diff --git a/superset-frontend/src/explore/components/controls/MetricControl/MetricDefinitionValue.test.jsx b/superset-frontend/src/explore/components/controls/MetricControl/MetricDefinitionValue.test.jsx
index 3b51fcc508..d55bfa1d83 100644
--- a/superset-frontend/src/explore/components/controls/MetricControl/MetricDefinitionValue.test.jsx
+++ b/superset-frontend/src/explore/components/controls/MetricControl/MetricDefinitionValue.test.jsx
@@ -16,38 +16,40 @@
  * specific language governing permissions and limitations
  * under the License.
  */
-import { shallow } from 'enzyme';
-
-import { AGGREGATES } from 'src/explore/constants';
+import { render, screen } from 'spec/helpers/testing-library';
 import MetricDefinitionValue from 'src/explore/components/controls/MetricControl/MetricDefinitionValue';
-import AdhocMetricOption from 'src/explore/components/controls/MetricControl/AdhocMetricOption';
 import AdhocMetric from 'src/explore/components/controls/MetricControl/AdhocMetric';
+import { AGGREGATES } from 'src/explore/constants';
 
 const sumValueAdhocMetric = new AdhocMetric({
   column: { type: 'DOUBLE', column_name: 'value' },
   aggregate: AGGREGATES.SUM,
 });
 
-describe('MetricDefinitionValue', () => {
-  it('renders a MetricOption given a saved metric', () => {
-    const wrapper = shallow(
-      <MetricDefinitionValue
-        onMetricEdit={() => {}}
-        option={{ metric_name: 'a_saved_metric', expression: 'COUNT(*)' }}
-        index={1}
-      />,
-    );
-    expect(wrapper.find('AdhocMetricOption')).toExist();
-  });
+const setup = propOverrides => {
+  const props = {
+    onMetricEdit: jest.fn(),
+    option: sumValueAdhocMetric,
+    index: 1,
+    columns: [],
+    savedMetrics: [],
+    savedMetricsOptions: [],
+    datasource: {},
+    onMoveLabel: jest.fn(),
+    onDropLabel: jest.fn(),
+    ...propOverrides,
+  };
+  return render(<MetricDefinitionValue {...props} />, { useDnd: true });
+};
 
-  it('renders an AdhocMetricOption given an adhoc metric', () => {
-    const wrapper = shallow(
-      <MetricDefinitionValue
-        onMetricEdit={() => {}}
-        option={sumValueAdhocMetric}
-        index={1}
-      />,
-    );
-    expect(wrapper.find(AdhocMetricOption)).toExist();
+test('renders a MetricOption given a saved metric', () => {
+  setup({
+    option: { metric_name: 'a_saved_metric', expression: 'COUNT(*)' },
   });
+  expect(screen.getByText('a_saved_metric')).toBeInTheDocument();
+});
+
+test('renders an AdhocMetricOption given an adhoc metric', () => {
+  setup();
+  expect(screen.getByText('SUM(value)')).toBeInTheDocument();
 });