From 8e3203f90367d5be12374298d2a2037a42680841 Mon Sep 17 00:00:00 2001 From: Marta Bondyra Date: Thu, 3 Dec 2020 14:20:02 +0100 Subject: [PATCH] fix test --- .../xy_visualization/visualization.test.ts | 31 ++++++++++--------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/x-pack/plugins/lens/public/xy_visualization/visualization.test.ts b/x-pack/plugins/lens/public/xy_visualization/visualization.test.ts index 5747e6592688d..cab1a0185333f 100644 --- a/x-pack/plugins/lens/public/xy_visualization/visualization.test.ts +++ b/x-pack/plugins/lens/public/xy_visualization/visualization.test.ts @@ -560,24 +560,27 @@ describe('xy_visualization', () => { }); it('should respect the order of accessors coming from datasource', () => { - const colorAssignment = require('./color_assignment'); // eslint-disable-line @typescript-eslint/no-var-requires - const getAccessorColorConfigSpy = jest.spyOn(colorAssignment, 'getAccessorColorConfig'); mockDatasource.publicAPIMock.getTableSpec.mockReturnValue([ { columnId: 'c' }, { columnId: 'b' }, ]); - callConfigForYConfigs({}); - expect(getAccessorColorConfigSpy).toHaveBeenCalledWith( - expect.anything(), - expect.anything(), - { - accessors: ['c', 'b'], - layerId: 'first', - seriesType: 'area', - xAccessor: 'a', - }, - expect.anything() - ); + const paletteGetter = jest.spyOn(paletteServiceMock, 'get'); + // overrite palette with a palette returning first blue, then green as color + paletteGetter.mockReturnValue({ + id: 'default', + title: '', + getColors: jest.fn(), + toExpression: jest.fn(), + getColor: jest.fn().mockReturnValueOnce('blue').mockReturnValueOnce('green'), + }); + + const yConfigs = callConfigForYConfigs({}); + expect(yConfigs?.accessors[0].columnId).toEqual('c'); + expect(yConfigs?.accessors[0].color).toEqual('blue'); + expect(yConfigs?.accessors[1].columnId).toEqual('b'); + expect(yConfigs?.accessors[1].color).toEqual('green'); + + paletteGetter.mockClear(); }); }); });