(
{JSON.stringify(location.state)}
)}
/>
>,
{
useRedux: true,
useRouter: true,
},
);
userEvent.click(screen.getByTestId('datasource-menu-trigger'));
expect(queryByTestId('mock-sqllab-route')).not.toBeInTheDocument();
await act(async () => {
userEvent.click(screen.getByText('View in SQL Lab'));
});
expect(getByTestId('mock-sqllab-route')).toBeInTheDocument();
expect(JSON.parse(`${getByTestId('mock-sqllab-route').textContent}`)).toEqual(
{
requestedQuery: {
datasourceKey: `${mockDatasource.id}__${mockDatasource.type}`,
sql: mockDatasource.sql,
},
},
);
});
test('Should open a different menu when datasource=query', async () => {
const props = createProps();
const queryProps = {
...props,
datasource: {
...props.datasource,
type: DatasourceType.Query,
},
};
render(, { useRouter: true });
expect(screen.queryByText('Query preview')).not.toBeInTheDocument();
expect(screen.queryByText('View in SQL Lab')).not.toBeInTheDocument();
expect(screen.queryByText('Save as dataset')).not.toBeInTheDocument();
userEvent.click(screen.getByTestId('datasource-menu-trigger'));
expect(await screen.findByText('Query preview')).toBeInTheDocument();
expect(screen.getByText('View in SQL Lab')).toBeInTheDocument();
expect(screen.getByText('Save as dataset')).toBeInTheDocument();
});
test('Click on Save as dataset', async () => {
const props = createProps();
const queryProps = {
...props,
datasource: {
...props.datasource,
type: DatasourceType.Query,
},
};
render(, {
useRedux: true,
useRouter: true,
});
userEvent.click(screen.getByTestId('datasource-menu-trigger'));
expect(
screen.queryByRole('button', { name: /save/i }),
).not.toBeInTheDocument();
expect(
screen.queryByRole('button', { name: /close/i }),
).not.toBeInTheDocument();
expect(
screen.queryByText(/select or type dataset name/i),
).not.toBeInTheDocument();
userEvent.click(screen.getByText('Save as dataset'));
// Renders a save dataset modal
const saveRadioBtn = await screen.findByRole('radio', {
name: /save as new/i,
});
const overwriteRadioBtn = screen.getByRole('radio', {
name: /overwrite existing/i,
});
const dropdownField = screen.getByText(/select or type dataset name/i);
expect(saveRadioBtn).toBeInTheDocument();
expect(overwriteRadioBtn).toBeInTheDocument();
expect(screen.getByRole('button', { name: /save/i })).toBeInTheDocument();
expect(screen.getByRole('button', { name: /close/i })).toBeInTheDocument();
expect(dropdownField).toBeInTheDocument();
});
test('should set the default temporal column', async () => {
const props = createProps();
const overrideProps = {
...props,
form_data: {
granularity_sqla: 'test-col',
},
datasource: {
...props.datasource,
main_dttm_col: 'test-default',
columns: [
{
column_name: 'test-col',
is_dttm: false,
},
{
column_name: 'test-default',
is_dttm: true,
},
],
},
};
render(, {
useRedux: true,
useRouter: true,
});
await openAndSaveChanges(overrideProps.datasource);
await waitFor(() => {
expect(props.actions.setControlValue).toHaveBeenCalledWith(
'granularity_sqla',
'test-default',
);
});
});
test('should set the first available temporal column', async () => {
const props = createProps();
const overrideProps = {
...props,
form_data: {
granularity_sqla: 'test-col',
},
datasource: {
...props.datasource,
main_dttm_col: null,
columns: [
{
column_name: 'test-col',
is_dttm: false,
},
{
column_name: 'test-first',
is_dttm: true,
},
],
},
};
render(, {
useRedux: true,
useRouter: true,
});
await openAndSaveChanges(overrideProps.datasource);
await waitFor(() => {
expect(props.actions.setControlValue).toHaveBeenCalledWith(
'granularity_sqla',
'test-first',
);
});
});
test('should not set the temporal column', async () => {
const props = createProps();
const overrideProps = {
...props,
form_data: {
granularity_sqla: null,
},
datasource: {
...props.datasource,
main_dttm_col: null,
columns: [
{
column_name: 'test-col',
is_dttm: false,
},
{
column_name: 'test-col-2',
is_dttm: false,
},
],
},
};
render(, {
useRedux: true,
useRouter: true,
});
await openAndSaveChanges(overrideProps.datasource);
await waitFor(() => {
expect(props.actions.setControlValue).toHaveBeenCalledWith(
'granularity_sqla',
null,
);
});
});
test('should show missing params state', () => {
const props = createProps({ datasource: fallbackExploreInitialData.dataset });
render(, { useRedux: true, useRouter: true });
expect(screen.getByText(/missing dataset/i)).toBeVisible();
expect(screen.getByText(/missing url parameters/i)).toBeVisible();
expect(
screen.getByText(
/the url is missing the dataset_id or slice_id parameters/i,
),
).toBeVisible();
});
test('should show missing dataset state', () => {
// @ts-ignore
delete window.location;
// @ts-ignore
window.location = { search: '?slice_id=152' };
const props = createProps({ datasource: fallbackExploreInitialData.dataset });
render(, { useRedux: true, useRouter: true });
expect(screen.getAllByText(/missing dataset/i)).toHaveLength(2);
expect(
screen.getByText(
/the dataset linked to this chart may have been deleted\./i,
),
).toBeVisible();
});