-
Notifications
You must be signed in to change notification settings - Fork 482
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Revert "Revert "Merge pull request #23689 from code-dot-org/es6-instr…
…uctions"" This reverts commit e0c0e74.
- Loading branch information
1 parent
ef6b643
commit e97c8f6
Showing
4 changed files
with
235 additions
and
38 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
77 changes: 77 additions & 0 deletions
77
apps/test/unit/templates/instructions/InstructionsDialogWrapperTest.jsx
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,77 @@ | ||
import React from 'react'; | ||
import {mount} from 'enzyme'; | ||
import sinon from 'sinon'; | ||
import {expect} from '../../../util/configuredChai'; | ||
import { | ||
UnwrappedInstructionsDialogWrapper as InstructionsDialogWrapper | ||
} from '@cdo/apps/templates/instructions/InstructionsDialogWrapper'; | ||
|
||
describe('InstructionsDialogWrapper', () => { | ||
let spy, wrapper; | ||
|
||
beforeEach(() => { | ||
spy = sinon.spy(); | ||
}); | ||
|
||
afterEach(() => { | ||
if (wrapper) { | ||
wrapper.unmount(); | ||
} | ||
}); | ||
|
||
it('renders nothing', () => { | ||
wrapper = mount( | ||
<InstructionsDialogWrapper | ||
isOpen={true} | ||
showInstructionsDialog={spy} | ||
/> | ||
); | ||
expect(wrapper).to.be.empty; | ||
}); | ||
|
||
it('does not call showInstructionsDialog on first render', () => { | ||
wrapper = mount( | ||
<InstructionsDialogWrapper | ||
isOpen={true} | ||
showInstructionsDialog={spy} | ||
/> | ||
); | ||
expect(spy).not.to.have.been.called; | ||
}); | ||
|
||
it('calls showInstructionsDialog every time props change to open', () => { | ||
wrapper = mount( | ||
<InstructionsDialogWrapper | ||
isOpen={false} | ||
showInstructionsDialog={spy} | ||
/> | ||
); | ||
expect(spy).not.to.have.been.called; | ||
wrapper.setProps({isOpen: true}); | ||
expect(spy).to.have.been.calledOnce; | ||
wrapper.setProps({isOpen: true}); | ||
expect(spy).to.have.been.calledOnce; | ||
wrapper.setProps({isOpen: false}); | ||
expect(spy).to.have.been.calledOnce; | ||
wrapper.setProps({isOpen: false}); | ||
expect(spy).to.have.been.calledOnce; | ||
wrapper.setProps({isOpen: true}); | ||
expect(spy).to.have.been.calledTwice; | ||
}); | ||
|
||
it('passes optional autoClose prop to showInstructionsDialog', () => { | ||
wrapper = mount( | ||
<InstructionsDialogWrapper | ||
isOpen={false} | ||
showInstructionsDialog={spy} | ||
/> | ||
); | ||
expect(spy).not.to.have.been.called; | ||
wrapper.setProps({isOpen: true, autoClose: true}); | ||
expect(spy).to.have.been.calledOnce.and.calledWith(true); | ||
wrapper.setProps({isOpen: false}); | ||
expect(spy).to.have.been.calledOnce; | ||
wrapper.setProps({isOpen: true, autoClose: false}); | ||
expect(spy).to.have.been.calledTwice.and.calledWith(false); | ||
}); | ||
}); |
123 changes: 123 additions & 0 deletions
123
apps/test/unit/templates/instructions/InstructionsWithWorkspaceTest.jsx
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,123 @@ | ||
import $ from 'jquery'; | ||
import React from 'react'; | ||
import sinon from 'sinon'; | ||
import {shallow} from 'enzyme'; | ||
import {expect} from '../../../util/configuredChai'; | ||
import { | ||
UnwrappedInstructionsWithWorkspace as InstructionsWithWorkspace | ||
} from '@cdo/apps/templates/instructions/InstructionsWithWorkspace'; | ||
|
||
describe('InstructionsWithWorkspace', () => { | ||
it('renders instructions and code workspace', () => { | ||
const wrapper = shallow( | ||
<InstructionsWithWorkspace | ||
instructionsHeight={400} | ||
setInstructionsMaxHeightAvailable={() => {}} | ||
/> | ||
); | ||
expect(wrapper).to.have.descendants('Connect(TopInstructions)'); | ||
expect(wrapper).to.have.descendants('Connect(CodeWorkspaceContainer)'); | ||
}); | ||
|
||
it('initially does not know window width or height', () => { | ||
const wrapper = shallow( | ||
<InstructionsWithWorkspace | ||
instructionsHeight={400} | ||
setInstructionsMaxHeightAvailable={() => {}} | ||
/> | ||
); | ||
expect(wrapper.state()).to.deep.equal({ | ||
windowWidth: undefined, | ||
windowHeight: undefined | ||
}); | ||
}); | ||
|
||
describe('onResize', () => { | ||
let setInstructionsMaxHeightAvailable; | ||
|
||
beforeEach(() => { | ||
setInstructionsMaxHeightAvailable = sinon.spy(); | ||
|
||
sinon.stub($.fn, 'width').returns(1024); | ||
sinon.stub($.fn, 'height').returns(768); | ||
}); | ||
|
||
afterEach(() => { | ||
$.fn.width.restore(); | ||
$.fn.height.restore(); | ||
}); | ||
|
||
function setupComponent({instructionsHeight = 400, codeWorkspaceHeight = 100} = {}) { | ||
const wrapper = shallow( | ||
<InstructionsWithWorkspace | ||
instructionsHeight={instructionsHeight} | ||
setInstructionsMaxHeightAvailable={setInstructionsMaxHeightAvailable} | ||
/> | ||
); | ||
|
||
// Fake ref to inner object, since we're shallow rendering. | ||
wrapper.instance().codeWorkspaceContainer = { | ||
getWrappedInstance: () => ({ | ||
getRenderedHeight: () => codeWorkspaceHeight | ||
}) | ||
}; | ||
|
||
return wrapper; | ||
} | ||
|
||
it('does nothing if window size has not changed', () => { | ||
const wrapper = setupComponent(); | ||
|
||
wrapper.setState({ | ||
windowWidth: 640, | ||
windowHeight: 480 | ||
}); | ||
$.fn.width.returns(640); | ||
$.fn.height.returns(480); | ||
sinon.spy(wrapper.instance(), 'setState'); | ||
|
||
wrapper.instance().onResize(); | ||
expect(setInstructionsMaxHeightAvailable).not.to.have.been.called; | ||
expect(wrapper.instance().setState).not.to.have.been.called; | ||
}); | ||
|
||
it('handles resize', () => { | ||
const wrapper = setupComponent(); | ||
wrapper.instance().onResize(); | ||
expect(setInstructionsMaxHeightAvailable).to.have.been.calledOnce | ||
.and.calledWith(230); | ||
}); | ||
|
||
it('breakpoint in behavior at total height of 420 (meets all reserves)', () => { | ||
let wrapper; | ||
|
||
wrapper = setupComponent({instructionsHeight: 18, codeWorkspaceHeight: 400}); | ||
wrapper.instance().onResize(); | ||
expect(setInstructionsMaxHeightAvailable).to.have.been.calledWith(139); | ||
|
||
setInstructionsMaxHeightAvailable.reset(); | ||
|
||
wrapper = setupComponent({instructionsHeight: 19, codeWorkspaceHeight: 400}); | ||
wrapper.instance().onResize(); | ||
expect(setInstructionsMaxHeightAvailable).to.have.been.calledWith(140); | ||
|
||
setInstructionsMaxHeightAvailable.reset(); | ||
|
||
wrapper = setupComponent({instructionsHeight: 20, codeWorkspaceHeight: 400}); | ||
wrapper.instance().onResize(); | ||
expect(setInstructionsMaxHeightAvailable).to.have.been.calledWith(150); | ||
|
||
setInstructionsMaxHeightAvailable.reset(); | ||
|
||
wrapper = setupComponent({instructionsHeight: 21, codeWorkspaceHeight: 400}); | ||
wrapper.instance().onResize(); | ||
expect(setInstructionsMaxHeightAvailable).to.have.been.calledWith(151); | ||
}); | ||
|
||
it('skips callback if codeWorkspaceContainer is not initialized', () => { | ||
const wrapper = setupComponent({codeWorkspaceHeight: 0}); | ||
wrapper.instance().onResize(); | ||
expect(setInstructionsMaxHeightAvailable).not.to.have.been.called; | ||
}); | ||
}); | ||
}); |