Skip to content

Commit

Permalink
update tests for welcome page
Browse files Browse the repository at this point in the history
  • Loading branch information
cezaraugusto committed Nov 12, 2018
1 parent ca81a72 commit 760703b
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 40 deletions.
2 changes: 1 addition & 1 deletion components/test/brave_adblock_ui/components/app_test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe('adblockPage component', () => {
})

describe('mapDispatchToProps', () => {
it('should change the current pageIndex if goToPageRequested is fired', () => {
it('should fire statsUpdated', () => {
const dispatch = jest.fn()

// For the `mapDispatchToProps`, call it directly but pass in
Expand Down
16 changes: 12 additions & 4 deletions components/test/brave_welcome_ui/actions/welcome_actions_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,19 @@ describe('welcome_actions', () => {
})
})

it('goToPageRequested', () => {
expect(actions.goToPageRequested(1337)).toEqual({
type: types.GO_TO_PAGE_REQUESTED,
it('goToTabRequested', () => {
expect(actions.goToTabRequested('https://rossmoody.design', '_blank')).toEqual({
type: types.GO_TO_TAB_REQUESTED,
meta: undefined,
payload: { pageIndex: 1337 }
payload: { url: 'https://rossmoody.design', target: '_blank' }
})
})

it('closeTabRequested', () => {
expect(actions.closeTabRequested()).toEqual({
type: types.CLOSE_TAB_REQUESTED,
meta: undefined,
payload: undefined
})
})
})
23 changes: 2 additions & 21 deletions components/test/brave_welcome_ui/components/app_test.tsx
Original file line number Diff line number Diff line change
@@ -1,35 +1,16 @@
import * as React from 'react'
import { shallow } from 'enzyme'
import { types } from '../../../brave_welcome_ui/constants/welcome_types'
import { welcomeInitialState } from '../../testData'
import {
WelcomePage,
mapStateToProps,
mapDispatchToProps
mapStateToProps
} from '../../../brave_welcome_ui/components/app'

describe('welcomePage component', () => {
describe('mapStateToProps', () => {
it('should map the default state', () => {
expect(mapStateToProps(welcomeInitialState)).toEqual({
welcomeData: {
pageIndex: 0
}
})
})
})

describe('mapDispatchToProps', () => {
it('should change the current pageIndex if goToPageRequested is fired', () => {
const dispatch = jest.fn()

// For the `mapDispatchToProps`, call it directly but pass in
// a mock function and check the arguments passed in are as expected
mapDispatchToProps(dispatch).actions.goToPageRequested(1337)
expect(dispatch.mock.calls[0][0]).toEqual({
type: types.GO_TO_PAGE_REQUESTED,
meta: undefined,
payload: { pageIndex: 1337 }
welcomeData: {}
})
})
})
Expand Down
35 changes: 24 additions & 11 deletions components/test/brave_welcome_ui/reducers/welcome_reducer_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,38 @@ import welcomeReducer from '../../../brave_welcome_ui/reducers/welcome_reducer'
import * as actions from '../../../brave_welcome_ui/actions/welcome_actions'
import { types } from '../../../brave_welcome_ui/constants/welcome_types'

window.open = jest.fn()
window.close = jest.fn()

describe('welcomeReducer', () => {
it('should handle initial state', () => {
const assertion = welcomeReducer(undefined, actions.goToPageRequested(1))
expect(assertion).toEqual({ pageIndex: 1 })
const assertion = welcomeReducer(undefined, actions.closeTabRequested())
expect(assertion).toEqual({})
})

describe('GO_TO_PAGE_REQUESTED', () => {
it('sets the pageIndex', () => {
const assertion = welcomeReducer(undefined, {
type: types.GO_TO_PAGE_REQUESTED,
payload: { pageIndex: 1337 }
describe.skip('IMPORT_NOW_REQUESTED', () => {
it('calls importNowRequested', () => {
// TODO
})
})

describe('GO_TO_TAB_REQUESTED', () => {
it('calls window.open', () => {
welcomeReducer(undefined, {
type: types.GO_TO_TAB_REQUESTED,
payload: { url: 'https://brave.com', target: '_blank' }
})
expect(assertion).toEqual({ pageIndex: 1337 })
expect(window.open).toBeCalled()
})
})

describe.skip('IMPORT_NOW_REQUESTED', () => {
it('calls importNowRequested', () => {
// TODO
describe.skip('CLOSE_TAB_REQUESTED', () => {
it('calls window.close', () => {
welcomeReducer(undefined, {
type: types.CLOSE_TAB_REQUESTED,
payload: undefined
})
expect(window.close).toBeCalled()
})
})
})
4 changes: 1 addition & 3 deletions components/test/testData.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,9 +33,7 @@ export const getMockChrome = () => {
}

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

export const rewardsInitialState: Rewards.ApplicationState = {
Expand Down

0 comments on commit 760703b

Please sign in to comment.