only display confirm on type change (#3234)

This commit is contained in:
Scott Bishel 2022-06-16 08:46:31 -06:00 committed by GitHub
parent 3a135a30e7
commit 5d320f092b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 6 additions and 129 deletions

View file

@ -1,99 +1,5 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP
exports[`components/cardDetail/CardDetailProperties cancel button in TypeorNameChange dialog should do nothing 1`] = `
<div>
<div
class="octo-propertylist CardDetailProperties"
>
<div
class="octo-propertyrow"
>
<div
aria-label="menuwrapper"
class="MenuWrapper"
role="button"
>
<div
class="octo-propertyname"
>
<button
class="Button"
type="button"
>
<span>
Owner
</span>
</button>
</div>
</div>
<div
class="octo-propertyvalue"
data-testid="select-non-editable"
tabindex="0"
>
<span
class="Label propColorDefault "
>
<span
class="Label-text"
>
Jean-Luc Picard
</span>
</span>
</div>
</div>
<div
class="octo-propertyrow"
>
<div
aria-label="menuwrapper"
class="MenuWrapper"
role="button"
>
<div
class="octo-propertyname"
>
<button
class="Button"
type="button"
>
<span>
MockStatus
</span>
</button>
</div>
</div>
<input
class="Editable octo-propertyvalue"
placeholder="Empty"
spellcheck="false"
style="width: 5px;"
title="1234"
value="1234"
/>
</div>
<div
class="octo-propertyname add-property"
>
<div
aria-label="menuwrapper"
class="MenuWrapper"
role="button"
>
<button
class="Button"
type="button"
>
<span>
+ Add a property
</span>
</button>
</div>
</div>
</div>
</div>
`;
exports[`components/cardDetail/CardDetailProperties cancel on delete dialog should do nothing 1`] = `
<div>
<div

View file

@ -169,15 +169,9 @@ describe('components/cardDetail/CardDetailProperties', () => {
const result = renderComponent()
// rename to "Owner-Renamed"
onPropertyRenameOpenConfirmationDialog(result.container)
onPropertyRenameNoConfirmationDialog(result.container)
const propertyTemplate = board.cardProperties[0]
const confirmButton = result.getByTitle('Change property')
expect(confirmButton).toBeDefined()
userEvent.click(confirmButton!)
// should be called once on confirming renaming the property
expect(mockedMutator.changePropertyTypeAndName).toBeCalledTimes(1)
expect(mockedMutator.changePropertyTypeAndName).toHaveBeenCalledWith(board, cards, propertyTemplate, 'select', 'Owner - Renamed')
@ -203,19 +197,6 @@ describe('components/cardDetail/CardDetailProperties', () => {
expect(template!.type).toBe('number')
})
it('cancel button in TypeorNameChange dialog should do nothing', () => {
const result = renderComponent()
const container = result.container
onPropertyRenameOpenConfirmationDialog(container)
const cancelButton = result.getByTitle('Cancel')
expect(cancelButton).toBeDefined()
userEvent.click(cancelButton!)
expect(container).toMatchSnapshot()
})
it('confirmation on delete dialog should delete the property', () => {
const result = renderComponent()
const container = result.container
@ -261,7 +242,7 @@ describe('components/cardDetail/CardDetailProperties', () => {
expect(confirmDialog).toBeDefined()
}
function onPropertyRenameOpenConfirmationDialog(container:HTMLElement) {
function onPropertyRenameNoConfirmationDialog(container:HTMLElement) {
const propertyLabel = container.querySelector('.MenuWrapper')
expect(propertyLabel).toBeDefined()
userEvent.click(propertyLabel!)
@ -271,8 +252,5 @@ describe('components/cardDetail/CardDetailProperties', () => {
expect(propertyNameInput).toBeDefined()
userEvent.type(propertyNameInput!, 'Owner - Renamed{enter}')
userEvent.click(propertyLabel!)
const confirmDialog = container.querySelector('.dialog.confirmation-dialog-box')
expect(confirmDialog).toBeDefined()
}
})

View file

@ -58,24 +58,17 @@ const CardDetailProperties = (props: Props) => {
const affectsNumOfCards:string = Calculations.countNotEmpty(cards, propertyTemplate, intl)
// if no card has this value set delete the property directly without warning
if (affectsNumOfCards === '0') {
// if only the name has changed, set the property without warning
if (affectsNumOfCards === '0' || oldType === newType) {
mutator.changePropertyTypeAndName(board, cards, propertyTemplate, newType, newName)
return
}
let subTextString = intl.formatMessage({
const subTextString = intl.formatMessage({
id: 'CardDetailProperty.property-name-change-subtext',
defaultMessage: 'type from "{oldPropType}" to "{newPropType}"',
}, {oldPropType: oldType, newPropType: newType})
if (propertyTemplate.name !== newName) {
subTextString = intl.formatMessage({
id: 'CardDetailProperty.property-type-change-subtext',
defaultMessage: 'name to "{newPropName}"',
}, {newPropName: newName})
}
setConfirmationDialogBox({
heading: intl.formatMessage({id: 'CardDetailProperty.confirm-property-type-change', defaultMessage: 'Confirm property type change'}),
subText: intl.formatMessage({
@ -101,7 +94,7 @@ const CardDetailProperties = (props: Props) => {
onClose: () => setShowConfirmationDialog(false),
})
// open confirmation dialog for property type or name change
// open confirmation dialog for property type change
setShowConfirmationDialog(true)
}