This repository has been archived by the owner on Dec 10, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
3 changed files
with
110 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
64 changes: 64 additions & 0 deletions
64
packages/superset-ui-encodable/test/encoders/Encoder.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
import createEncoderFactory from '../../src/encoders/createEncoderFactory'; | ||
|
||
describe('Encoder', () => { | ||
const factory = createEncoderFactory<{ | ||
x: ['X', number]; | ||
y: ['Y', number]; | ||
color: ['Color', string]; | ||
shape: ['Category', string]; | ||
tooltip: ['Text', string, 'multiple']; | ||
}>({ | ||
channelTypes: { | ||
x: 'X', | ||
y: 'Y', | ||
color: 'Color', | ||
shape: 'Category', | ||
tooltip: 'Text', | ||
}, | ||
defaultEncoding: { | ||
x: { type: 'quantitative', field: 'speed' }, | ||
y: { type: 'quantitative', field: 'price' }, | ||
color: { type: 'nominal', field: 'brand' }, | ||
shape: { type: 'nominal', field: 'brand' }, | ||
tooltip: [{ field: 'make' }, { field: 'model' }], | ||
}, | ||
}); | ||
|
||
const encoder = factory.create(); | ||
|
||
describe('new Encoder()', () => { | ||
it('creates new encoder', () => { | ||
expect(encoder).toBeDefined(); | ||
}); | ||
}); | ||
describe('.getChannelNames()', () => { | ||
it('returns an array of channel names', () => { | ||
expect(encoder.getChannelNames()).toEqual(['x', 'y', 'color', 'shape', 'tooltip']); | ||
}); | ||
}); | ||
describe('.getChannelEncoders()', () => { | ||
it('returns an array of channel encoders', () => { | ||
expect(encoder.getChannelEncoders()).toHaveLength(5); | ||
}); | ||
}); | ||
describe('.getGroupBys()', () => { | ||
it('returns an array of groupby fields', () => { | ||
expect(encoder.getGroupBys()).toEqual(['brand', 'make', 'model']); | ||
}); | ||
}); | ||
describe('.hasLegend()', () => { | ||
it('returns true if has legend', () => { | ||
expect(encoder.hasLegend()).toBeTruthy(); | ||
}); | ||
it('returns false if does not have legend', () => { | ||
expect( | ||
factory | ||
.create({ | ||
color: { type: 'nominal', field: 'brand', legend: false }, | ||
shape: { value: 'diamond' }, | ||
}) | ||
.hasLegend(), | ||
).toBeFalsy(); | ||
}); | ||
}); | ||
}); |
38 changes: 38 additions & 0 deletions
38
packages/superset-ui-encodable/test/encoders/createEncoderFactory.test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import createEncoderFactory from '../../src/encoders/createEncoderFactory'; | ||
|
||
describe('createEncoderFactory()', () => { | ||
it('supports defaultEncoding as fixed value', () => { | ||
const factory = createEncoderFactory<{ | ||
x: ['X', number]; | ||
}>({ | ||
channelTypes: { | ||
x: 'X', | ||
}, | ||
defaultEncoding: { | ||
x: { type: 'quantitative', field: 'speed' }, | ||
}, | ||
}); | ||
|
||
const encoder = factory.create(); | ||
expect(encoder.encoding).toEqual({ | ||
x: { type: 'quantitative', field: 'speed' }, | ||
}); | ||
}); | ||
it('supports completeEncoding for customization', () => { | ||
const factory = createEncoderFactory<{ | ||
color: ['Color', string]; | ||
}>({ | ||
channelTypes: { | ||
color: 'Color', | ||
}, | ||
completeEncoding: () => ({ | ||
color: { value: 'red' }, | ||
}), | ||
}); | ||
|
||
const encoder = factory.create(); | ||
expect(encoder.encoding).toEqual({ | ||
color: { value: 'red' }, | ||
}); | ||
}); | ||
}); |