You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@superset.apache.org by yj...@apache.org on 2020/10/29 05:45:09 UTC

[incubator-superset] 26/33: update tests and clear typescript errors

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

yjc pushed a commit to branch home-screen-mvp
in repository https://gitbox.apache.org/repos/asf/incubator-superset.git

commit 065ad3c1778541467e645117285df1259316e9fb
Author: Phillip Kelley-Dotson <pk...@yahoo.com>
AuthorDate: Fri Oct 23 22:44:10 2020 -0700

    update tests and clear typescript errors
---
 .../views/CRUD/welcome/ChartTable_spec.tsx         |  8 +--
 .../views/CRUD/welcome/EmptyState_spec.tsx         | 76 +++++++++++++++++++---
 .../views/CRUD/welcome/SavedQueries_spec.tsx       | 20 ++++--
 .../views/CRUD/welcome/Welcome_spec.tsx            |  3 +-
 .../src/views/CRUD/dashboard/DashboardCard.tsx     |  2 +-
 .../src/views/CRUD/welcome/EmptyState.tsx          |  5 +-
 6 files changed, 89 insertions(+), 25 deletions(-)

diff --git a/superset-frontend/spec/javascripts/views/CRUD/welcome/ChartTable_spec.tsx b/superset-frontend/spec/javascripts/views/CRUD/welcome/ChartTable_spec.tsx
index 7a39e9f..aa024d8 100644
--- a/superset-frontend/spec/javascripts/views/CRUD/welcome/ChartTable_spec.tsx
+++ b/superset-frontend/spec/javascripts/views/CRUD/welcome/ChartTable_spec.tsx
@@ -31,7 +31,6 @@ const mockStore = configureStore([thunk]);
 const store = mockStore({});
 
 const chartsEndpoint = 'glob:*/api/v1/chart/?*';
