-
Notifications
You must be signed in to change notification settings - Fork 232
fix(top-app-bar): foundation should be destroyed and reinitialized on variant change #519
Changes from all commits
90d9943
ea64e2c
6fe6c52
0af79bd
405a109
1cebcef
bb7765a
4bf447a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import React from 'react'; | ||
import TopAppBar from '../../../packages/top-app-bar'; | ||
import MaterialIcon from '../../../packages/material-icon'; | ||
import MainTopAppBarContent from './mainContent'; | ||
|
||
class TopAppBarProminentToShortCollapsedScreenshotTest extends React.Component { | ||
state = { | ||
isPhone: window.innerWidth < 599, | ||
}; | ||
|
||
componentDidMount() { | ||
window.addEventListener('resize', this.updateTopAppBarVariant); | ||
} | ||
|
||
shouldComponentUpdate(_, nextState) { | ||
return nextState.isPhone !== this.state.isPhone; | ||
} | ||
|
||
componentWillUnmount() { | ||
window.removeEventListener('resize', this.updateTopAppBarVariant); | ||
} | ||
|
||
updateTopAppBarVariant = () => { | ||
const isPhone = window.innerWidth < 599; | ||
this.setState({isPhone}); | ||
} | ||
|
||
render() { | ||
if (this.state.isPhone) { | ||
return ( | ||
<div> | ||
<TopAppBar | ||
shortCollapsed | ||
navigationIcon={<MaterialIcon | ||
icon='menu' | ||
onClick={() => console.log('click')} | ||
/>} | ||
/> | ||
<MainTopAppBarContent /> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div> | ||
<TopAppBar | ||
prominent | ||
title={'Annie, I\'m a Hawk'} | ||
navigationIcon={<MaterialIcon | ||
icon='menu' | ||
onClick={() => console.log('click')} | ||
/>} | ||
/> | ||
<MainTopAppBarContent /> | ||
</div> | ||
); | ||
} | ||
} | ||
|
||
export default TopAppBarProminentToShortCollapsedScreenshotTest; |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -215,6 +215,111 @@ test('#enableRippleOnElement throws error if a native element', () => { | |
); | ||
}); | ||
|
||
test('when changes from short to fixed the foundation changes', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. wow great test coverage! |
||
const wrapper = shallow(<TopAppBar short />); | ||
const originalFoundation = wrapper.instance().foundation_; | ||
wrapper.setProps({fixed: true, short: false}); | ||
assert.notEqual(wrapper.instance().foundation_, originalFoundation); | ||
assert.exists(wrapper.instance().foundation_); | ||
}); | ||
|
||
test('when changes from short to fixed the foundation changes', () => { | ||
const wrapper = shallow(<TopAppBar short />); | ||
const originalFoundation = wrapper.instance().foundation_; | ||
wrapper.setProps({fixed: true, short: false}); | ||
assert.notEqual(wrapper.instance().foundation_, originalFoundation); | ||
assert.exists(wrapper.instance().foundation_); | ||
}); | ||
|
||
test('when changes from short to standard the foundation changes', () => { | ||
const wrapper = shallow(<TopAppBar short />); | ||
const originalFoundation = wrapper.instance().foundation_; | ||
wrapper.setProps({short: false}); | ||
assert.notEqual(wrapper.instance().foundation_, originalFoundation); | ||
assert.exists(wrapper.instance().foundation_); | ||
}); | ||
|
||
test('when changes from short to prominent the foundation changes', () => { | ||
const wrapper = shallow(<TopAppBar short />); | ||
const originalFoundation = wrapper.instance().foundation_; | ||
wrapper.setProps({short: false, prominent: true}); | ||
assert.notEqual(wrapper.instance().foundation_, originalFoundation); | ||
assert.exists(wrapper.instance().foundation_); | ||
}); | ||
|
||
test('when changes from short to shortCollpased the foundation changes', () => { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Shouldn't the foundation not change in this case? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. From what I understand it should reinitialize. When There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. ah right - this is because you would want the short collapsed to immediately collapse. Good call. Thanks! |
||
const wrapper = shallow(<TopAppBar short />); | ||
const originalFoundation = wrapper.instance().foundation_; | ||
wrapper.setProps({shortCollapsed: true}); | ||
assert.notEqual(wrapper.instance().foundation_, originalFoundation); | ||
assert.exists(wrapper.instance().foundation_); | ||
}); | ||
|
||
test('when changes from fixed to prominent the foundation changes', () => { | ||
const wrapper = shallow(<TopAppBar fixed/>); | ||
const originalFoundation = wrapper.instance().foundation_; | ||
wrapper.setProps({fixed: false, prominent: true}); | ||
assert.notEqual(wrapper.instance().foundation_, originalFoundation); | ||
assert.exists(wrapper.instance().foundation_); | ||
}); | ||
|
||
test('when changes from fixed to short the foundation changes', () => { | ||
const wrapper = shallow(<TopAppBar fixed/>); | ||
const originalFoundation = wrapper.instance().foundation_; | ||
wrapper.setProps({fixed: false, short: true}); | ||
assert.notEqual(wrapper.instance().foundation_, originalFoundation); | ||
assert.exists(wrapper.instance().foundation_); | ||
}); | ||
|
||
test('when changes from fixed to shortCollpased the foundation changes', () => { | ||
const wrapper = shallow(<TopAppBar fixed/>); | ||
const originalFoundation = wrapper.instance().foundation_; | ||
wrapper.setProps({fixed: false, shortCollapsed: true}); | ||
assert.notEqual(wrapper.instance().foundation_, originalFoundation); | ||
assert.exists(wrapper.instance().foundation_); | ||
}); | ||
|
||
test('when changes from fixed to standard the foundation changes', () => { | ||
const wrapper = shallow(<TopAppBar fixed/>); | ||
const originalFoundation = wrapper.instance().foundation_; | ||
wrapper.setProps({fixed: false}); | ||
assert.notEqual(wrapper.instance().foundation_, originalFoundation); | ||
assert.exists(wrapper.instance().foundation_); | ||
}); | ||
|
||
test('when changes from standard to fixed the foundation changes', () => { | ||
const wrapper = shallow(<TopAppBar />); | ||
const originalFoundation = wrapper.instance().foundation_; | ||
wrapper.setProps({fixed: true}); | ||
assert.notEqual(wrapper.instance().foundation_, originalFoundation); | ||
assert.exists(wrapper.instance().foundation_); | ||
}); | ||
|
||
test('when changes from standard to short the foundation changes', () => { | ||
const wrapper = shallow(<TopAppBar />); | ||
const originalFoundation = wrapper.instance().foundation_; | ||
wrapper.setProps({short: true}); | ||
assert.notEqual(wrapper.instance().foundation_, originalFoundation); | ||
assert.exists(wrapper.instance().foundation_); | ||
}); | ||
|
||
test('when changes from standard to shortCollapsed the foundation changes', () => { | ||
const wrapper = shallow(<TopAppBar />); | ||
const originalFoundation = wrapper.instance().foundation_; | ||
wrapper.setProps({shortCollapsed: true}); | ||
assert.notEqual(wrapper.instance().foundation_, originalFoundation); | ||
assert.exists(wrapper.instance().foundation_); | ||
}); | ||
|
||
test('when changes from standard to prominent the foundation does not ' + | ||
'change', () => { | ||
const wrapper = shallow(<TopAppBar />); | ||
const originalFoundation = wrapper.instance().foundation_; | ||
wrapper.setProps({prominent: true}); | ||
assert.equal(wrapper.instance().foundation_, originalFoundation); | ||
assert.exists(wrapper.instance().foundation_); | ||
}); | ||
|
||
test('#componentWillUnmount destroys foundation', () => { | ||
const wrapper = shallow(<TopAppBar />); | ||
const foundation = wrapper.instance().foundation_; | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
formatting issue, but for the sake of time I'm going to ignore this one and fix in a following pr