Add cancel edit cell spec

pull/10616/head
Andrew Watkins 2017-07-18 12:22:20 -07:00
parent a746de32ae
commit e90614e33d
3 changed files with 47 additions and 0 deletions

View File

@ -11,6 +11,7 @@ import {
renameDashboardCell,
syncDashboardCell,
templateVariableSelected,
cancelEditCell,
} from 'src/dashboards/actions'
let state
@ -62,6 +63,13 @@ const c1 = {
isEditing: false,
name: 'Gigawatts',
}
const editingCell = {
i: 1,
isEditing: true,
name: 'Edit me',
}
const cells = [c1]
const tempVar = {
...d1.templates[0],
@ -180,4 +188,17 @@ describe('DataExplorer.Reducers.UI', () => {
expect(actual.dashboards[0].templates[0].values[1].selected).to.equal(false)
expect(actual.dashboards[0].templates[0].values[2].selected).to.equal(true)
})
it('can cancel cell editing', () => {
const dash = _.cloneDeep(d1)
dash.cells = [editingCell]
const actual = reducer(
{dashboards: [dash]},
cancelEditCell(dash.id, editingCell.i)
)
expect(actual.dashboards[0].cells[0].isEditing).to.equal(false)
expect(actual.dashboards[0].cells[0].name).to.equal(editingCell.name)
})
})

View File

@ -93,6 +93,14 @@ export const editDashboardCell = (dashboard, x, y, isEditing) => ({
},
})
export const cancelEditCell = (dashboardID, cellID) => ({
type: 'CANCEL_EDIT_CELL',
payload: {
dashboardID,
cellID,
},
})
export const renameDashboardCell = (dashboard, x, y, name) => ({
type: 'RENAME_DASHBOARD_CELL',
payload: {

View File

@ -132,6 +132,24 @@ export default function ui(state = initialState, action) {
return {...state, ...newState}
}
case 'CANCEL_EDIT_CELL': {
const {dashboardID, cellID} = action.payload
const dashboards = state.dashboards.map(
d =>
(d.id === dashboardID
? {
...d,
cells: d.cells.map(
c => (c.i === cellID ? {...c, isEditing: false} : c)
),
}
: d)
)
return {...state, dashboards}
}
case 'SYNC_DASHBOARD_CELL': {
const {cell, dashboard} = action.payload