-
Notifications
You must be signed in to change notification settings - Fork 2k
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 #4697 from mattermost/pick-PR4694-MM-51842
Cherry Pick #4694 Backport: MM-51842: fix value-change detection in number properties
- Loading branch information
Showing
3 changed files
with
86 additions
and
1 deletion.
There are no files selected for viewing
13 changes: 13 additions & 0 deletions
13
webapp/src/properties/number/__snapshots__/number.test.tsx.snap
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,13 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`properties/number should match snapshot for number with empty value 1`] = ` | ||
<div> | ||
<input | ||
class="Editable octo-propertyvalue" | ||
placeholder="" | ||
style="width: 100%;" | ||
title="" | ||
value="" | ||
/> | ||
</div> | ||
`; |
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,72 @@ | ||
// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. | ||
// See LICENSE.txt for license information. | ||
|
||
import React, {ComponentProps} from 'react' | ||
import {render, screen} from '@testing-library/react' | ||
import {mocked} from 'jest-mock' | ||
|
||
import userEvent from '@testing-library/user-event' | ||
|
||
import {wrapIntl} from '../../testUtils' | ||
import {TestBlockFactory} from '../../test/testBlockFactory' | ||
import mutator from '../../mutator' | ||
|
||
import {Board, IPropertyTemplate} from '../..//blocks/board' | ||
import {Card} from '../../blocks/card' | ||
|
||
import NumberProperty from './property' | ||
import NumberEditor from './number' | ||
|
||
jest.mock('../../components/flashMessages') | ||
jest.mock('../../mutator') | ||
|
||
const mockedMutator = mocked(mutator) | ||
|
||
describe('properties/number', () => { | ||
let board: Board | ||
let card: Card | ||
let propertyTemplate: IPropertyTemplate | ||
let baseProps: ComponentProps<typeof NumberEditor> | ||
|
||
beforeEach(() => { | ||
board = TestBlockFactory.createBoard() | ||
card = TestBlockFactory.createCard() | ||
propertyTemplate = board.cardProperties[0] | ||
|
||
baseProps = { | ||
property: new NumberProperty(), | ||
card, | ||
board, | ||
propertyTemplate, | ||
propertyValue: '', | ||
readOnly: false, | ||
showEmptyPlaceholder: false, | ||
} | ||
}) | ||
|
||
it('should match snapshot for number with empty value', () => { | ||
const {container} = render( | ||
wrapIntl(( | ||
<NumberEditor | ||
{...baseProps} | ||
/> | ||
)), | ||
) | ||
expect(container).toMatchSnapshot() | ||
}) | ||
|
||
it('should fire change event when valid number value is entered', async () => { | ||
render( | ||
wrapIntl( | ||
<NumberEditor | ||
{...baseProps} | ||
/>, | ||
), | ||
) | ||
const value = '42' | ||
const input = screen.getByRole('textbox') | ||
userEvent.type(input, `${value}{Enter}`) | ||
|
||
expect(mockedMutator.changePropertyValue).toHaveBeenCalledWith(board.id, card, propertyTemplate.id, `${value}`) | ||
}) | ||
}) |
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