-
Notifications
You must be signed in to change notification settings - Fork 138
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Adds button to hamburger menu to format code (#2382)
- Loading branch information
1 parent
0781da1
commit 0db2527
Showing
5 changed files
with
96 additions
and
0 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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,81 @@ | ||
import {fromJS} from 'immutable'; | ||
import React from 'react'; | ||
import {Provider} from 'react-redux'; | ||
import {act, create} from 'react-test-renderer'; | ||
import configureStore from 'redux-mock-store'; | ||
|
||
import {MenuItem} from '../TopBar/createMenu'; | ||
import HamburgerMenu from '../TopBar/HamburgerMenu'; | ||
|
||
jest.mock('i18next', () => { | ||
return { | ||
t: jest.fn().mockImplementation(translationKey => translationKey), | ||
init: jest.fn(), | ||
}; | ||
}); | ||
|
||
const mockStore = configureStore([]); | ||
const store = mockStore( | ||
fromJS({ | ||
ui: { | ||
openTopBarMenu: 'hamburger', | ||
}, | ||
}), | ||
); | ||
|
||
const DEFAULT_PROPS = { | ||
hasInstructions: false, | ||
isEditingInstructions: false, | ||
isUserAuthenticated: false, | ||
onAutoFormat: jest.fn(), | ||
onStartEditingInstructions: jest.fn(), | ||
onStartGithubLogIn: jest.fn(), | ||
}; | ||
|
||
function buildComponent() { | ||
return ( | ||
<Provider store={store}> | ||
<HamburgerMenu {...DEFAULT_PROPS} /> | ||
</Provider> | ||
); | ||
} | ||
|
||
function renderComponent(props = {}) { | ||
let component; | ||
act(() => { | ||
component = create(buildComponent(props)); | ||
}); | ||
return component; | ||
} | ||
|
||
describe('hamburger menu', () => { | ||
let menu; | ||
|
||
beforeEach(() => { | ||
menu = renderComponent(); | ||
DEFAULT_PROPS.onAutoFormat.mockClear(); | ||
DEFAULT_PROPS.onStartEditingInstructions.mockClear(); | ||
DEFAULT_PROPS.onStartGithubLogIn.mockClear(); | ||
}); | ||
|
||
it('renders the format code button', () => { | ||
const menuItems = menu.root.findAllByType(MenuItem); | ||
const formatCodeBtn = menuItems.find( | ||
btn => btn.props.children === 'top-bar.format-code', | ||
); | ||
expect(formatCodeBtn).toBeTruthy(); | ||
}); | ||
|
||
it('calls the passed `onAutoFormat()` method when format code button is pressed', () => { | ||
const menuItems = menu.root.findAllByType(MenuItem); | ||
const formatCodeBtn = menuItems.find( | ||
btn => btn.props.children === 'top-bar.format-code', | ||
); | ||
|
||
act(() => { | ||
formatCodeBtn.props.onClick(); | ||
}); | ||
|
||
expect(DEFAULT_PROPS.onAutoFormat).toHaveBeenCalledTimes(1); | ||
}); | ||
}); |
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