Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,89 @@ describe('DeckMulti Component Rendering', () => {
});
});

it('should include dashboardId in child slice requests when present', async () => {
const props = {
...baseMockProps,
formData: {
...baseMockProps.formData,
dashboardId: 123, // Simulate embedded dashboard context
},
};

renderWithProviders(<DeckMulti {...props} />);

// Wait for child slice requests
await waitFor(() => {
expect(SupersetClient.get).toHaveBeenCalled();
});

// Check that all requests include the dashboardId
const calls = (SupersetClient.get as jest.Mock).mock.calls;
calls.forEach(call => {
const url = call[0].endpoint;
const urlParams = new URLSearchParams(url.split('?')[1]);
const formDataString = urlParams.get('form_data');
const formData = JSON.parse(formDataString || '{}');
expect(formData.dashboardId).toBe(123);
});
});

it('should not include dashboardId when not present', async () => {
const props = {
...baseMockProps,
formData: {
...baseMockProps.formData,
// No dashboardId
},
};

renderWithProviders(<DeckMulti {...props} />);

// Wait for child slice requests
await waitFor(() => {
expect(SupersetClient.get).toHaveBeenCalled();
});

// Check that requests don't include dashboardId
const calls = (SupersetClient.get as jest.Mock).mock.calls;
calls.forEach(call => {
const url = call[0].endpoint;
const formData = JSON.parse(
new URLSearchParams(url.split('?')[1]).get('form_data') || '{}',
);
expect(formData.dashboardId).toBeUndefined();
});
});

it('should preserve dashboardId through filter updates', async () => {
const props = {
...baseMockProps,
formData: {
...baseMockProps.formData,
dashboardId: 456,
extra_filters: [{ col: 'test', op: 'IN' as const, val: ['value'] }],
},
};

renderWithProviders(<DeckMulti {...props} />);

// Wait for child slice requests
await waitFor(() => {
expect(SupersetClient.get).toHaveBeenCalled();
});

// Verify dashboardId is preserved with filters
const calls = (SupersetClient.get as jest.Mock).mock.calls;
calls.forEach(call => {
const url = call[0].endpoint;
const formData = JSON.parse(
new URLSearchParams(url.split('?')[1]).get('form_data') || '{}',
);
expect(formData.dashboardId).toBe(456);
expect(formData.extra_filters).toBeDefined();
});
});

it('should handle viewport changes', async () => {
const { rerender } = renderWithProviders(<DeckMulti {...baseMockProps} />);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,8 @@ const DeckMulti = (props: DeckMultiProps) => {
...subslice.form_data,
extra_filters: extraFilters,
adhoc_filters: adhocFilters,
// Preserve dashboard context for embedded mode permissions
...(formData.dashboardId && { dashboardId: formData.dashboardId }),
},
} as any as JsonObject & { slice_id: number };

Expand Down
Loading