From 70e0e7ed75a63f7442f8f276fd786c1648e1d36c Mon Sep 17 00:00:00 2001 From: Cameron Yick Date: Wed, 31 Jul 2024 14:59:02 -0400 Subject: [PATCH] testing(legend): add unit test for preserving the gradientLength property at compile time --- test/compile/legend/parse.test.ts | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) diff --git a/test/compile/legend/parse.test.ts b/test/compile/legend/parse.test.ts index 8ccc9cb7d3..02e4b0b801 100644 --- a/test/compile/legend/parse.test.ts +++ b/test/compile/legend/parse.test.ts @@ -153,6 +153,34 @@ describe('compile/legend', () => { expect(def.title).toBe('foo'); }); + it('should produce a Vega legend with gradientLength for color with a discrete scale type', () => { + const model = parseUnitModelWithScale({ + mark: 'point', + encoding: { + x: {field: 'a', type: 'nominal'}, + color: { + field: 'a', + type: 'quantitative', + scale: {type: 'quantile'}, + legend: { + gradientLength: 100 + } + } + } + }); + + const def = parseLegendForChannel(model, COLOR).combine(); + // TODO: Check if we are open to enabling toMatchSnapshot testing instead? + expect(def).toEqual({ + disable: false, + gradientLength: 100, + labelOverlap: 'greedy', + stroke: 'color', + title: 'a', + type: 'discrete' + }); + }); + [SIZE, SHAPE, OPACITY, STROKEWIDTH].forEach(channel => { it(`should produce a Vega legend object with correct type and scale for ${channel}`, () => { const spec: NormalizedUnitSpec = {