-
Notifications
You must be signed in to change notification settings - Fork 917
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Jason Sadler
committed
Dec 22, 2018
1 parent
83cb307
commit 16a6566
Showing
4 changed files
with
133 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
101 changes: 101 additions & 0 deletions
101
...t/brave_rewards/extension/brave_rewards/background/reducers/rewards_panel_reducer_test.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
/* This Source Code Form is subject to the terms of the Mozilla Public | ||
* License, v. 2.0. If a copy of the MPL was not distributed with this file, | ||
* You can obtain one at http://mozilla.org/MPL/2.0/. */ | ||
/* global chrome */ | ||
|
||
import reducers from '../../../../../../brave_rewards/resources/extension/brave_rewards/background/reducers' | ||
import { types } from '../../../../../../brave_rewards/resources/extension/brave_rewards/constants/rewards_panel_types' | ||
import { defaultState } from '../../../../../../brave_rewards/resources/extension/brave_rewards/background/storage' | ||
|
||
describe('rewards panel reducer', () => { | ||
const constantDate = new Date('2018-01-01T12:00:00') | ||
|
||
beforeAll(() => { | ||
(global as any).Date = class extends Date { | ||
constructor () { | ||
super() | ||
return constantDate | ||
} | ||
} | ||
}) | ||
|
||
describe('ON_TAB_RETRIEVED', () => { | ||
describe('persist publisher info', () => { | ||
it.skip('url is the same', () => { | ||
const initState: Rewards.State = { ...defaultState, walletCreated: true } | ||
const expectedState1: Rewards.State = { ...defaultState, walletCreated: true } | ||
const expectedState2: Rewards.State = { | ||
...defaultState, | ||
walletCreated: true, | ||
publishers: { 1: 'clifton.io' } | ||
} | ||
|
||
const payload = { | ||
tab: { | ||
url: 'https://clifton.io', | ||
incognito: false, | ||
active: true, | ||
windowId: 1 | ||
} | ||
} | ||
|
||
// first visit | ||
let state = reducers({ rewardsPanelData: initState }, { | ||
type: types.ON_TAB_RETRIEVED, | ||
payload | ||
}) | ||
|
||
expect(state.rewardsPanelData).toEqual(expectedState1) | ||
|
||
// imitates ON_PUBLISHER_DATA | ||
state.rewardsPanelData.publishers = { id_1: 'clifton.io' } | ||
|
||
// second visit | ||
state = reducers(state, { | ||
type: types.ON_TAB_RETRIEVED, | ||
payload | ||
}) | ||
|
||
expect(state.rewardsPanelData).toEqual(expectedState2) | ||
}) | ||
|
||
it('url is not the same', () => { | ||
const initState: Rewards.State = { ...defaultState, walletCreated: true } | ||
const expectedState: Rewards.State = { ...defaultState, walletCreated: true } | ||
|
||
// first visit | ||
let state = reducers({ rewardsPanelData: initState }, { | ||
type: types.ON_TAB_RETRIEVED, | ||
payload: { | ||
tab: { | ||
url: 'https://clifton.io', | ||
incognito: false, | ||
active: true, | ||
windowId: 1 | ||
} | ||
} | ||
}) | ||
|
||
expect(state.rewardsPanelData).toEqual(expectedState) | ||
|
||
// imitates ON_PUBLISHER_DATA | ||
state.rewardsPanelData.publishers = { id_1: 'clifton.io' } | ||
|
||
// second visit | ||
state = reducers(state, { | ||
type: types.ON_TAB_RETRIEVED, | ||
payload: { | ||
tab: { | ||
url: 'https://brave.com', | ||
incognito: false, | ||
active: true, | ||
windowId: 1 | ||
} | ||
} | ||
}) | ||
|
||
expect(state.rewardsPanelData).toEqual(expectedState) | ||
}) | ||
}) | ||
}) | ||
}) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters