mirror of
https://github.com/apache/superset.git
synced 2026-04-22 09:35:23 +00:00
test(frontend): Migrate from describe/it to flat test() pattern (#35305)
Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
@@ -23,7 +23,9 @@ import { table, initialState as mockState } from '../fixtures';
|
||||
|
||||
const initialState = mockState.sqlLab;
|
||||
|
||||
// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
|
||||
describe('sqlLabReducer', () => {
|
||||
// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
|
||||
describe('Query editors actions', () => {
|
||||
let newState;
|
||||
let defaultQueryEditor;
|
||||
@@ -38,12 +40,12 @@ describe('sqlLabReducer', () => {
|
||||
newState = sqlLabReducer(newState, action);
|
||||
qe = newState.queryEditors.find(e => e.id === 'abcd');
|
||||
});
|
||||
it('should add a query editor', () => {
|
||||
test('should add a query editor', () => {
|
||||
expect(newState.queryEditors).toHaveLength(
|
||||
initialState.queryEditors.length + 1,
|
||||
);
|
||||
});
|
||||
it('should merge the current unsaved changes when adding a query editor', () => {
|
||||
test('should merge the current unsaved changes when adding a query editor', () => {
|
||||
const expectedTitle = 'new updated title';
|
||||
const updateAction = {
|
||||
type: actions.QUERY_EDITOR_SET_TITLE,
|
||||
@@ -62,7 +64,7 @@ describe('sqlLabReducer', () => {
|
||||
newState.queryEditors[newState.queryEditors.length - 1].id,
|
||||
).toEqual('efgh');
|
||||
});
|
||||
it('should remove a query editor', () => {
|
||||
test('should remove a query editor', () => {
|
||||
expect(newState.queryEditors).toHaveLength(
|
||||
initialState.queryEditors.length + 1,
|
||||
);
|
||||
@@ -75,7 +77,7 @@ describe('sqlLabReducer', () => {
|
||||
initialState.queryEditors.length,
|
||||
);
|
||||
});
|
||||
it('should select the latest query editor when tabHistory is empty', () => {
|
||||
test('should select the latest query editor when tabHistory is empty', () => {
|
||||
const currentQE = newState.queryEditors[0];
|
||||
newState = {
|
||||
...initialState,
|
||||
@@ -94,7 +96,7 @@ describe('sqlLabReducer', () => {
|
||||
);
|
||||
expect(newState.tabHistory).toEqual([initialState.queryEditors[2].id]);
|
||||
});
|
||||
it('should remove a query editor including unsaved changes', () => {
|
||||
test('should remove a query editor including unsaved changes', () => {
|
||||
expect(newState.queryEditors).toHaveLength(
|
||||
initialState.queryEditors.length + 1,
|
||||
);
|
||||
@@ -116,7 +118,7 @@ describe('sqlLabReducer', () => {
|
||||
expect(newState.unsavedQueryEditor.dbId).toBeUndefined();
|
||||
expect(newState.unsavedQueryEditor.id).toBeUndefined();
|
||||
});
|
||||
it('should set q query editor active', () => {
|
||||
test('should set q query editor active', () => {
|
||||
const expectedTitle = 'new updated title';
|
||||
const addQueryEditorAction = {
|
||||
type: actions.ADD_QUERY_EDITOR,
|
||||
@@ -139,7 +141,7 @@ describe('sqlLabReducer', () => {
|
||||
);
|
||||
expect(newState.queryEditors[1].name).toEqual(expectedTitle);
|
||||
});
|
||||
it('should not fail while setting DB', () => {
|
||||
test('should not fail while setting DB', () => {
|
||||
const dbId = 9;
|
||||
const action = {
|
||||
type: actions.QUERY_EDITOR_SETDB,
|
||||
@@ -150,7 +152,7 @@ describe('sqlLabReducer', () => {
|
||||
expect(newState.unsavedQueryEditor.dbId).toBe(dbId);
|
||||
expect(newState.unsavedQueryEditor.id).toBe(qe.id);
|
||||
});
|
||||
it('should not fail while setting schema', () => {
|
||||
test('should not fail while setting schema', () => {
|
||||
const schema = 'foo';
|
||||
const action = {
|
||||
type: actions.QUERY_EDITOR_SET_SCHEMA,
|
||||
@@ -161,7 +163,7 @@ describe('sqlLabReducer', () => {
|
||||
expect(newState.unsavedQueryEditor.schema).toBe(schema);
|
||||
expect(newState.unsavedQueryEditor.id).toBe(qe.id);
|
||||
});
|
||||
it('should not fail while setting autorun', () => {
|
||||
test('should not fail while setting autorun', () => {
|
||||
const action = {
|
||||
type: actions.QUERY_EDITOR_SET_AUTORUN,
|
||||
queryEditor: qe,
|
||||
@@ -173,7 +175,7 @@ describe('sqlLabReducer', () => {
|
||||
expect(newState.unsavedQueryEditor.autorun).toBe(true);
|
||||
expect(newState.unsavedQueryEditor.id).toBe(qe.id);
|
||||
});
|
||||
it('should not fail while setting title', () => {
|
||||
test('should not fail while setting title', () => {
|
||||
const title = 'Untitled Query 1';
|
||||
const action = {
|
||||
type: actions.QUERY_EDITOR_SET_TITLE,
|
||||
@@ -184,7 +186,7 @@ describe('sqlLabReducer', () => {
|
||||
expect(newState.unsavedQueryEditor.name).toBe(title);
|
||||
expect(newState.unsavedQueryEditor.id).toBe(qe.id);
|
||||
});
|
||||
it('should not fail while setting Sql', () => {
|
||||
test('should not fail while setting Sql', () => {
|
||||
const sql = 'SELECT nothing from dev_null';
|
||||
const action = {
|
||||
type: actions.QUERY_EDITOR_SET_SQL,
|
||||
@@ -195,7 +197,7 @@ describe('sqlLabReducer', () => {
|
||||
expect(newState.unsavedQueryEditor.sql).toBe(sql);
|
||||
expect(newState.unsavedQueryEditor.id).toBe(qe.id);
|
||||
});
|
||||
it('should not fail while setting queryLimit', () => {
|
||||
test('should not fail while setting queryLimit', () => {
|
||||
const queryLimit = 101;
|
||||
const action = {
|
||||
type: actions.QUERY_EDITOR_SET_QUERY_LIMIT,
|
||||
@@ -206,7 +208,7 @@ describe('sqlLabReducer', () => {
|
||||
expect(newState.unsavedQueryEditor.queryLimit).toBe(queryLimit);
|
||||
expect(newState.unsavedQueryEditor.id).toBe(qe.id);
|
||||
});
|
||||
it('should set selectedText', () => {
|
||||
test('should set selectedText', () => {
|
||||
const selectedText = 'TEST';
|
||||
const action = {
|
||||
type: actions.QUERY_EDITOR_SET_SELECTED_TEXT,
|
||||
@@ -218,7 +220,7 @@ describe('sqlLabReducer', () => {
|
||||
expect(newState.unsavedQueryEditor.selectedText).toBe(selectedText);
|
||||
expect(newState.unsavedQueryEditor.id).toBe(qe.id);
|
||||
});
|
||||
it('should not wiped out unsaved changes while delayed async call intercepted', () => {
|
||||
test('should not wiped out unsaved changes while delayed async call intercepted', () => {
|
||||
const expectedSql = 'Updated SQL WORKING IN PROGRESS--';
|
||||
const action = {
|
||||
type: actions.QUERY_EDITOR_SET_SQL,
|
||||
@@ -239,7 +241,7 @@ describe('sqlLabReducer', () => {
|
||||
interceptedAction.northPercent,
|
||||
);
|
||||
});
|
||||
it('should migrate query editor by new query editor id', () => {
|
||||
test('should migrate query editor by new query editor id', () => {
|
||||
const { length } = newState.queryEditors;
|
||||
const index = newState.queryEditors.findIndex(({ id }) => id === qe.id);
|
||||
const newQueryEditor = {
|
||||
@@ -267,7 +269,7 @@ describe('sqlLabReducer', () => {
|
||||
newQueryEditor.tabViewId,
|
||||
);
|
||||
});
|
||||
it('should clear the destroyed query editors', () => {
|
||||
test('should clear the destroyed query editors', () => {
|
||||
const expectedQEId = '1233289';
|
||||
const action = {
|
||||
type: actions.CLEAR_DESTROYED_QUERY_EDITOR,
|
||||
@@ -285,6 +287,7 @@ describe('sqlLabReducer', () => {
|
||||
expect(newState.destroyedQueryEditors).toEqual({});
|
||||
});
|
||||
});
|
||||
// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
|
||||
describe('Tables', () => {
|
||||
let newState;
|
||||
let newTable;
|
||||
@@ -297,12 +300,12 @@ describe('sqlLabReducer', () => {
|
||||
newState = sqlLabReducer(initialState, action);
|
||||
newTable = newState.tables[0];
|
||||
});
|
||||
it('should add a table', () => {
|
||||
test('should add a table', () => {
|
||||
// Testing that beforeEach actually added the table
|
||||
expect(newState.tables).toHaveLength(1);
|
||||
expect(newState.tables[0].expanded).toBe(true);
|
||||
});
|
||||
it('should merge the table attributes', () => {
|
||||
test('should merge the table attributes', () => {
|
||||
// Merging the extra attribute
|
||||
newTable.extra = true;
|
||||
const action = {
|
||||
@@ -313,7 +316,7 @@ describe('sqlLabReducer', () => {
|
||||
expect(newState.tables).toHaveLength(1);
|
||||
expect(newState.tables[0].extra).toBe(true);
|
||||
});
|
||||
it('should overwrite table ID be ignored when the existing table is already initialized', () => {
|
||||
test('should overwrite table ID be ignored when the existing table is already initialized', () => {
|
||||
const action = {
|
||||
type: actions.MERGE_TABLE,
|
||||
table: newTable,
|
||||
@@ -345,7 +348,7 @@ describe('sqlLabReducer', () => {
|
||||
expect(newState.tables).toHaveLength(1);
|
||||
expect(newState.tables[0].id).toBe(remoteId);
|
||||
});
|
||||
it('should expand and collapse a table', () => {
|
||||
test('should expand and collapse a table', () => {
|
||||
const collapseTableAction = {
|
||||
type: actions.COLLAPSE_TABLE,
|
||||
table: newTable,
|
||||
@@ -359,7 +362,7 @@ describe('sqlLabReducer', () => {
|
||||
newState = sqlLabReducer(newState, expandTableAction);
|
||||
expect(newState.tables[0].expanded).toBe(true);
|
||||
});
|
||||
it('should remove a table', () => {
|
||||
test('should remove a table', () => {
|
||||
const action = {
|
||||
type: actions.REMOVE_TABLES,
|
||||
tables: [newTable],
|
||||
@@ -368,6 +371,7 @@ describe('sqlLabReducer', () => {
|
||||
expect(newState.tables).toHaveLength(0);
|
||||
});
|
||||
});
|
||||
// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
|
||||
describe('Run Query', () => {
|
||||
const DENORMALIZED_CHANGED_ON = '2023-06-26T07:53:05.439';
|
||||
const CHANGED_ON_TIMESTAMP = 1687765985439;
|
||||
@@ -385,7 +389,7 @@ describe('sqlLabReducer', () => {
|
||||
sqlEditorId: 'dfsadfs',
|
||||
};
|
||||
});
|
||||
it('should start a query', () => {
|
||||
test('should start a query', () => {
|
||||
const action = {
|
||||
type: actions.START_QUERY,
|
||||
query: {
|
||||
@@ -401,7 +405,7 @@ describe('sqlLabReducer', () => {
|
||||
newState = sqlLabReducer(newState, action);
|
||||
expect(Object.keys(newState.queries)).toHaveLength(1);
|
||||
});
|
||||
it('should stop the query', () => {
|
||||
test('should stop the query', () => {
|
||||
const startQueryAction = {
|
||||
type: actions.START_QUERY,
|
||||
query,
|
||||
@@ -415,7 +419,7 @@ describe('sqlLabReducer', () => {
|
||||
const q = newState.queries[Object.keys(newState.queries)[0]];
|
||||
expect(q.state).toBe('stopped');
|
||||
});
|
||||
it('should remove a query', () => {
|
||||
test('should remove a query', () => {
|
||||
const startQueryAction = {
|
||||
type: actions.START_QUERY,
|
||||
query,
|
||||
@@ -428,7 +432,7 @@ describe('sqlLabReducer', () => {
|
||||
newState = sqlLabReducer(newState, removeQueryAction);
|
||||
expect(Object.keys(newState.queries)).toHaveLength(0);
|
||||
});
|
||||
it('should refresh queries when polling returns new results', () => {
|
||||
test('should refresh queries when polling returns new results', () => {
|
||||
const startDttmInStr = '1693433503447.166992';
|
||||
const endDttmInStr = '1693433503500.23132';
|
||||
newState = sqlLabReducer(
|
||||
@@ -449,7 +453,7 @@ describe('sqlLabReducer', () => {
|
||||
expect(newState.queries.abcd.endDttm).toBe(Number(endDttmInStr));
|
||||
expect(newState.queriesLastUpdate).toBe(CHANGED_ON_TIMESTAMP);
|
||||
});
|
||||
it('should skip refreshing queries when polling contains existing results', () => {
|
||||
test('should skip refreshing queries when polling contains existing results', () => {
|
||||
const completedQuery = {
|
||||
...query,
|
||||
extra: {
|
||||
@@ -478,10 +482,11 @@ describe('sqlLabReducer', () => {
|
||||
expect(newState.queries.abcd).toBe(query);
|
||||
expect(newState.queries.def).toBe(completedQuery);
|
||||
});
|
||||
it('should refresh queries when polling returns empty', () => {
|
||||
test('should refresh queries when polling returns empty', () => {
|
||||
newState = sqlLabReducer(newState, actions.refreshQueries({}));
|
||||
});
|
||||
});
|
||||
// eslint-disable-next-line no-restricted-globals -- TODO: Migrate from describe blocks
|
||||
describe('CLEAR_INACTIVE_QUERIES', () => {
|
||||
let newState;
|
||||
let query;
|
||||
@@ -496,7 +501,7 @@ describe('sqlLabReducer', () => {
|
||||
cached: false,
|
||||
};
|
||||
});
|
||||
it('updates queries that have already been completed', () => {
|
||||
test('updates queries that have already been completed', () => {
|
||||
newState = sqlLabReducer(
|
||||
{
|
||||
...newState,
|
||||
|
||||
Reference in New Issue
Block a user