From 4859955fd1380f201c7cca6e99a9c68b71455e71 Mon Sep 17 00:00:00 2001 From: Ville Brofeldt Date: Thu, 5 Jan 2023 12:59:38 +0200 Subject: [PATCH] fix test --- .../src/views/CRUD/welcome/Welcome.test.tsx | 55 ++++++++++++++++++- 1 file changed, 54 insertions(+), 1 deletion(-) diff --git a/superset-frontend/src/views/CRUD/welcome/Welcome.test.tsx b/superset-frontend/src/views/CRUD/welcome/Welcome.test.tsx index ce688f08fffd0..5c693ab261ae2 100644 --- a/superset-frontend/src/views/CRUD/welcome/Welcome.test.tsx +++ b/superset-frontend/src/views/CRUD/welcome/Welcome.test.tsx @@ -106,10 +106,15 @@ const mockedProps = { userId: 5, email: 'alpha@alpha.com', isActive: true, + isAnonymous: false, + permissions: {}, + roles: { + sql_lab: [], + }, }, }; -describe('Welcome', () => { +describe('Welcome with sql role', () => { let wrapper: ReactWrapper; beforeAll(async () => { @@ -122,6 +127,10 @@ describe('Welcome', () => { }); }); + afterAll(() => { + fetchMock.resetHistory(); + }); + it('renders', () => { expect(wrapper).toExist(); }); @@ -142,6 +151,50 @@ describe('Welcome', () => { }); }); +describe('Welcome without sql role', () => { + let wrapper: ReactWrapper; + + beforeAll(async () => { + await act(async () => { + const props = { + ...mockedProps, + user: { + ...mockedProps.user, + roles: {}, + }, + }; + wrapper = mount( + + + , + ); + }); + }); + + afterAll(() => { + fetchMock.resetHistory(); + }); + + it('renders', () => { + expect(wrapper).toExist(); + }); + + it('renders all panels on the page on page load', () => { + expect(wrapper.find('CollapsePanel')).toHaveLength(6); + }); + + it('calls api methods in parallel on page load', () => { + const chartCall = fetchMock.calls(/chart\/\?q/); + const savedQueryCall = fetchMock.calls(/saved_query\/\?q/); + const recentCall = fetchMock.calls(/superset\/recent_activity\/*/); + const dashboardCall = fetchMock.calls(/dashboard\/\?q/); + expect(chartCall).toHaveLength(2); + expect(recentCall).toHaveLength(1); + expect(savedQueryCall).toHaveLength(0); + expect(dashboardCall).toHaveLength(2); + }); +}); + async function mountAndWait(props = mockedProps) { const wrapper = mount(