Skip to content

Commit 3c480e3

Browse files
committed
Renamed the test, improve coverage.
1 parent 76fe75c commit 3c480e3

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

src/constraint/encoding.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {Channel} from 'vega-lite/build/src/channel';
22
import {channelCompatibility} from 'vega-lite/build/src/fielddef';
33
import {ScaleType, scaleTypeSupportProperty, hasDiscreteDomain, channelScalePropertyIncompatability, Scale} from 'vega-lite/build/src/scale';
44
import {Type} from 'vega-lite/build/src/type';
5-
import {SortField} from 'vega-lite/build/src/sort';
5+
import {SortField, isSortField} from 'vega-lite/build/src/sort';
66
import {AbstractConstraint, AbstractConstraintModel} from './base';
77

88
import {QueryConfig} from '../config';
@@ -376,13 +376,13 @@ export const FIELD_CONSTRAINTS: EncodingConstraintModel<FieldQuery>[] = [
376376
return true;
377377
}
378378
},{
379-
name: 'onlyCountWithAsteriskFieldOnSort',
379+
name: 'onlyUseCountWithAsteriskSortField',
380380
description: 'Sort by * if and only if op is count',
381381
properties: [Property.SORT, getEncodingNestedProp('sort', 'field'), getEncodingNestedProp('sort', 'op')],
382382
allowWildcardForProperties: false,
383383
strict: true,
384384
satisfy: (fieldQ: FieldQuery, _: Schema, __: PropIndex<Wildcard<any>>, ___: QueryConfig) => {
385-
if (fieldQ.sort && !!(fieldQ.sort as SortField).field) {
385+
if (fieldQ.sort && isSortField(fieldQ.sort)) {
386386
return ((fieldQ.sort as SortField).field === '*') === ((fieldQ.sort as SortField).op === 'count');
387387
}
388388
return true;

test/constraint/encoding.test.ts

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -492,20 +492,22 @@ describe('constraints/encoding', () => {
492492
});
493493
});
494494

495-
describe('onlyCountWithAutoCountFieldOnSort', () => {
495+
describe('onlyUseCountWithAsteriskSortField', () => {
496496
it('should allow sort with * if and only if count is op', () => {
497+
const encQ: EncodingQuery = {channel: Channel.X, field: 'O', type: Type.ORDINAL};
498+
assert.isTrue(FIELD_CONSTRAINT_INDEX['onlyUseCountWithAsteriskSortField'].satisfy(encQ, schema, new PropIndex<Wildcard<any>>(), defaultOpt));
497499

498-
const encQ: EncodingQuery = {channel: Channel.X, field: 'O', sort: {field: '*', op: 'count', order: 'ascending'}, type: Type.ORDINAL};
499-
assert.isTrue(FIELD_CONSTRAINT_INDEX['onlyCountWithAutoCountFieldOnSort'].satisfy(encQ, schema, new PropIndex<Wildcard<any>>(), defaultOpt));
500+
const encQ1: EncodingQuery = {channel: Channel.X, field: 'O', sort: {field: '*', op: 'count', order: 'ascending'}, type: Type.ORDINAL};
501+
assert.isTrue(FIELD_CONSTRAINT_INDEX['onlyUseCountWithAsteriskSortField'].satisfy(encQ1, schema, new PropIndex<Wildcard<any>>(), defaultOpt));
500502

501503
const encQ2: EncodingQuery = {channel: Channel.X, field: 'O', sort: {field: '*', op: 'mean', order: 'ascending'}, type: Type.ORDINAL};
502-
assert.isFalse(FIELD_CONSTRAINT_INDEX['onlyCountWithAutoCountFieldOnSort'].satisfy(encQ2, schema, new PropIndex<Wildcard<any>>(), defaultOpt));
504+
assert.isFalse(FIELD_CONSTRAINT_INDEX['onlyUseCountWithAsteriskSortField'].satisfy(encQ2, schema, new PropIndex<Wildcard<any>>(), defaultOpt));
503505

504506
const encQ3: EncodingQuery = {channel: Channel.X, field: 'O', sort: {field: 'A', op: 'count', order: 'ascending'}, type: Type.ORDINAL};
505-
assert.isFalse(FIELD_CONSTRAINT_INDEX['onlyCountWithAutoCountFieldOnSort'].satisfy(encQ3, schema, new PropIndex<Wildcard<any>>(), defaultOpt));
507+
assert.isFalse(FIELD_CONSTRAINT_INDEX['onlyUseCountWithAsteriskSortField'].satisfy(encQ3, schema, new PropIndex<Wildcard<any>>(), defaultOpt));
506508

507509
const encQ4: EncodingQuery = {channel: Channel.X, field: 'O', sort: {field: 'A', op: 'mean', order: 'ascending'}, type: Type.ORDINAL};
508-
assert.isTrue(FIELD_CONSTRAINT_INDEX['onlyCountWithAutoCountFieldOnSort'].satisfy(encQ4, schema, new PropIndex<Wildcard<any>>(), defaultOpt));
510+
assert.isTrue(FIELD_CONSTRAINT_INDEX['onlyUseCountWithAsteriskSortField'].satisfy(encQ4, schema, new PropIndex<Wildcard<any>>(), defaultOpt));
509511

510512

511513
});

test/wildcard.test.ts

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import {Mark} from 'vega-lite/build/src/mark';
22

33
import {assert} from 'chai';
44
import {initWildcard, isWildcard, SHORT_WILDCARD, getDefaultName, getDefaultEnumValues} from '../src/wildcard';
5-
import {DEFAULT_PROP_PRECEDENCE, toKey} from '../src/property';
5+
import {DEFAULT_PROP_PRECEDENCE, toKey, isEncodingNestedProp} from '../src/property';
66
import {DEFAULT_QUERY_CONFIG} from '../src/config';
77

88
describe('wildcard', () => {
@@ -114,8 +114,12 @@ describe('wildcard', () => {
114114
if (e === undefined) {
115115
missing.push(toKey(prop));
116116
}
117+
if ((isEncodingNestedProp(prop) && prop.parent === 'sort' && prop.child === 'field')){
118+
assert.deepEqual(e, ['a', 'b', '*']);
119+
}
117120
}
118121
assert.equal(missing.length, 0, 'Properties with missing enum: ' + missing.join(','));
119122
});
120123
});
121124
});
125+

0 commit comments

Comments
 (0)