-// fetchMock.get(chartsEndpoint, { result: mockDashboards });
 
 const mockCharts = [...new Array(3)].map((_, i) => ({
   changed_on_utc: new Date().toISOString(),
@@ -44,15 +43,11 @@ const mockCharts = [...new Array(3)].map((_, i) => ({
   thumbnail_url: '/thumbnail',
 }));
 
-/* fetchMock.get(chartsEndpoint, {
-  result: [],
-});
-*/
 fetchMock.get(chartsEndpoint, {
   result: mockCharts,
 });
 
-describe('DashboardTable', () => {
+describe('ChartTable', () => {
   beforeEach(fetchMock.resetHistory);
 
   const mockedProps = {};
@@ -67,6 +62,7 @@ describe('DashboardTable', () => {
   it('it renders', () => {
     expect(wrapper.find(ChartTable)).toExist();
   });
+
   it('fetches chart favorites and renders chart cards ', () => {
     expect(fetchMock.calls(chartsEndpoint)).toHaveLength(1);
     expect(wrapper.find(ChartCard)).toExist();
diff --git a/superset-frontend/spec/javascripts/views/CRUD/welcome/EmptyState_spec.tsx b/superset-frontend/spec/javascripts/views/CRUD/welcome/EmptyState_spec.tsx
index b4eb6d1..7eaa234 100644
--- a/superset-frontend/spec/javascripts/views/CRUD/welcome/EmptyState_spec.tsx
+++ b/superset-frontend/spec/javascripts/views/CRUD/welcome/EmptyState_spec.tsx
@@ -18,18 +18,78 @@
  */
 import React from 'react';
 import { styledMount as mount } from 'spec/helpers/theming';
-import { act } from 'react-dom/test-utils';
-
-import waitForComponentToPaint from 'spec/helpers/waitForComponentToPaint';
 import EmptyState from 'src/views/CRUD/welcome/EmptyState';
 
 describe('EmptyState', () => {
-  it('it renders an favorite dashboard empty state', () => {
-    const props = {
+  const variants = [
+    {
       tab: 'Favorite',
       tableName: 'DASHBOARDS',
-    };
-    const wrapper = mount(<EmptyState {...props} />);
-    expect(wrapper).toExist();
+    },
+    {
+      tab: 'Mine',
+      tableName: 'DASHBOARDS',
+    },
+    {
+      tab: 'Favorite',
+      tableName: 'CHARTS',
+    },
+    {
+      tab: 'Mine',
+      tableName: 'CHARTS',
+    },
+    {
+      tab: 'Favorite',
+      tableName: 'SAVED_QUERIES',
+    },
+    {
+      tab: 'Mine',
+      tableName: 'SAVED_QUEREIS',
+    },
+  ];
+  const recents = [
+    {
+      tab: 'Viewed',
+      tableName: 'RECENTS',
+    },
+    {
+      tab: 'Edited',
+      tableName: 'RECENTS',
+    },
+    {
+      tab: 'Created',
+      tableName: 'RECENTS',
+    },
+  ];
+  variants.forEach(variant => {
+    it(`it renders an ${variant.tab} ${variant.tableName} empty state`, () => {
+      const wrapper = mount(<EmptyState {...variant} />);
+      expect(wrapper).toExist();
+      const textContainer = wrapper.find('.ant-empty-description');
+      expect(textContainer.text()).toEqual(
+        variant.tab === 'Favorite'
+          ? "You don't have any favorites yet!"
+          : `No ${
+              variant.tableName === 'SAVED_QUERIES'
+                ? 'saved queries'
+                : variant.tableName.toLowerCase()
+            } yet`,
+      );
+      console.log('wrapper', wrapper.debug());
+      console.log('wrapper', wrapper.find('ant-empty-image').children().debug());
+      //expect(wrapper.find('ant-empty-image').children()).toHaveLength(1);
+      expect(wrapper.find('button')).toHaveLength(1);
+    });
+  });
+  recents.forEach(recent => {
+    it(`it renders an ${recent.tab} ${recent.tableName} empty state`, () => {
+      const wrapper = mount(<EmptyState {...recent} />);
+      expect(wrapper).toExist();
+      const textContainer = wrapper.find('.ant-empty-description');
+      expect(wrapper.find('.ant-empty-image').children()).toHaveLength(1);
+      expect(textContainer.text()).toContain(
+        `Recently ${recent.tab.toLowerCase()} charts, dashboards, and saved queries will appear here`,
+      );
+    });
   });
 });
diff --git a/superset-frontend/spec/javascripts/views/CRUD/welcome/SavedQueries_spec.tsx b/superset-frontend/spec/javascripts/views/CRUD/welcome/SavedQueries_spec.tsx
index 28173f2..015e4eb 100644
--- a/superset-frontend/spec/javascripts/views/CRUD/welcome/SavedQueries_spec.tsx
+++ b/superset-frontend/spec/javascripts/views/CRUD/welcome/SavedQueries_spec.tsx
@@ -31,7 +31,8 @@ import SavedQueries from 'src/views/CRUD/welcome/SavedQueries';
 const mockStore = configureStore([thunk]);
 const store = mockStore({});
 
-const queriesEndpoint = 'glob:*/api/v1/saved_queries/?*';
+const queriesEndpoint = 'glob:*/api/v1/saved_query/?*';
+const savedQueriesInfo = 'glob:*/api/v1/saved_query/_info';
 
 const mockqueries = [...new Array(3)].map((_, i) => ({
   created_by: {
@@ -64,6 +65,10 @@ fetchMock.get(queriesEndpoint, {
   result: mockqueries,
 });
 
+fetchMock.get(savedQueriesInfo, {
+  permissions: ['can_list', 'can_edit', 'can_delete'],
+});
+
 describe('SavedQueries', () => {
   const savedQueryProps = {
     user: {
@@ -82,19 +87,22 @@ describe('SavedQueries', () => {
     expect(wrapper.find(SavedQueries)).toExist();
   });
 
-  it('it renders a submenu with clickable tabls and buttons', async () => {
+  it('it renders a submenu with clickable tables and buttons', async () => {
     expect(wrapper.find(SubMenu)).toExist();
     expect(wrapper.find('MenuItem')).toHaveLength(2);
-    expect(wrapper.find('Button')).toHaveLength(4);
+    console.log('button', wrapper.find('button').length);
     act(() => {
       wrapper.find('MenuItem').at(1).simulate('click');
     });
+
+    console.log('menu item', wrapper.find('MenuItem').at(1).debug());
     await waitForComponentToPaint(wrapper);
-    expect(fetchMock.calls(/chart\/\?q/)).toHaveLength(1);
+    expect(fetchMock.calls(/saved_query\/\?q/)).toHaveLength(1);
   });
 
-  it('fetches queries favorites and renders chart cards', () => {
-    expect(fetchMock.calls(/chart\/\?q/)).toHaveLength(1);
+  it('fetches queries favorites and renders listviewcard cards', () => {
+    expect(fetchMock.calls(/saved_query\/\?q/)).toHaveLength(1);
     expect(wrapper.find('ListViewCard')).toExist();
+    console.log('wrapper', wrapper);
   });
 });
diff --git a/superset-frontend/spec/javascripts/views/CRUD/welcome/Welcome_spec.tsx b/superset-frontend/spec/javascripts/views/CRUD/welcome/Welcome_spec.tsx
index 38891c0..fa1778d 100644
--- a/superset-frontend/spec/javascripts/views/CRUD/welcome/Welcome_spec.tsx
+++ b/superset-frontend/spec/javascripts/views/CRUD/welcome/Welcome_spec.tsx
@@ -37,8 +37,7 @@ describe('Welcome', () => {
   it('is renders', () => {
     expect(wrapper.find(Welcome)).toExist();
   });
-  it('renders first submenu on page load', () => {
-    expect(wrapper.find('SubMenu')).toHaveLength(1);
+  it('renders all panels on the page on page load', () => {
     expect(wrapper.find('PanelContent')).toHaveLength(4);
   });
 });
diff --git a/superset-frontend/src/views/CRUD/dashboard/DashboardCard.tsx b/superset-frontend/src/views/CRUD/dashboard/DashboardCard.tsx
index 2a09f70..2469d64 100644
--- a/superset-frontend/src/views/CRUD/dashboard/DashboardCard.tsx
+++ b/superset-frontend/src/views/CRUD/dashboard/DashboardCard.tsx
@@ -113,7 +113,7 @@ function DashboardCard({
   );
   return (
     <ListViewCard
-      loading={dashboard.loading}
+      loading={dashboard.loading || false}
       title={dashboard.dashboard_title}
       titleRight={<Label>{dashboard.published ? 'published' : 'draft'}</Label>}
       url={bulkSelectEnabled ? undefined : dashboard.url}
diff --git a/superset-frontend/src/views/CRUD/welcome/EmptyState.tsx b/superset-frontend/src/views/CRUD/welcome/EmptyState.tsx
index fe2d03e..381a08d 100644
--- a/superset-frontend/src/views/CRUD/welcome/EmptyState.tsx
+++ b/superset-frontend/src/views/CRUD/welcome/EmptyState.tsx
@@ -62,8 +62,9 @@ export default function EmptyState({ tableName, tab }: EmptyStateProps) {
   );
   const recent = (
     <div className="no-recents">
-      {t(`Recently ${tab?.toLowerCase()} charts, dashboards, and saved queries will
-      appear here`)}
+      {t(
+        `Recently ${tab?.toLowerCase()} charts, dashboards, and saved queries will appear here`,
+      )}
     </div>
   );
   // Mine and Recent Activity(all tabs) tab empty state