Skip to content

Commit

Permalink
Small bug fix for last grant deletion
Browse files Browse the repository at this point in the history
Adding test to reflect change
  • Loading branch information
ryanml committed Feb 11, 2019
1 parent ff40ce8 commit a2ef113
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -157,7 +157,7 @@ export const grantPanelReducer = (state: RewardsExtension.State | undefined, act
})

if (grantIndex > -1) {
grants = state.grants.splice(1, grantIndex)
grants = state.grants.splice(grantIndex, 1)
currentGrant = undefined
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ const grantReducer: Reducer<Rewards.State | undefined> = (state: Rewards.State,
})

if (grantIndex > -1) {
state.grants.splice(1, grantIndex)
state.grants.splice(grantIndex, 1)
currentGrant = undefined
}

Expand Down
36 changes: 36 additions & 0 deletions components/test/brave_rewards/ui/reducers/grant_reducer_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,42 @@ describe('Grant Reducer', () => {
}
]

expect(assertion).toEqual({
rewardsData: expectedState
})
})
it('deletes last grant', () => {
const initialState = {
...defaultState
}
initialState.grants = [
{
promotionId: 'test-promotion-id-2',
expiryTime: 0,
probi: '',
type: 'ads',
captcha: 'data:image/jpeg;base64,XXX',
hint: 'blue'
}
]
initialState.currentGrant = {
promotionId: 'test-promotion-id-2',
expiryTime: 0,
probi: '',
type: 'ads'
}

const assertion = reducers({
rewardsData: initialState
}, {
type: types.ON_GRANT_DELETE,
payload: {}
})

const expectedState: Rewards.State = { ...defaultState }
expectedState.currentGrant = undefined
expectedState.grants = []

expect(assertion).toEqual({
rewardsData: expectedState
})
Expand Down

0 comments on commit a2ef113

Please sign in to comment.