Skip to content

Commit 72d054e

Browse files
committed
Align tests
1 parent 2caecb5 commit 72d054e

File tree

3 files changed

+56
-11
lines changed

3 files changed

+56
-11
lines changed

superset-frontend/src/components/Chart/ChartContextMenu/useContextMenu.test.tsx

+23-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,12 @@ const setup = ({
6060
...mockState,
6161
user: {
6262
...mockState.user,
63-
roles: roles ?? { Admin: [['can_explore', 'Superset']] },
63+
roles: roles ?? {
64+
Admin: [
65+
['can_explore', 'Superset'],
66+
['can_samples', 'Datasource'],
67+
],
68+
},
6469
},
6570
},
6671
});
@@ -87,12 +92,27 @@ test('Context menu contains all displayed items only', () => {
8792
expect(screen.getByText('Drill by')).toBeInTheDocument();
8893
});
8994

90-
test('Context menu contains all items for can_view_and_drill permission', () => {
95+
test('Context menu shows all items tied to can_view_and_drill permission', () => {
9196
const result = setup({
92-
roles: { Admin: [['can_view_and_drill', 'Dashboard']] },
97+
roles: {
98+
Admin: [
99+
['can_view_and_drill', 'Dashboard'],
100+
['can_samples', 'Datasource'],
101+
],
102+
},
93103
});
94104
result.current.onContextMenu(0, 0, {});
95105
expect(screen.getByText('Drill to detail')).toBeInTheDocument();
96106
expect(screen.getByText('Drill by')).toBeInTheDocument();
97107
expect(screen.getByText('Add cross-filter')).toBeInTheDocument();
98108
});
109+
110+
test('Context menu does not show "Drill to detail" without proper permissions', () => {
111+
const result = setup({
112+
roles: { Admin: [['can_view_and_drill', 'Dashboard']] },
113+
});
114+
result.current.onContextMenu(0, 0, {});
115+
expect(screen.queryByText('Drill to detail')).not.toBeInTheDocument();
116+
expect(screen.getByText('Drill by')).toBeInTheDocument();
117+
expect(screen.getByText('Add cross-filter')).toBeInTheDocument();
118+
});

superset-frontend/src/components/Chart/DrillDetail/DrillDetailModal.test.tsx

+23-3
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,16 @@ jest.mock('react-router-dom', () => ({
3535

3636
const { id: chartId, form_data: formData } = chartQueries[sliceId];
3737
const { slice_name: chartName } = formData;
38+
const store = getMockStoreWithNativeFilters();
39+
const drillToDetailModalState = {
40+
...store.getState(),
41+
user: {
42+
...store.getState().user,
43+
roles: { Admin: [['can_explore', 'Superset']] },
44+
},
45+
};
3846

39-
const renderModal = async () => {
40-
const store = getMockStoreWithNativeFilters();
47+
const renderModal = async (overrideState: Record<string, any> = {}) => {
4148
const DrillDetailModalWrapper = () => {
4249
const [showModal, setShowModal] = useState(false);
4350
return (
@@ -59,7 +66,10 @@ const renderModal = async () => {
5966
render(<DrillDetailModalWrapper />, {
6067
useRouter: true,
6168
useRedux: true,
62-
store,
69+
initialState: {
70+
...drillToDetailModalState,
71+
...overrideState,
72+
},
6373
});
6474

6575
userEvent.click(screen.getByRole('button', { name: 'Show modal' }));
@@ -93,3 +103,13 @@ test('should forward to Explore', async () => {
93103
`/explore/?dashboard_page_id=&slice_id=${sliceId}`,
94104
);
95105
});
106+
107+
test('should render "Edit chart" as disabled without can_explore permission', async () => {
108+
await renderModal({
109+
user: {
110+
...drillToDetailModalState.user,
111+
roles: { Admin: [['test_invalid_role', 'Superset']] },
112+
},
113+
});
114+
expect(screen.getByRole('button', { name: 'Edit chart' })).toBeDisabled();
115+
});

superset-frontend/src/dashboard/components/SliceHeaderControls/SliceHeaderControls.test.tsx

+10-5
Original file line numberDiff line numberDiff line change
@@ -305,18 +305,23 @@ test('Drill to detail modal is under featureflag', () => {
305305
expect(screen.queryByText('Drill to detail')).not.toBeInTheDocument();
306306
});
307307

308-
test('Should show the "Drill to detail"', () => {
308+
test('Should show "Drill to detail"', () => {
309309
// @ts-ignore
310310
global.featureFlags = {
311311
[FeatureFlag.DRILL_TO_DETAIL]: true,
312312
};
313313
const props = createProps();
314314
props.slice.slice_id = 18;
315-
renderWrapper(props);
315+
renderWrapper(props, {
316+
Admin: [
317+
['can_view_and_drill', 'Dashboard'],
318+
['can_samples', 'Datasource'],
319+
],
320+
});
316321
expect(screen.getByText('Drill to detail')).toBeInTheDocument();
317322
});
318323

319-
test('Should show the can_view_and_drill permission related items', () => {
324+
test('Should show menu items tied to can_view_and_drill permission', () => {
320325
// @ts-ignore
321326
global.featureFlags = {
322327
[FeatureFlag.DRILL_TO_DETAIL]: true,
@@ -331,10 +336,10 @@ test('Should show the can_view_and_drill permission related items', () => {
331336
});
332337
expect(screen.getByText('View query')).toBeInTheDocument();
333338
expect(screen.getByText('View as table')).toBeInTheDocument();
334-
expect(screen.getByText('Drill to detail')).toBeInTheDocument();
339+
expect(screen.queryByText('Drill to detail')).not.toBeInTheDocument();
335340
});
336341

337-
test('Should not show the "Edit chart" with can_view_and_drill permission', () => {
342+
test('Should not show the "Edit chart" without proper permissions', () => {
338343
const props = {
339344
...createProps(),
340345
supersetCanExplore: false,

0 commit comments

Comments
 (0)