Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Housekeeping #11

Merged
merged 32 commits into from
Oct 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
32 commits
Select commit Hold shift + click to select a range
a181b5f
update packages
colinrobertbrooks Oct 20, 2021
12da76a
add .npmignore
colinrobertbrooks Oct 20, 2021
88a9643
example
colinrobertbrooks Oct 20, 2021
b9eec7b
point example at local package
colinrobertbrooks Oct 20, 2021
296cf61
update README
colinrobertbrooks Oct 20, 2021
123887e
update package
colinrobertbrooks Oct 20, 2021
585fd21
add github workflow
colinrobertbrooks Oct 21, 2021
575f681
no lock file
colinrobertbrooks Oct 21, 2021
455e0c8
disable rule
colinrobertbrooks Oct 21, 2021
2e30099
update name
colinrobertbrooks Oct 21, 2021
1a13e22
update rule
colinrobertbrooks Oct 21, 2021
43c572b
add jest to devDependencies
colinrobertbrooks Oct 22, 2021
6a2db74
pin eslint-config-colinrobertbrooks
colinrobertbrooks Oct 22, 2021
7089700
add engines
colinrobertbrooks Oct 22, 2021
3d878e7
example: downgrade react for @atlaskit/css-reset@6.1.4
colinrobertbrooks Oct 22, 2021
4a71ab3
add example to github worklfow
colinrobertbrooks Oct 22, 2021
57ff11a
fix main.yml
colinrobertbrooks Oct 22, 2021
a360417
revise @testing-library/jest-dom import
colinrobertbrooks Oct 22, 2021
9fbe441
restore rule
colinrobertbrooks Oct 22, 2021
c559763
commit example package-lock.json
colinrobertbrooks Oct 22, 2021
1e91f7c
try file
colinrobertbrooks Oct 22, 2021
5bf4755
update workflow
colinrobertbrooks Oct 22, 2021
aa67beb
add es build
colinrobertbrooks Oct 22, 2021
52a88fb
point example at es build
colinrobertbrooks Oct 22, 2021
30fe7fa
reorder worklfow steps
colinrobertbrooks Oct 22, 2021
6c90f4c
revert workflow changes
colinrobertbrooks Oct 22, 2021
5bdcf6f
add @testing-library/jest-dom to devDependencies
colinrobertbrooks Oct 22, 2021
2697029
revise @testing-library/react import
colinrobertbrooks Oct 22, 2021
13d40ed
add react as a devDependency
colinrobertbrooks Oct 22, 2021
1f7dbed
add react-dom as a peerDependency
colinrobertbrooks Oct 22, 2021
b60166f
update names
colinrobertbrooks Oct 22, 2021
542f3dd
update name
colinrobertbrooks Oct 22, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 4 additions & 7 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
{
"extends": [
"colinrcummings",
"colinrcummings/jest",
"colinrcummings/prettier"
"colinrobertbrooks",
"colinrobertbrooks/jest",
"colinrobertbrooks/prettier"
],
"env": {
"browser": true
Expand All @@ -11,10 +11,7 @@
"import/no-unresolved": [
"error",
{
"ignore": [
"@testing-library/jest-dom/extend-expect",
"@testing-library/react"
]
"ignore": ["@testing-library/jest-dom"]
}
]
}
Expand Down
41 changes: 41 additions & 0 deletions .github/workflows/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
name: CI
on: [pull_request]
jobs:
build:
name: Verify react-beautiful-dnd-test-utils on Node ${{ matrix.node }} and ${{ matrix.os }}

runs-on: ${{ matrix.os }}
strategy:
matrix:
node: ['12.18.1']
os: [ubuntu-latest]

steps:
- name: Checkout repo
uses: actions/checkout@v2

- name: Use Node ${{ matrix.node }}
uses: actions/setup-node@v1
with:
node-version: ${{ matrix.node }}

- name: Install module dependencies (without cache)
uses: bahmutov/npm-install@v1
with:
useLockFile: false

- name: Validate module
run: npm run validate

- name: Build module
run: npm run build

- name: Install example app dependencies (without cache)
uses: bahmutov/npm-install@v1
with:
useLockFile: false
working-directory: ./example

- name: Test example app with built module
run: npm run test
working-directory: ./example
3 changes: 3 additions & 0 deletions .npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
example
other
src
4 changes: 2 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,13 +27,13 @@ npm install --save-dev react-beautiful-dnd-test-utils

## Supported versions of `rbd`

Version 3 of this library supports testing `rbd` version 12. Use version 2 of this library for testing `rbd` version 11.
Version 3 of this library supports testing `rbd` version 12+. Use version 2 of this library for testing `rbd` version 11.

## Usage

Currently supports moving a [`<Draggable />`](https://github.com/atlassian/react-beautiful-dnd/blob/master/docs/api/draggable.md) _n_ positions up or down inside a [`<Droppable />`](https://github.com/atlassian/react-beautiful-dnd/blob/master/docs/api/droppable.md).

See an [example test](https://github.com/colinrcummings/react-beautiful-dnd-test-utils-example/blob/master/src/App.test.js) in the [`react-beautiful-dnd-test-utils-example`](https://github.com/colinrcummings/react-beautiful-dnd-test-utils-example) repo.
See an [example test](./example/src/App.test.js).

## License

Expand Down
1 change: 1 addition & 0 deletions example/.env
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
SKIP_PREFLIGHT_CHECK=true
27 changes: 27 additions & 0 deletions example/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# react-beautiful-dnd-test-utils-example

A fork of the `working-board` branch of [react-beautiful-dnd-task-app](https://github.com/alexreardon/react-beautiful-dnd-task-app) tested with [react-beautiful-dnd-test-utils](https://github.com/colinrobertbrooks/react-beautiful-dnd-test-utils).

---

## Setup

Run `npm run build` in the root directory, then run`npm install`.
kayluhb marked this conversation as resolved.
Show resolved Hide resolved

colinrobertbrooks marked this conversation as resolved.
Show resolved Hide resolved
---

## Run the Task App

Run `npm start` and open [localhost:3000](http://localhost:3000/).
colinrobertbrooks marked this conversation as resolved.
Show resolved Hide resolved

---

## Tests

Run `npm test`.
colinrobertbrooks marked this conversation as resolved.
Show resolved Hide resolved

---

## Boilerplate

This project was bootstrapped with [Create React App](https://github.com/facebook/create-react-app).
36 changes: 36 additions & 0 deletions example/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
{
"name": "react-beautiful-dnd-test-utils-example",
"version": "3.2.1",
"private": true,
"scripts": {
"start": "react-scripts start",
"build": "react-scripts build",
"test": "react-scripts test"
},
"dependencies": {
"@atlaskit/css-reset": "^6.1.4",
"react": "^16.8.0",
"react-beautiful-dnd": "^13.1.0",
"react-dom": "^16.8.0",
"styled-components": "^5.3.3"
},
"devDependencies": {
"@sheerun/mutationobserver-shim": "^0.3.3",
"@testing-library/jest-dom": "^5.14.1",
"@testing-library/react": "^12.1.2",
"react-beautiful-dnd-test-utils": "file:../",
"react-scripts": "^4.0.3"
},
"browserslist": {
"production": [
">0.2%",
"not dead",
"not op_mini all"
],
"development": [
"last 1 chrome version",
"last 1 firefox version",
"last 1 safari version"
]
}
}
Binary file added example/public/favicon.ico
Binary file not shown.
16 changes: 16 additions & 0 deletions example/public/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta
name="viewport"
content="width=device-width, initial-scale=1, shrink-to-fit=no"
/>
<link rel="shortcut icon" href="%PUBLIC_URL%/favicon.ico" />
<title>React App</title>
</head>
<body>
<noscript> You need to enable JavaScript to run this app. </noscript>
<div id="root"></div>
</body>
</html>
12 changes: 12 additions & 0 deletions example/src/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
{
"rules": {
"import/extensions": "off",
"import/no-extraneous-dependencies": "off",
"import/no-unresolved": "off",
"max-classes-per-file": "off",
"no-shadow": "off",
"react/no-access-state-in-setstate": "off",
"react/prop-types": "off",
"react/state-in-constructor": "off"
}
}
128 changes: 128 additions & 0 deletions example/src/App.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,128 @@
import React from 'react';
import { DragDropContext, Droppable } from 'react-beautiful-dnd';
import styled from 'styled-components';
import Column from './Column';

const Container = styled.div`
display: flex;
`;

const reorder = (array, startIndex, endIndex) => {
const result = Array.from(array);
const [removed] = result.splice(startIndex, 1);
result.splice(endIndex, 0, removed);

return result;
};

class InnerList extends React.PureComponent {
render() {
const { column, taskMap, index } = this.props;
const tasks = column.taskIds.map(taskId => taskMap[taskId]);
return <Column column={column} tasks={tasks} index={index} />;
}
}

class App extends React.Component {
state = this.props.initialState;

onDragEnd = result => {
const { destination, source, draggableId, type } = result;

if (!destination) {
return;
}

if (
destination.droppableId === source.droppableId &&
destination.index === source.index
) {
return;
}

if (type === 'COLUMN') {
this.setState({
...this.state,
columnOrder: reorder(
this.state.columnOrder,
source.index,
destination.index
)
});
return;
}

const home = this.state.columns[source.droppableId];
const foreign = this.state.columns[destination.droppableId];

if (home === foreign) {
const newColumn = {
...home,
taskIds: reorder(home.taskIds, source.index, destination.index)
};

const newState = {
...this.state,
columns: {
...this.state.columns,
[newColumn.id]: newColumn
}
};

this.setState(newState);
return;
}

const homeTaskIds = Array.from(home.taskIds);
homeTaskIds.splice(source.index, 1);
const newHome = {
...home,
taskIds: homeTaskIds
};

const foreignTaskIds = Array.from(foreign.taskIds);
foreignTaskIds.splice(destination.index, 0, draggableId);
const newForeign = {
...foreign,
taskIds: foreignTaskIds
};

const newState = {
...this.state,
columns: {
...this.state.columns,
[newHome.id]: newHome,
[newForeign.id]: newForeign
}
};
this.setState(newState);
};

render() {
return (
<DragDropContext onDragEnd={this.onDragEnd}>
<Droppable droppableId="board" direction="horizontal" type="COLUMN">
{provided => (
<Container ref={provided.innerRef} {...provided.droppableProps}>
{this.state.columnOrder.map((columnId, index) => {
const column = this.state.columns[columnId];

return (
<InnerList
key={column.id}
column={column}
index={index}
taskMap={this.state.tasks}
/>
);
})}
{provided.placeholder}
</Container>
)}
</Droppable>
</DragDropContext>
);
}
}

export default App;
Loading