From e8dbc0aea41206db9c5c85cd3fc01139316bc779 Mon Sep 17 00:00:00 2001 From: Alex P Date: Wed, 21 Feb 2018 14:52:22 -0800 Subject: [PATCH] Write tests for cellEditorOverlay reducer --- .../reducers/cellEditorOverlaySpec.js | 119 ++++++++++++++++++ .../dashboards/reducers/cellEditorOverlay.js | 2 +- 2 files changed, 120 insertions(+), 1 deletion(-) create mode 100644 ui/spec/dashboards/reducers/cellEditorOverlaySpec.js diff --git a/ui/spec/dashboards/reducers/cellEditorOverlaySpec.js b/ui/spec/dashboards/reducers/cellEditorOverlaySpec.js new file mode 100644 index 000000000..6cdbbdbd4 --- /dev/null +++ b/ui/spec/dashboards/reducers/cellEditorOverlaySpec.js @@ -0,0 +1,119 @@ +import reducer, {initialState} from 'src/dashboards/reducers/cellEditorOverlay' + +import { + showCellEditorOverlay, + hideCellEditorOverlay, + changeCellType, + renameCell, + updateSingleStatColors, + updateSingleStatType, + updateGaugeColors, + updateAxes, +} from 'src/dashboards/actions/cellEditorOverlay' + +import { + validateGaugeColors, + validateSingleStatColors, + getSingleStatType, +} from 'src/dashboards/constants/gaugeColors' + +const defaultCellType = 'line' +const defaultCellName = 'defaultCell' +const defaultCellAxes = { + y: { + base: '10', + bounds: ['0', ''], + label: '', + prefix: '', + scale: 'linear', + suffix: '', + }, +} + +const defaultCell = { + axes: defaultCellAxes, + colors: [], + name: defaultCellName, + type: defaultCellType, +} + +const defaultSingleStatType = getSingleStatType(defaultCell.colors) +const defaultSingleStatColors = validateSingleStatColors( + defaultCell.colors, + defaultSingleStatType +) +const defaultGaugeColors = validateGaugeColors(defaultCell.colors) + +describe('Dashboards.Reducers.cellEditorOverlay', () => { + it('should show cell editor overlay', () => { + const actual = reducer(initialState, showCellEditorOverlay(defaultCell)) + console.log('actual: ', actual) + const expected = { + cell: defaultCell, + gaugeColors: defaultGaugeColors, + singleStatColors: defaultSingleStatColors, + singleStatType: defaultSingleStatType, + } + console.log('expected: ', expected) + + expect(actual.cell).to.equal(expected.cell) + expect(actual.gaugeColors).to.equal(expected.gaugeColors) + expect(actual.singleStatColors).to.equal(expected.singleStatColors) + expect(actual.singleStatType).to.equal(expected.singleStatType) + }) + + it('should hide cell editor overlay', () => { + const actual = reducer(initialState, hideCellEditorOverlay) + const expected = null + + expect(actual.cell).to.equal(expected) + }) + + it('should change the cell editor visualization type', () => { + const actual = reducer(initialState, changeCellType(defaultCellType)) + const expected = defaultCellType + + expect(actual.cell.type).to.equal(expected) + }) + + it('should change the name of the cell', () => { + const actual = reducer(initialState, renameCell(defaultCellName)) + const expected = defaultCellName + + expect(actual.cell.name).to.equal(expected) + }) + + it('should update the cell single stat colors', () => { + const actual = reducer( + initialState, + updateSingleStatColors(defaultSingleStatColors) + ) + const expected = defaultSingleStatColors + + expect(actual.singleStatColors).to.equal(expected) + }) + + it('should toggle the single stat type', () => { + const actual = reducer( + initialState, + updateSingleStatType(defaultSingleStatType) + ) + const expected = defaultSingleStatType + + expect(actual.singleStatType).to.equal(expected) + }) + + it('should update the cell gauge colors', () => { + const actual = reducer(initialState, updateGaugeColors(defaultGaugeColors)) + const expected = defaultGaugeColors + + expect(actual.gaugeColors).to.equal(expected) + }) + + it('should update the cell axes', () => { + const actual = reducer(initialState, updateAxes(defaultCellAxes)) + const expected = defaultCellAxes + + expect(actual.cell.axes).to.equal(expected) + }) +}) diff --git a/ui/src/dashboards/reducers/cellEditorOverlay.js b/ui/src/dashboards/reducers/cellEditorOverlay.js index 64ca629a6..f82fc446a 100644 --- a/ui/src/dashboards/reducers/cellEditorOverlay.js +++ b/ui/src/dashboards/reducers/cellEditorOverlay.js @@ -7,7 +7,7 @@ import { getSingleStatType, } from 'src/dashboards/constants/gaugeColors' -const initialState = { +export const initialState = { cell: null, singleStatType: SINGLE_STAT_TEXT, singleStatColors: DEFAULT_SINGLESTAT_COLORS,