Skip to content

Commit

Permalink
Merge pull request #1159 from brave/ca-2667
Browse files Browse the repository at this point in the history
fix broken tests after lint fix
  • Loading branch information
NejcZdovc authored Dec 20, 2018
2 parents 2091feb + 1747078 commit b045822
Show file tree
Hide file tree
Showing 16 changed files with 87 additions and 99 deletions.
2 changes: 1 addition & 1 deletion components/brave_adblock_ui/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import { debounce } from '../common/debounce'

const keyName = 'adblock-data'

const defaultState: AdBlock.State = {
export const defaultState: AdBlock.State = {
stats: {
numBlocked: 0,
regionalAdBlockEnabled: false
Expand Down
2 changes: 1 addition & 1 deletion components/brave_welcome_ui/actions/welcome_actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import { types } from '../constants/welcome_types'

export const importNowRequested = () => action(types.IMPORT_NOW_REQUESTED)

export const goToTabRequested = (url: URL, target: string) => action(types.GO_TO_TAB_REQUESTED, {
export const goToTabRequested = (url: string, target: string) => action(types.GO_TO_TAB_REQUESTED, {
url,
target
})
Expand Down
2 changes: 1 addition & 1 deletion components/brave_welcome_ui/storage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import { debounce } from '../common/debounce'

const keyName = 'welcome-data'

const defaultState = {}
export const defaultState = {}

const cleanData = (state: Welcome.State) => {
state = { ...state }
Expand Down
19 changes: 1 addition & 18 deletions components/test/brave_rewards/ui/components/app_test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,24 +15,7 @@ import {
describe('rewardsPage component', () => {
describe('mapStateToProps', () => {
it('should map the default state', () => {
expect(mapStateToProps(rewardsInitialState)).toEqual({
rewardsData: {
walletCreated: false,
walletCreateFailed: false,
createdTimestamp: null,
enabledMain: false,
enabledAds: false,
enabledContribute: false,
firstLoad: null,
contributionMinTime: 8,
contributionMinVisits: 1,
contributionMonthly: 10,
contributionNonVerified: true,
contributionVideos: true,
donationAbilityYT: true,
donationAbilityTwitter: true
}
})
expect(mapStateToProps(rewardsInitialState)).toEqual(rewardsInitialState)
})
})

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@
import reducers from '../../../../brave_rewards/resources/ui/reducers/index'
import { types } from '../../../../brave_rewards/resources/ui/constants/rewards_types'
import { defaultState } from '../../../../brave_rewards/resources/ui/storage'
import { rewardsInitialState } from '../../../testData'

describe('publishers reducer', () => {
describe('ON_CONTRIBUTE_LIST', () => {
it('does not include excluded publishers in auto-contribute list', () => {
const initialState = reducers(defaultState, {
const initialState = reducers(rewardsInitialState, {
type: types.ON_NUM_EXCLUDED_SITES,
payload: {
excludedSitesInfo: {
Expand Down Expand Up @@ -68,7 +69,7 @@ describe('publishers reducer', () => {
})

it('removes a recently restored publisher from state.excluded', () => {
let testState = reducers(defaultState, {
let testState = reducers(rewardsInitialState, {
type: types.ON_NUM_EXCLUDED_SITES,
payload: {
excludedSitesInfo: {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ describe('rewards reducer', () => {
const constantDate = new Date('2018-01-01T12:00:00')

beforeAll(() => {
global.Date = class extends Date {
(global as any).Date = class extends Date {
constructor () {
super()
return constantDate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ describe('wallet reducer', () => {
const constantDate = new Date('2018-01-01T12:00:00')

beforeAll(() => {
global.Date = class extends Date {
(global as any).Date = class extends Date {
constructor () {
super()
return constantDate
Expand Down
4 changes: 2 additions & 2 deletions components/test/brave_sync_ui/actions/sync_actions_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,10 @@ describe('sync_actions', () => {
})

it('onRemoveDevice', () => {
expect(actions.onRemoveDevice(1337)).toEqual({
expect(actions.onRemoveDevice(1337, 'clifton windows')).toEqual({
type: types.SYNC_ON_REMOVE_DEVICE,
meta: undefined,
payload: { id: 1337 }
payload: { id: 1337, deviceName: 'clifton windows' }
})
})

Expand Down
10 changes: 1 addition & 9 deletions components/test/brave_sync_ui/components/app_test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,7 @@ import {
describe('sync page component', () => {
describe('mapStateToProps', () => {
it('should map the default state', () => {
expect(mapStateToProps(syncInitialState)).toEqual({
syncData: {
devices: [{ id: 0, lastActive: '', name: '' }],
isSyncConfigured: false,
seedQRImageSource: '',
syncWords: '',
thisDeviceName: ''
}
})
expect(mapStateToProps(syncInitialState)).toEqual(syncInitialState)
})
})

Expand Down
4 changes: 3 additions & 1 deletion components/test/brave_webtorrent/actions/tab_action_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,9 @@ const tab: chrome.tabs.Tab = {
windowId: 1,
active: true,
incognito: false,
selected: false
selected: false,
discarded: false,
autoDiscardable: false
}

const changeInfo: chrome.tabs.TabChangeInfo = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,37 @@ const torrent: Torrent = {
progress: 0,
ratio: 0,
numPeers: 0,
length: 0
torrentFile: Buffer.from('1337', 'utf-8'),
torrentFileBlobURL: 'https://brave.com',
files: [],
received: 1337,
path: '/',
ready: true,
name: 'torrentz',
destroy: jest.fn(),
addPeer: jest.fn(),
addWebSeed: jest.fn(),
removePeer: jest.fn(),
select: jest.fn(),
deselect: jest.fn(),
createServer: jest.fn(),
pause: jest.fn(),
resume: jest.fn(),
on: jest.fn(),
addListener: jest.fn(),
once: jest.fn(),
removeListener: jest.fn(),
off: jest.fn(),
removeAllListeners: jest.fn(),
setMaxListeners: jest.fn(),
getMaxListeners: jest.fn(),
listeners: jest.fn(),
rawListeners: jest.fn(),
emit: jest.fn(),
listenerCount: jest.fn(),
prependListener: jest.fn(),
prependOnceListener: jest.fn(),
eventNames: jest.fn()
}

describe('webtorrent_actions', () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,15 @@ const defaultState = { currentWindowId: -1, activeTabIds: {},
torrentStateMap: {}, torrentObjMap: {} }
describe('webtorrent reducer test', () => {
it('handle the initial state', () => {
const state = webtorrentReducer(undefined, tabActions.tabRemoved({ tabId: 1 }))
const state = webtorrentReducer(undefined, tabActions.tabRemoved(1))
expect(state).toEqual(defaultState)
})

describe('WINDOW_CREATED', () => {
it('sets currentWindowId if it is the first window', () => {
const window: chrome.windows.Window = {
state: 'normal',
type: 'normal',
id: 1,
focused: false,
incognito: false,
Expand All @@ -33,6 +35,8 @@ describe('webtorrent reducer test', () => {

it('sets currentWindowId if it is focused', () => {
const window: chrome.windows.Window = {
state: 'normal',
type: 'normal',
id: 2,
focused: true,
incognito: false,
Expand All @@ -45,6 +49,8 @@ describe('webtorrent reducer test', () => {

it('do not set currentWindowId if either focused or it is the first window', () => {
const window: chrome.windows.Window = {
state: 'normal',
type: 'normal',
id: 1,
focused: false,
incognito: false,
Expand Down Expand Up @@ -73,6 +79,8 @@ describe('webtorrent reducer test', () => {
})

const tab: chrome.tabs.Tab = {
discarded: false,
autoDiscardable: false,
id: 0,
index: 2,
pinned: false,
Expand All @@ -94,24 +102,30 @@ describe('webtorrent reducer test', () => {
const changeInfo = {}
describe('TAB_UPDATED', () => {
it('state is unchanged if tab url is not ready', () => {
const state = webtorrentReducer(torrentsState,
tabActions.tabUpdated(tab.id, changeInfo, tab))
expect(state).toEqual(state)
if (tab && tab.id) {
const state = webtorrentReducer(torrentsState,
tabActions.tabUpdated(tab.id, changeInfo, tab))
expect(state).toEqual(state)
}
})

it('update currentWindowID if it is not initialized yet', () => {
const stateWithoutWindowId = { ...torrentsState, currentWindowId: -1 }
const state = webtorrentReducer(stateWithoutWindowId,
tabActions.tabUpdated(tab.id, changeInfo, tab))
expect(state).toEqual({ ...stateWithoutWindowId, currentWindowId: 0 })
if (tab && tab.id) {
const stateWithoutWindowId = { ...torrentsState, currentWindowId: -1 }
const state = webtorrentReducer(stateWithoutWindowId,
tabActions.tabUpdated(tab.id, changeInfo, tab))
expect(state).toEqual({ ...stateWithoutWindowId, currentWindowId: 0 })
}
})

it('update activeTabIds if it is not initialized yet for this window', () => {
const stateWithNoActiveTabIds = { ...torrentsState, activeTabIds: {} }
const activeTab = { ...tab, active: true }
const state = webtorrentReducer(stateWithNoActiveTabIds,
tabActions.tabUpdated(activeTab.id, changeInfo, activeTab))
expect(state).toEqual({ ...torrentsState, activeTabIds: { 0: 0 } })
if (activeTab && activeTab.id) {
const state = webtorrentReducer(stateWithNoActiveTabIds,
tabActions.tabUpdated(activeTab.id, changeInfo, activeTab))
expect(state).toEqual({ ...torrentsState, activeTabIds: { 0: 0 } })
}
})
// TODO: mock ParseTorrent to test tab url case
})
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,8 @@ describe('torrentViewerHeader component', () => {
<TorrentViewerHeader
tabId={tabId}
torrentId={torrentId}
startTorrent={startTorrentMock}
stopDownload={stopDownloadMock}
onStartTorrent={startTorrentMock}
onStopDownload={stopDownloadMock}
/>
</TestThemeProvider>
)
Expand All @@ -36,8 +36,8 @@ describe('torrentViewerHeader component', () => {
tabId={tabId}
torrentId={torrentId}
torrent={torrentObj}
startTorrent={startTorrentMock}
stopDownload={stopDownloadMock}
onStartTorrent={startTorrentMock}
onStopDownload={stopDownloadMock}
/>
</TestThemeProvider>
)
Expand Down
2 changes: 1 addition & 1 deletion components/test/brave_webtorrent/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* 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/. */

import { ActiveTabIds, ApplicationState, TorrentObj, TorrentState, TorrentStateMap, TorrentObjMap, TorrentsState } from '../../brave_webtorrent/extension/constants/webtorrentState.ts'
import { ActiveTabIds, ApplicationState, TorrentObj, TorrentState, TorrentStateMap, TorrentObjMap, TorrentsState } from '../../brave_webtorrent/extension/constants/webtorrentState'

export const currentWindowId: number = 0

Expand Down
53 changes: 9 additions & 44 deletions components/test/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@
* 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/. */

import { defaultState as welcomeData } from '../../components/brave_welcome_ui/storage'
import { defaultState as rewardsData } from '../../components/brave_rewards/resources/ui/storage'
import { defaultState as adblockData } from '../../components/brave_adblock_ui/storage'
import { defaultState as syncData } from '../../components/brave_sync/ui/storage'

export class ChromeEvent {
listeners: Array<() => void>

Expand Down Expand Up @@ -32,50 +37,10 @@ export const getMockChrome = () => {
}
}

export const welcomeInitialState: Welcome.ApplicationState = {
welcomeData: {}
}
export const welcomeInitialState: Welcome.ApplicationState = { welcomeData }

export const rewardsInitialState: Rewards.ApplicationState = {
rewardsData: {
walletCreated: false,
walletCreateFailed: false,
createdTimestamp: null,
enabledMain: false,
enabledAds: false,
enabledContribute: false,
firstLoad: null,
contributionMinTime: 8,
contributionMinVisits: 1,
contributionMonthly: 10,
contributionNonVerified: true,
contributionVideos: true,
donationAbilityYT: true,
donationAbilityTwitter: true
}
}
export const rewardsInitialState: Rewards.ApplicationState = { rewardsData }

export const adblockInitialState: AdBlock.ApplicationState = {
adblockData: {
stats: {
numBlocked: 0,
regionalAdBlockEnabled: false
}
}
}
export const adblockInitialState: AdBlock.ApplicationState = { adblockData }

export const syncInitialState: Sync.ApplicationState = {
syncData: {
thisDeviceName: '',
devices: [
{
name: '',
id: 0,
lastActive: ''
}
],
isSyncConfigured: false,
seedQRImageSource: '',
syncWords: ''
}
}
export const syncInitialState: Sync.ApplicationState = { syncData }
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,10 @@
},
"include": [
"./components/definitions/*",
"./components"
"./components/**/*"
],
"exclude": [
"./components/test/**/*",
"./components/brave_sync/extension"
]
}

0 comments on commit b045822

Please sign in to comment.