Skip to content

Commit

Permalink
test: work on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
darthtrevino committed Mar 22, 2019
1 parent 5682439 commit 576d148
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 28 deletions.
Expand Up @@ -71,12 +71,9 @@ import Box from './components/Box'
/**
* Wraps a component into a DragDropContext that uses the TestBackend.
*/
function wrapInTestContext(DecoratedComponent) {
return (
<DragDropContextProvider backend={TestBackend}>
<DecoratedComponent {...this.props} />
</DragDropContextProvider>
)
export default function wrapInTestContext(DecoratedComponent) {
const TestStub = props => <DecoratedComponent {...props} />
return DragDropContext(TestBackend)(TestStub)
}

it('can be tested with the testing backend', () => {
Expand Down
5 changes: 3 additions & 2 deletions packages/examples-hooks/package.json
Expand Up @@ -27,8 +27,8 @@
"immutability-helper": "^3.0.0",
"lodash": "^4.17.11",
"query-string": "^6.3.0",
"react-dnd": "^7.3.2",
"react-dnd-html5-backend": "^7.2.0",
"react-dnd": "link:../react-dnd",
"react-dnd-html5-backend": "link:../react-dnd-html5-backend",
"react-frame-component": "^4.1.0"
},
"devDependencies": {
Expand All @@ -37,6 +37,7 @@
"npm-run-all": "^4.1.5",
"react": "link:../react-dnd/node_modules/react",
"react-dom": "link:../react-dnd/node_modules/react-dom",
"react-dnd-test-utils": "link:../react-dnd-test-utils",
"rimraf": "^2.6.3",
"typescript": "^3.3.3333"
},
Expand Down
6 changes: 3 additions & 3 deletions packages/examples/package.json
Expand Up @@ -27,8 +27,8 @@
"immutability-helper": "^3.0.0",
"lodash": "^4.17.11",
"query-string": "^6.3.0",
"react-dnd": "^7.3.2",
"react-dnd-html5-backend": "^7.2.0",
"react-dnd": "link:../react-dnd",
"react-dnd-html5-backend": "link:../react-dnd-html5-backend",
"react-frame-component": "^4.1.0"
},
"devDependencies": {
Expand All @@ -37,7 +37,7 @@
"npm-run-all": "^4.1.5",
"react": "link:../react-dnd/node_modules/react",
"react-dom": "link:../react-dnd/node_modules/react-dom",
"react-dnd-test-utils": "^0.0.0",
"react-dnd-test-utils": "link:../react-dnd-test-utils",
"rimraf": "^2.6.3",
"typescript": "^3.3.3333"
},
Expand Down
Expand Up @@ -4,22 +4,22 @@ import Box from '../Box'
import Dustbin from '../Dustbin'
import { DragDropContextProvider } from 'react-dnd'
import TestBackend from 'react-dnd-test-backend'
import { WrapInTestContext } from 'react-dnd-test-utils'

describe('Integration: Dustbin Single Target', () => {
it('can simulate a full drag and drop interaction', () => {
function DustbinWithBox() {
function TestCase() {
return (
<DragDropContextProvider backend={TestBackend}>
<div>
<Dustbin />
<Box name="test" />
</div>
</DragDropContextProvider>
<div>
<Dustbin />
<Box name="test" />
</div>
)
}
const WrappedTestCase = wrapInTestContext(TestCase)

// Render with the test context that uses the test backend
const root: any = TestUtils.renderIntoDocument(<DustbinWithBox />)
const root: any = TestUtils.renderIntoDocument(<WrappedTestCase />)

// Obtain a reference to the backend
const backend = root.getManager().getBackend()
Expand Down
3 changes: 2 additions & 1 deletion packages/react-dnd-test-utils/package.json
@@ -1,7 +1,8 @@
{
"name": "react-dnd-test-utils",
"version": "0.0.0",
"version": "7.3.2",
"license": "MIT",
"main": "lib/cjs/index.js",
"scripts": {
"clean": "rimraf lib",
"build:cjs": "tsc -b tsconfig.cjs.json",
Expand Down
11 changes: 4 additions & 7 deletions packages/react-dnd-test-utils/src/wrapInTestContext.tsx
@@ -1,11 +1,8 @@
import * as React from 'react'
import { DragDropContextProvider } from 'react-dnd'
import TestBackend from 'react-dnd-test-backend'
import { DragDropContext } from 'react-dnd'

export function wrapInTestContext(DecoratedComponent: any): any {
return (props: any) => (
<DragDropContextProvider backend={TestBackend}>
<DecoratedComponent {...props} />
</DragDropContextProvider>
)
export default function wrapInTestContext(DecoratedComponent: any): any {
const TestStub = (props: any) => <DecoratedComponent {...props} />
return DragDropContext(TestBackend)(TestStub)
}
2 changes: 1 addition & 1 deletion packages/react-dnd/package.json
Expand Up @@ -36,7 +36,7 @@
"npm-run-all": "^4.1.5",
"react": "^16.8.4",
"react-dom": "^16.8.4",
"react-dnd-test-utils": "^0.0.0",
"react-dnd-test-utils": "link:../react-dnd-test-utils",
"rimraf": "^2.6.3",
"ts-loader": "^5.3.3",
"typescript": "^3.3.3333",
Expand Down
18 changes: 18 additions & 0 deletions yarn.lock
Expand Up @@ -12155,6 +12155,24 @@ react-dev-utils@^4.2.1:
strip-ansi "3.0.1"
text-table "0.2.0"

"react-dnd-html5-backend@link:packages/react-dnd-html5-backend":
version "7.2.0"
dependencies:
dnd-core "^7.2.0"
lodash "^4.17.11"

"react-dnd-test-utils@link:packages/react-dnd-test-utils":
version "7.3.2"

"react-dnd@link:packages/react-dnd":
version "7.3.2"
dependencies:
dnd-core "^7.2.0"
hoist-non-react-statics "^3.3.0"
invariant "^2.1.0"
lodash "^4.17.11"
shallowequal "^1.1.0"

react-dom@^16.8.4:
version "16.8.4"
resolved "https://registry.yarnpkg.com/react-dom/-/react-dom-16.8.4.tgz#1061a8e01a2b3b0c8160037441c3bf00a0e3bc48"
Expand Down

0 comments on commit 576d148

Please sign in to comment.