-
Notifications
You must be signed in to change notification settings - Fork 79
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2163 from coursemology-collab/allen/assessment-edit
Assessment edit page fixes
- Loading branch information
Showing
17 changed files
with
340 additions
and
66 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,55 @@ | ||
import React, { PropTypes } from 'react'; | ||
import shallowUntil from '../shallowUntil'; | ||
|
||
describe('#shallowUntil', () => { | ||
const Div = () => <div />; | ||
const hoc = Component => () => <Component />; | ||
|
||
it('shallow renders the current wrapper one level deep', () => { | ||
const EnhancedDiv = hoc(Div); | ||
const wrapper = shallowUntil(<EnhancedDiv />, 'Div'); | ||
expect(wrapper.contains(<div />)).toBeTruthy(); | ||
}); | ||
|
||
it('shallow renders the current wrapper several levels deep', () => { | ||
const EnhancedDiv = hoc(hoc(hoc(Div))); | ||
const wrapper = shallowUntil(<EnhancedDiv />, 'Div'); | ||
expect(wrapper.contains(<div />)).toBeTruthy(); | ||
}); | ||
|
||
it('shallow renders the current wrapper even if the selector never matches', () => { | ||
const EnhancedDiv = hoc(Div); | ||
const wrapper = shallowUntil(<EnhancedDiv />, 'NotDiv'); | ||
expect(wrapper.contains(<div />)).toBeTruthy(); | ||
}); | ||
|
||
it('stops shallow rendering when it encounters a DOM element', () => { | ||
const wrapper = shallowUntil(<div><Div /></div>, 'Div'); | ||
expect(wrapper.contains(<div><Div /></div>)).toBeTruthy(); | ||
}); | ||
|
||
describe('with context', () => { | ||
const Foo = () => <Div />; | ||
Foo.contextTypes = { open: PropTypes.bool.isRequired }; | ||
|
||
class Bar extends React.Component { | ||
static childContextTypes = { open: PropTypes.bool } | ||
getChildContext = () => ({ open: true }) | ||
render = () => <Foo /> | ||
} | ||
|
||
it('passes down context from the root component', () => { | ||
const EnhancedFoo = hoc(Foo); | ||
const wrapper = shallowUntil(<EnhancedFoo />, { context: { open: true } }, 'Foo'); | ||
expect(wrapper.context('open')).toEqual(true); | ||
expect(wrapper.contains(<Div />)).toBeTruthy(); | ||
}); | ||
|
||
it('passes down context from an intermediary component', () => { | ||
const EnhancedBar = hoc(Bar); | ||
const wrapper = shallowUntil(<EnhancedBar />, 'Foo'); | ||
expect(wrapper.context('open')).toEqual(true); | ||
expect(wrapper.contains(<Div />)).toBeTruthy(); | ||
}); | ||
}); | ||
}); |
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,41 @@ | ||
import { shallow } from 'enzyme'; | ||
|
||
// See https://github.com/airbnb/enzyme/issues/539 and the `until` helper was borrowed from there. | ||
function until(selector, {context} = this.options) { | ||
if (!selector || this.isEmptyRender() || typeof this.node.type === 'string') | ||
return this; | ||
|
||
const instance = this.instance(); | ||
if (instance.getChildContext) { | ||
context = { | ||
...context, | ||
...instance.getChildContext(), | ||
} | ||
} | ||
|
||
return this.is(selector) | ||
? this.shallow({context}) | ||
: until.call(this.shallow({context}), selector, {context}) | ||
} | ||
|
||
|
||
|
||
/** | ||
* Shallow renders the component until the component matches the selector. | ||
* This is useful when the component you want to test is nested inside another component. | ||
* example: | ||
* ``` | ||
* const component = <Provider> | ||
* <MyComponent /> | ||
* </Provider> | ||
* ``` | ||
* In the above case, `shallow(component)` will render the <Provider />, and | ||
* `shallowUntil(component, 'MyComponent')` will render <MyComponent /> | ||
*/ | ||
export default function shallowUntil(component, options, selector) { | ||
if (selector === undefined) { | ||
selector = options; | ||
options = undefined; | ||
} | ||
return until.call(shallow(component, options), selector); | ||
} |
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
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 was deleted.
Oops, something went wrong.
Oops, something went wrong.