Files
superset2/superset/assets/spec/javascripts/explore/utils_spec.jsx
Alanna Scott 90e4d6469d [js-testing] more tests for SelectControl (#2877)
* rename spec folder

* remove special handling for viz_type control since it now uses VizTypeControl

* add test for getOptions

* linting

* add test for cwp

* linting
2017-05-31 10:52:02 -07:00

60 lines
2.0 KiB
JavaScript

import { it, describe } from 'mocha';
import { expect } from 'chai';
import URI from 'urijs';
import { getExploreUrl } from '../../../javascripts/explore/exploreUtils';
describe('utils', () => {
const formData = {
datasource: '1__table',
};
const sFormData = JSON.stringify(formData);
function compareURI(uri1, uri2) {
expect(uri1.toString()).to.equal(uri2.toString());
}
it('getExploreUrl generates proper base url', () => {
// This assertion is to show clearly the value of location.href
// in the context of unit tests.
expect(location.href).to.equal('about:blank');
compareURI(
URI(getExploreUrl(formData, 'base', false, 'http://superset.com')),
URI('/superset/explore/table/1/').search({ form_data: sFormData }),
);
});
it('getExploreUrl generates proper json url', () => {
compareURI(
URI(getExploreUrl(formData, 'json', false, 'superset.com')),
URI('/superset/explore_json/table/1/').search({ form_data: sFormData }),
);
});
it('getExploreUrl generates proper json forced url', () => {
compareURI(
URI(getExploreUrl(formData, 'json', true, 'superset.com')),
URI('/superset/explore_json/table/1/')
.search({ form_data: sFormData, force: 'true' }),
);
});
it('getExploreUrl generates proper csv URL', () => {
compareURI(
URI(getExploreUrl(formData, 'csv', false, 'superset.com')),
URI('/superset/explore_json/table/1/')
.search({ form_data: sFormData, csv: 'true' }),
);
});
it('getExploreUrl generates proper standalone URL', () => {
compareURI(
URI(getExploreUrl(formData, 'standalone', false, 'superset.com')),
URI('/superset/explore/table/1/')
.search({ form_data: sFormData, standalone: 'true' }),
);
});
it('getExploreUrl preserves main URLs params', () => {
compareURI(
URI(getExploreUrl(formData, 'json', false, 'superset.com?foo=bar')),
URI('/superset/explore_json/table/1/')
.search({ foo: 'bar', form_data: sFormData }),
);
});
});