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

Commit

Permalink
fix: Don't keep the new lane title when the board is controlled (#249)
Browse files Browse the repository at this point in the history
  • Loading branch information
lourenci committed Feb 9, 2020
1 parent c590657 commit 442a9de
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 10 deletions.
6 changes: 2 additions & 4 deletions src/components/Board/components/DefaultLaneHeader/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,19 +47,17 @@ function useRenameMode(state) {

export default function({ children: lane, allowRemoveLane, onLaneRemove, allowRenameLane, onLaneRename }) {
const [renameMode, toggleRenameMode] = useRenameMode(false)
const [title, setTitle] = useState(lane.title)
const [titleInput, setTitleInput] = useState('')

function handleRenameLane(event) {
event.preventDefault()

onLaneRename(lane, titleInput)
setTitle(titleInput)
toggleRenameMode()
}

function handleRenameMode() {
setTitleInput(title)
setTitleInput(lane.title)
toggleRenameMode()
}

Expand All @@ -85,7 +83,7 @@ export default function({ children: lane, allowRemoveLane, onLaneRemove, allowRe
) : (
<>
<LaneTitle allowRenameLane={allowRenameLane} onClick={handleRenameMode}>
{title}
{lane.title}
</LaneTitle>
{allowRemoveLane && <span onClick={() => onLaneRemove(lane)}>×</span>}
</>
Expand Down
10 changes: 5 additions & 5 deletions src/components/Board/components/DefaultLaneHeader/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ describe('<DefaultLaneHeader />', () => {

describe('when the user moves the mouse over the title', () => {
it('does not show a mouse pointer', () => {
expect(subject.queryByText('Lane title')).not.toHaveStyle('cursor: pointer')
expect(subject.queryByText('Lane title')).not.toHaveStyle({ cursor: 'pointer' })
})
})

Expand All @@ -95,7 +95,7 @@ describe('<DefaultLaneHeader />', () => {

describe('when the user moves the mouse over the title', () => {
it('shows a mouse pointer', () => {
expect(subject.queryByText('Lane title')).toHaveStyle('cursor: pointer')
expect(subject.queryByText('Lane title')).toHaveStyle({ cursor: 'pointer' })
})
})

Expand Down Expand Up @@ -127,8 +127,8 @@ describe('<DefaultLaneHeader />', () => {
fireEvent.click(subject.queryByText('Rename', { selector: 'button' }))
})

it('toggles the input for the new lane title', () => {
expect(subject.queryByText('New title')).toBeInTheDocument()
it('toggles the input for the lane title', () => {
expect(subject.queryByText('Lane title')).toBeInTheDocument()
expect(subject.container.querySelector('input')).not.toBeInTheDocument()
})

Expand All @@ -143,7 +143,7 @@ describe('<DefaultLaneHeader />', () => {
fireEvent.click(subject.queryByText('Cancel', { selector: 'button' }))
})

it('cancels the renaming', () => {
it('toggles the input for the lane title', () => {
expect(subject.queryByText('Lane title')).toBeInTheDocument()
expect(subject.container.querySelector('input')).not.toBeInTheDocument()
})
Expand Down
8 changes: 7 additions & 1 deletion src/components/Board/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -456,6 +456,11 @@ describe('<Board />', () => {
fireEvent.click(subject.queryByText('Rename', { selector: 'button' }))
})

it('does not rename the lane', () => {
expect(subject.queryByText('Lane Backlog')).toBeInTheDocument()
expect(subject.queryByText('New title')).not.toBeInTheDocument()
})

it('calls the "onLaneRename" callback passing the lane to be renamed', () => {
expect(onLaneRename).toHaveBeenCalledTimes(1)
expect(onLaneRename).toHaveBeenCalledWith(
Expand Down Expand Up @@ -1135,7 +1140,8 @@ describe('<Board />', () => {
})

it('renames the lane', () => {
expect(subject.queryAllByTestId('lane')[0]).toHaveTextContent('New title')
expect(subject.queryByText('Lane Backlog')).not.toBeInTheDocument()
expect(subject.queryByText('New title')).toBeInTheDocument()
})

it('calls the "onLaneRename" callback passing both the updated board and the renamed lane', () => {
Expand Down

0 comments on commit 442a9de

Please sign in to comment.