2020-12-02 01:20:00 -05:00
|
|
|
/**
|
|
|
|
* Licensed to the Apache Software Foundation (ASF) under one
|
|
|
|
* or more contributor license agreements. See the NOTICE file
|
|
|
|
* distributed with this work for additional information
|
|
|
|
* regarding copyright ownership. The ASF licenses this file
|
|
|
|
* to you under the Apache License, Version 2.0 (the
|
|
|
|
* "License"); you may not use this file except in compliance
|
|
|
|
* with the License. You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing,
|
|
|
|
* software distributed under the License is distributed on an
|
|
|
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
|
|
|
* KIND, either express or implied. See the License for the
|
|
|
|
* specific language governing permissions and limitations
|
|
|
|
* under the License.
|
|
|
|
*/
|
2022-01-07 20:16:24 -05:00
|
|
|
import { overrideExtraFormData } from '../../src/query/processExtraFormData';
|
2020-12-02 01:20:00 -05:00
|
|
|
|
2021-03-08 14:28:43 -05:00
|
|
|
describe('overrideExtraFormData', () => {
|
|
|
|
it('should assign allowed non-existent value', () => {
|
2020-12-02 01:20:00 -05:00
|
|
|
expect(
|
2021-03-08 14:28:43 -05:00
|
|
|
overrideExtraFormData(
|
2020-12-02 01:20:00 -05:00
|
|
|
{
|
|
|
|
granularity: 'something',
|
|
|
|
viz_type: 'custom',
|
|
|
|
datasource: 'table_1',
|
|
|
|
},
|
|
|
|
{
|
2021-03-08 14:28:43 -05:00
|
|
|
time_range: '100 years ago',
|
2020-12-02 01:20:00 -05:00
|
|
|
},
|
|
|
|
),
|
|
|
|
).toEqual({
|
|
|
|
granularity: 'something',
|
|
|
|
viz_type: 'custom',
|
|
|
|
datasource: 'table_1',
|
2021-03-08 14:28:43 -05:00
|
|
|
time_range: '100 years ago',
|
2020-12-02 01:20:00 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-03-08 14:28:43 -05:00
|
|
|
it('should override allowed preexisting value', () => {
|
2020-12-02 01:20:00 -05:00
|
|
|
expect(
|
2021-03-08 14:28:43 -05:00
|
|
|
overrideExtraFormData(
|
2020-12-02 01:20:00 -05:00
|
|
|
{
|
|
|
|
granularity: 'something',
|
|
|
|
viz_type: 'custom',
|
|
|
|
datasource: 'table_1',
|
2021-03-08 14:28:43 -05:00
|
|
|
time_range: '100 years ago',
|
2020-12-02 01:20:00 -05:00
|
|
|
},
|
|
|
|
{
|
2021-03-08 14:28:43 -05:00
|
|
|
time_range: '50 years ago',
|
2020-12-02 01:20:00 -05:00
|
|
|
},
|
|
|
|
),
|
|
|
|
).toEqual({
|
|
|
|
granularity: 'something',
|
|
|
|
viz_type: 'custom',
|
2021-01-05 09:49:16 -05:00
|
|
|
datasource: 'table_1',
|
2021-03-08 14:28:43 -05:00
|
|
|
time_range: '50 years ago',
|
2021-01-05 09:49:16 -05:00
|
|
|
});
|
|
|
|
});
|
2020-12-02 01:20:00 -05:00
|
|
|
|
2021-03-08 14:28:43 -05:00
|
|
|
it('should not override non-allowed value', () => {
|
2020-12-02 01:20:00 -05:00
|
|
|
expect(
|
|
|
|
overrideExtraFormData(
|
|
|
|
{
|
|
|
|
granularity: 'something',
|
|
|
|
viz_type: 'custom',
|
|
|
|
datasource: 'table_1',
|
2021-03-08 14:28:43 -05:00
|
|
|
time_range: '100 years ago',
|
2020-12-02 01:20:00 -05:00
|
|
|
},
|
|
|
|
{
|
2021-04-14 07:30:43 -04:00
|
|
|
// @ts-expect-error
|
2021-03-08 14:28:43 -05:00
|
|
|
viz_type: 'other custom viz',
|
2020-12-02 01:20:00 -05:00
|
|
|
},
|
|
|
|
),
|
|
|
|
).toEqual({
|
|
|
|
granularity: 'something',
|
|
|
|
viz_type: 'custom',
|
|
|
|
datasource: 'table_1',
|
2021-03-08 14:28:43 -05:00
|
|
|
time_range: '100 years ago',
|
2020-12-02 01:20:00 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-03-08 14:28:43 -05:00
|
|
|
it('should override pre-existing extra value', () => {
|
2020-12-02 01:20:00 -05:00
|
|
|
expect(
|
|
|
|
overrideExtraFormData(
|
|
|
|
{
|
|
|
|
granularity: 'something',
|
|
|
|
viz_type: 'custom',
|
|
|
|
datasource: 'table_1',
|
2021-03-08 14:28:43 -05:00
|
|
|
time_range: '100 years ago',
|
|
|
|
extras: {
|
|
|
|
time_grain_sqla: 'PT1H',
|
|
|
|
},
|
2020-12-02 01:20:00 -05:00
|
|
|
},
|
2022-03-23 06:57:35 -04:00
|
|
|
{ time_grain_sqla: 'P1D' },
|
2020-12-02 01:20:00 -05:00
|
|
|
),
|
|
|
|
).toEqual({
|
|
|
|
granularity: 'something',
|
|
|
|
viz_type: 'custom',
|
|
|
|
datasource: 'table_1',
|
2021-03-08 14:28:43 -05:00
|
|
|
time_range: '100 years ago',
|
|
|
|
extras: {
|
2022-03-23 06:57:35 -04:00
|
|
|
time_grain_sqla: 'P1D',
|
2021-03-08 14:28:43 -05:00
|
|
|
},
|
2020-12-02 01:20:00 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
|
2021-03-08 14:28:43 -05:00
|
|
|
it('should add extra override value', () => {
|
2020-12-02 01:20:00 -05:00
|
|
|
expect(
|
|
|
|
overrideExtraFormData(
|
|
|
|
{
|
|
|
|
granularity: 'something',
|
|
|
|
viz_type: 'custom',
|
|
|
|
datasource: 'table_1',
|
2021-03-08 14:28:43 -05:00
|
|
|
time_range: '100 years ago',
|
2020-12-02 01:20:00 -05:00
|
|
|
},
|
|
|
|
{
|
2021-04-14 07:30:43 -04:00
|
|
|
time_grain_sqla: 'PT1H',
|
2020-12-02 01:20:00 -05:00
|
|
|
},
|
|
|
|
),
|
|
|
|
).toEqual({
|
|
|
|
granularity: 'something',
|
|
|
|
viz_type: 'custom',
|
|
|
|
datasource: 'table_1',
|
2021-03-08 14:28:43 -05:00
|
|
|
time_range: '100 years ago',
|
|
|
|
extras: {
|
|
|
|
time_grain_sqla: 'PT1H',
|
|
|
|
},
|
2020-12-02 01:20:00 -05:00
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|