From e8db4283914753d3a4619772aaad7b69bf571f8e Mon Sep 17 00:00:00 2001 From: Cezar Augusto Date: Sat, 10 Nov 2018 14:05:53 -0200 Subject: [PATCH] update tests for welcome page --- .../brave_adblock_ui/components/app_test.tsx | 2 +- .../actions/welcome_actions_test.ts | 16 ++++++--- .../brave_welcome_ui/components/app_test.tsx | 23 ++---------- .../reducers/welcome_reducer_test.ts | 35 +++++++++++++------ components/test/testData.ts | 4 +-- 5 files changed, 40 insertions(+), 40 deletions(-) diff --git a/components/test/brave_adblock_ui/components/app_test.tsx b/components/test/brave_adblock_ui/components/app_test.tsx index 4d1632e434cf..1de2b9456b8a 100644 --- a/components/test/brave_adblock_ui/components/app_test.tsx +++ b/components/test/brave_adblock_ui/components/app_test.tsx @@ -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 diff --git a/components/test/brave_welcome_ui/actions/welcome_actions_test.ts b/components/test/brave_welcome_ui/actions/welcome_actions_test.ts index ff0027387515..7d8d45928947 100644 --- a/components/test/brave_welcome_ui/actions/welcome_actions_test.ts +++ b/components/test/brave_welcome_ui/actions/welcome_actions_test.ts @@ -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 }) }) }) diff --git a/components/test/brave_welcome_ui/components/app_test.tsx b/components/test/brave_welcome_ui/components/app_test.tsx index eeeb568d7869..68b37c5dbf7c 100644 --- a/components/test/brave_welcome_ui/components/app_test.tsx +++ b/components/test/brave_welcome_ui/components/app_test.tsx @@ -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: {} }) }) }) diff --git a/components/test/brave_welcome_ui/reducers/welcome_reducer_test.ts b/components/test/brave_welcome_ui/reducers/welcome_reducer_test.ts index 9930a0f740b0..9efae2ac78af 100644 --- a/components/test/brave_welcome_ui/reducers/welcome_reducer_test.ts +++ b/components/test/brave_welcome_ui/reducers/welcome_reducer_test.ts @@ -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() }) }) }) diff --git a/components/test/testData.ts b/components/test/testData.ts index d26fb972468f..1eaac667ad14 100644 --- a/components/test/testData.ts +++ b/components/test/testData.ts @@ -33,9 +33,7 @@ export const getMockChrome = () => { } export const welcomeInitialState: Welcome.ApplicationState = { - welcomeData: { - pageIndex: 0 - } + welcomeData: {} } export const rewardsInitialState: Rewards.ApplicationState = {