Skip to content

Kepler.gl is a powerful open source geospatial analysis tool for large-scale data sets.

more tests (#3783)

Igor Dykhtabee730e9eaaf
diff --git a/test/browser/components/common/file-uploader-test.js b/test/browser/components/common/file-uploader-test.js
index e1169e6cf..ec3c41848 100644
--- a/test/browser/components/common/file-uploader-test.js
+++ b/test/browser/components/common/file-uploader-test.js
@@ -205,6 +205,19 @@ test('Components -> FileUpload remote URL is staged without downloading', t => {
'should clear the url field after adding it'
);
+ wrapper
+ .find('.file-uploader__remote-url input')
+ .hostNodes()
+ .first()
+ .simulate('change', {target: {value: 'not-a-url'}});
+ wrapper.find('.file-uploader__remote-add').hostNodes().first().simulate('click');
+ t.equal(onAddRemoteDataset.callCount, 1, 'an invalid url is not staged');
+ t.equal(
+ wrapper.find(FileUpload).children().first().state().remoteUrl,
+ 'not-a-url',
+ 'an invalid url stays in the field'
+ );
+
t.end();
});
diff --git a/test/browser/components/modals/load-data-modal-test.js b/test/browser/components/modals/load-data-modal-test.js
index e9e3515b9..d398004d2 100644
--- a/test/browser/components/modals/load-data-modal-test.js
+++ b/test/browser/components/modals/load-data-modal-test.js
@@ -151,3 +151,61 @@ test('Components -> LoadDataModal -> auto create layers', t => {
t.end();
});
+
+test('Components -> LoadDataModal -> one unchecked dataset stays out', t => {
+ const onConfirmAddData = sinon.spy();
+ const points = {info: {label: 'points.csv'}};
+ const remote = {
+ info: {label: 'quakes.csv', format: 'row'},
+ metadata: {source: 'https://example.com/quakes.csv'}
+ };
+ const loading = mountWithTheme(
+ <IntlWrapper>
+ <LoadDataModal
+ onConfirmAddData={onConfirmAddData}
+ fileLoading={true}
+ stagedToAdd={[points, remote]}
+ />
+ </IntlWrapper>
+ );
+ t.equal(
+ loading.find('.add-data-bar button').at(1).props().disabled,
+ true,
+ 'Add Data waits until parsing finishes'
+ );
+
+ const wrapper = mountWithTheme(
+ <IntlWrapper>
+ <LoadDataModal onConfirmAddData={onConfirmAddData} stagedToAdd={[points, remote]} />
+ </IntlWrapper>
+ );
+ const checks = () => wrapper.find('.upload-file-list').find('Checkbox');
+ t.equal(checks().length, 2, 'local and remote datasets can each be included');
+ t.equal(
+ wrapper.find('.add-data-bar button').at(1).props().disabled,
+ false,
+ 'Add Data is enabled when a dataset is checked'
+ );
+
+ checks().at(1).simulate('change');
+ wrapper.find('.add-data-bar button').at(1).simulate('click');
+ t.deepEqual(
+ onConfirmAddData.args[0][0],
+ {autoCreateLayers: true, datasets: [points]},
+ 'Add Data commits only the checked dataset'
+ );
+
+ const tabs = wrapper.find('.load-data-modal__tab__item');
+ let clickedStorage = false;
+ for (let i = 0; i < tabs.length; i++) {
+ if (tabs.at(i).text() === 'Load from Storage') {
+ tabs.at(i).simulate('click');
+ clickedStorage = true;
+ break;
+ }
+ }
+ t.equal(clickedStorage, true, 'should find the storage tab');
+ t.equal(wrapper.find('.add-data-bar').length, 0, 'storage keeps its own load action');
+
+ t.end();
+});
diff --git a/test/node/reducers/composer-state-test.js b/test/node/reducers/composer-state-test.js
index b3897e096..6295137b6 100644
--- a/test/node/reducers/composer-state-test.js
+++ b/test/node/reducers/composer-state-test.js
@@ -6,7 +6,12 @@
import {drainTasksForTesting, succeedTaskWithValues} from '@kepler.gl/tasks';
import test from 'tape';
-import {appendStagedLoadedFiles, registerEntry, stageLoadedFiles} from '@kepler.gl/actions';
+import {
+ appendStagedLoadedFiles,
+ loadFilesSuccess,
+ registerEntry,
+ stageLoadedFiles
+} from '@kepler.gl/actions';
import {processCsvData} from '@kepler.gl/processors';
import keplerGlReducer, {
addDataToMapUpdater,
@@ -1279,5 +1284,35 @@ test('#composerStateReducer -> stageLoadedFilesUpdater keeps the modal open', t
);
t.equal(duplicate, withRemote, 'should ignore a url that is already staged');
+ const closedModal = {
+ ...withRemote,
+ uiState: {...withRemote.uiState, currentModal: null}
+ };
+ const afterClose = combinedUpdaters.appendStagedLoadedFilesUpdater(
+ closedModal,
+ appendStagedLoadedFiles([
+ {
+ ...remote,
+ info: {...remote.info, id: 'remote-2', label: 'cities.csv'},
+ metadata: {source: 'https://example.com/cities.csv'}
+ }
+ ])
+ );
+ t.equal(afterClose, closedModal, 'a remote url is not staged after the modal closes');
+
+ const activeLoad = {
+ ...loadingState,
+ visState: {
+ ...loadingState.visState,
+ fileLoading: {...loadingState.visState.fileLoading, loadId: 2},
+ stagedToAdd: [{info: {label: 'fresh.csv'}}]
+ }
+ };
+ const staleAdd = combinedUpdaters.loadFilesSuccessUpdater(activeLoad, {
+ ...loadFilesSuccess([{info: {label: 'old.csv', format: 'csv'}, data: {fields: [], rows: []}}]),
+ loadId: 1
+ });
+ t.equal(staleAdd, activeLoad, 'a stale add does not replace the current load');
+
t.end();
});
diff --git a/test/node/reducers/vis-state-test.js b/test/node/reducers/vis-state-test.js
index 3af03dee8..3ac07c3ca 100644
--- a/test/node/reducers/vis-state-test.js
+++ b/test/node/reducers/vis-state-test.js
@@ -7252,6 +7252,72 @@ test('#visStateReducer -> local dataset is not blocked by a remote download', t
);
});
+test('#visStateReducer -> deferred empty queue stages the parsed files', t => {
+ drainTasksForTesting();
+ const onFinish = sinon.spy(VisStateActions.stageLoadedFiles);
+ const initialState = CloneDeep(InitialState).visState;
+ const loading = reducer(
+ initialState,
+ VisStateActions.loadFiles([{type: 'text/csv', name: 'points.csv'}], onFinish, {
+ deferAddToMap: true
+ })
+ );
+ drainTasksForTesting();
+ const cache = [{info: {label: 'points.csv', format: 'csv'}, data: []}];
+ const ready = {
+ ...loading,
+ fileLoading: {
+ ...loading.fileLoading,
+ filesToLoad: [],
+ fileCache: cache
+ }
+ };
+ reducer(ready, VisStateActions.loadNextFile());
+ const [task, ...rest] = drainTasksForTesting();
+ t.equal(rest.length, 0, 'should create 1 task');
+ t.equal(task.type, 'ACTION_TASK', 'an empty deferred queue finishes the load');
+ const action = succeedTaskInTest(task);
+ t.equal(onFinish.calledOnce, true, 'should stage the parsed files');
+ t.deepEqual(onFinish.lastCall.args[0], cache, 'should stage the parsed cache');
+ t.deepEqual(
+ onFinish.lastCall.args[1],
+ {deferAddToMap: true},
+ 'should keep the deferred load options'
+ );
+ t.equal(action.loadId, ready.fileLoading.loadId, 'the finish belongs to this load');
+ t.end();
+});
+
+test('#visStateReducer -> deferred arrow batches are not added early', t => {
+ drainTasksForTesting();
+ const batch = {
+ gen: {next: () => Promise.resolve({done: true, value: null})},
+ fileName: 'data.arrow',
+ progress: {percent: 0.4},
+ accumulated: {data: [{value: 1}], fileName: 'data.arrow'},
+ onFinish: VisStateActions.stageLoadedFiles
+ };
+ reducer(
+ CloneDeep(InitialState).visState,
+ VisStateActions.nextFileBatch({...batch, options: {deferAddToMap: true}})
+ );
+ const deferredTasks = drainTasksForTesting();
+ t.equal(
+ deferredTasks.some(task => task.type === 'PROCESS_FILE_CONTENT'),
+ false,
+ 'a deferred arrow file waits until parsing finishes'
+ );
+
+ reducer(CloneDeep(InitialState).visState, VisStateActions.nextFileBatch(batch));
+ const immediateTasks = drainTasksForTesting();
+ t.equal(
+ immediateTasks.some(task => task.type === 'PROCESS_FILE_CONTENT'),
+ true,
+ 'an arrow file still adds each batch when it is not deferred'
+ );
+ t.end();
+});
+
test('#visStateReducer -> setLayerAnimationTimeConfig', t => {
// change Trip layer isVisible
const nextState = reducer(