2023-09-08 10:51:59 -05:00
|
|
|
import { e2e } from '../index';
|
|
|
|
import { fromBaseUrl } from '../support/url';
|
|
|
|
|
|
|
|
export interface DeleteDataSourceConfig {
|
|
|
|
id: string;
|
|
|
|
name: string;
|
|
|
|
quick?: boolean;
|
|
|
|
}
|
|
|
|
|
|
|
|
export const deleteDataSource = ({ id, name, quick = false }: DeleteDataSourceConfig) => {
|
2023-09-11 05:20:54 -05:00
|
|
|
cy.logToConsole('Deleting data source with name:', name);
|
2023-09-08 10:51:59 -05:00
|
|
|
|
|
|
|
if (quick) {
|
|
|
|
quickDelete(name);
|
|
|
|
} else {
|
|
|
|
uiDelete(name);
|
|
|
|
}
|
|
|
|
|
2023-09-11 05:20:54 -05:00
|
|
|
cy.logToConsole('Deleted data source with name:', name);
|
2023-09-08 10:51:59 -05:00
|
|
|
|
2023-09-22 09:06:49 -05:00
|
|
|
e2e.getScenarioContext().then(({ addedDataSources }) => {
|
2023-09-08 10:51:59 -05:00
|
|
|
e2e.setScenarioContext({
|
|
|
|
addedDataSources: addedDataSources.filter((dataSource: DeleteDataSourceConfig) => {
|
|
|
|
return dataSource.id !== id && dataSource.name !== name;
|
|
|
|
}),
|
|
|
|
});
|
|
|
|
});
|
|
|
|
};
|
|
|
|
|
|
|
|
const quickDelete = (name: string) => {
|
2023-09-11 05:20:54 -05:00
|
|
|
cy.request('DELETE', fromBaseUrl(`/api/datasources/name/${name}`));
|
2023-09-08 10:51:59 -05:00
|
|
|
};
|
|
|
|
|
|
|
|
const uiDelete = (name: string) => {
|
|
|
|
e2e.pages.DataSources.visit();
|
|
|
|
e2e.pages.DataSources.dataSources(name).click();
|
|
|
|
e2e.pages.DataSource.delete().click();
|
|
|
|
e2e.pages.ConfirmModal.delete().click();
|
|
|
|
|
|
|
|
e2e.pages.DataSources.visit();
|
|
|
|
|
|
|
|
// @todo replace `e2e.pages.DataSources.dataSources` with this when argument is empty
|
2023-09-11 05:20:54 -05:00
|
|
|
cy.get('[aria-label^="Data source list item "]').each((item) => cy.wrap(item).should('not.contain', name));
|
2023-09-08 10:51:59 -05:00
|
|
|
};
|