Skip to content

Commit

Permalink
fix test
Browse files Browse the repository at this point in the history
  • Loading branch information
villebro committed Jan 5, 2023
1 parent b91afd6 commit 4859955
Showing 1 changed file with 54 additions and 1 deletion.
55 changes: 54 additions & 1 deletion superset-frontend/src/views/CRUD/welcome/Welcome.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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 () => {
Expand All @@ -122,6 +127,10 @@ describe('Welcome', () => {
});
});

afterAll(() => {
fetchMock.resetHistory();
});

it('renders', () => {
expect(wrapper).toExist();
});
Expand All @@ -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(
<Provider store={store}>
<Welcome {...props} />
</Provider>,
);
});
});

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(
<Provider store={store}>
Expand Down

0 comments on commit 4859955

Please sign in to comment.