Skip to content
This repository has been archived by the owner on Oct 8, 2022. It is now read-only.

Commit

Permalink
Add spec for dragging carg
Browse files Browse the repository at this point in the history
  • Loading branch information
lourenci committed Apr 6, 2019
1 parent 7d6e183 commit 61c36c0
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 10 deletions.
13 changes: 8 additions & 5 deletions __mocks__/react-beautiful-dnd.js
@@ -1,9 +1,5 @@
import React from 'react'

const callbacks = {
onDragEnd: jest.fn()
}

function DragDropContext (props) {
callbacks.onDragEnd = props.onDragEnd

Expand All @@ -23,8 +19,15 @@ const draggableProvide = {
draggableProps: {},
dragHandleProps: {}
}
const draggableSnapshot = {
isDragging: false
}
function Draggable (props) {
return <>{props.children(draggableProvide)}</>
return <>{props.children(draggableProvide, draggableSnapshot)}</>
}

const callbacks = {
onDragEnd: jest.fn(),
isDragging: isDragging => { draggableSnapshot.isDragging = isDragging }
}
export { DragDropContext, Droppable, Draggable, callbacks }
23 changes: 18 additions & 5 deletions src/components/Board/components/Lane/components/Card/index.spec.js
@@ -1,30 +1,43 @@
import React from 'react'
import { render } from 'react-testing-library'
import Card from './'
import { callbacks } from 'react-beautiful-dnd'

describe('<Card />', () => {
let subject

beforeEach(() => {
function mount () {
const card = {
id: 1,
title: 'Card title',
description: 'Card content'
}

subject = render(<Card>{card}</Card>)
})
return subject
}
afterEach(() => { subject = undefined })

it('renders a card', () => {
expect(subject.container).toBeInTheDocument()
expect(mount().container).toBeInTheDocument()
})

it("renders the card's title", () => {
expect(subject.queryByText(/^Card title$/)).toBeInTheDocument()
expect(mount().queryByText(/^Card title$/)).toBeInTheDocument()
})

it("renders the card's description", () => {
expect(subject.queryByText(/^Card content$/)).toBeInTheDocument()
expect(mount().queryByText(/^Card content$/)).toBeInTheDocument()
})

describe('when the card is being dragging', () => {
beforeEach(() => {
callbacks.isDragging(true)
mount()
})

it('shows the card with a box shadow', () => {
expect(subject.queryByText(/^Card title$/).parentNode).toHaveStyle('box-shadow: 2px 2px grey')
})
})
})

0 comments on commit 61c36c0

Please sign in to comment.