diff --git a/webapp/src/components/__snapshots__/propertyValueElement.test.tsx.snap b/webapp/src/components/__snapshots__/propertyValueElement.test.tsx.snap new file mode 100644 index 000000000..5861999df --- /dev/null +++ b/webapp/src/components/__snapshots__/propertyValueElement.test.tsx.snap @@ -0,0 +1,151 @@ +// Jest Snapshot v1, https://goo.gl/fbAQLP + +exports[`components/propertyValueElement should match snapshot, date, array value 1`] = ` +
+
+ +
+
+`; + +exports[`components/propertyValueElement should match snapshot, multi-select 1`] = ` +
+
+ + value 1 + + + value 2 + +
+
+`; + +exports[`components/propertyValueElement should match snapshot, person, array value 1`] = ` +
+ +
+`; + +exports[`components/propertyValueElement should match snapshot, select 1`] = ` +
+
+ + + value 1 + +
+ +
+
+
+
+`; + +exports[`components/propertyValueElement should match snapshot, select, read-only 1`] = ` +
+
+ + + value 1 + + +
+
+`; + +exports[`components/propertyValueElement should match snapshot, url, array value 1`] = ` +
+ +
+`; + +exports[`components/propertyValueElement should match snapshot, url, array value 2`] = ` +
+ +
+`; diff --git a/webapp/src/components/propertyValueElement.test.tsx b/webapp/src/components/propertyValueElement.test.tsx new file mode 100644 index 000000000..7ed877c2a --- /dev/null +++ b/webapp/src/components/propertyValueElement.test.tsx @@ -0,0 +1,200 @@ +// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved. +// See LICENSE.txt for license information. + +import React from 'react' +import {render} from '@testing-library/react' +import '@testing-library/jest-dom' +import {IntlProvider} from 'react-intl' + +import 'isomorphic-fetch' +import {DndProvider} from 'react-dnd' +import {HTML5Backend} from 'react-dnd-html5-backend' + +import {IPropertyTemplate, IPropertyOption} from '../blocks/board' + +import {TestBlockFactory} from '../test/testBlockFactory' + +import PropertyValueElement from './propertyValueElement' + +const wrapProviders = (children: any) => { + return ( + + {children} + + ) +} + +describe('components/propertyValueElement', () => { + const board = TestBlockFactory.createBoard() + const card = TestBlockFactory.createCard(board) + const comments = TestBlockFactory.createComment(card) + + test('should match snapshot, select', async () => { + const propertyTemplate = board.fields.cardProperties.find((p) => p.id === 'property1') + const component = wrapProviders( + , + ) + + const {container} = render(component) + expect(container).toMatchSnapshot() + }) + + test('should match snapshot, select, read-only', async () => { + const propertyTemplate = board.fields.cardProperties.find((p) => p.id === 'property1') + const component = wrapProviders( + , + ) + + const {container} = render(component) + expect(container).toMatchSnapshot() + }) + + test('should match snapshot, multi-select', () => { + const options: IPropertyOption[] = [] + for (let i = 0; i < 3; i++) { + const propertyOption: IPropertyOption = { + id: `ms${i}`, + value: `value ${i}`, + color: 'propColorBrown', + } + options.push(propertyOption) + } + + const propertyTemplate: IPropertyTemplate = { + id: 'multiSelect', + name: 'MultiSelect', + type: 'multiSelect', + options, + } + card.fields.properties.multiSelect = ['ms1', 'ms2'] + const component = wrapProviders( + , + ) + + const {container} = render(component) + expect(container).toMatchSnapshot() + }) + + test('should match snapshot, url, array value', () => { + const propertyTemplate: IPropertyTemplate = { + id: 'property_url', + name: 'Property URL', + type: 'url', + options: [], + } + card.fields.properties.property_url = ['http://localhost'] + + const component = wrapProviders( + , + ) + + const {container} = render(component) + expect(container).toMatchSnapshot() + }) + + test('should match snapshot, url, array value', () => { + const propertyTemplate: IPropertyTemplate = { + id: 'property_url', + name: 'Property URL', + type: 'url', + options: [], + } + card.fields.properties.property_url = ['http://localhost'] + + const component = wrapProviders( + , + ) + + const {container} = render(component) + expect(container).toMatchSnapshot() + }) + + test('should match snapshot, person, array value', () => { + const propertyTemplate: IPropertyTemplate = { + id: 'text', + name: 'Generic Text', + type: 'text', + options: [], + } + card.fields.properties.person = ['value1', 'value2'] + + const component = wrapProviders( + , + ) + + const {container} = render(component) + expect(container).toMatchSnapshot() + }) + + test('should match snapshot, date, array value', () => { + const propertyTemplate: IPropertyTemplate = { + id: 'date', + name: 'Date', + type: 'date', + options: [], + } + card.fields.properties.date = ['invalid date'] + + const component = wrapProviders( + , + ) + const {container} = render(component) + expect(container).toMatchSnapshot() + }) +}) diff --git a/webapp/src/components/propertyValueElement.tsx b/webapp/src/components/propertyValueElement.tsx index 48929d161..622590e53 100644 --- a/webapp/src/components/propertyValueElement.tsx +++ b/webapp/src/components/propertyValueElement.tsx @@ -188,7 +188,7 @@ const PropertyValueElement = (props:Props): JSX.Element => { } else if (propertyTemplate.type === 'person') { return ( mutator.changePropertyValue(card, propertyTemplate.id, newValue)} /> @@ -200,14 +200,14 @@ const PropertyValueElement = (props:Props): JSX.Element => { return ( mutator.changePropertyValue(card, propertyTemplate.id, newValue)} /> ) } else if (propertyTemplate.type === 'url') { return ( { setValue(propertyValue)}