mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 00:08:25 +00:00
feat: add change events to Checkbox and Rating input elements (#6734)
This commit is contained in:
1 parent
a8b3afc390
commit
bbe7b9da07
12 files changed
+457
-26
No files matched your search
@@ -1514,6 +1514,9 @@ class RatingInputElementType(InputElementType):
|
||||
]
|
||||
simple_formula_fields = ["value", "label"]
|
||||
|
||||
def get_event_names(self, instance: RatingInputElement) -> List[str]:
|
||||
return [EventTypes.CHANGE.value]
|
||||
|
||||
class SerializedDict(ElementDict):
|
||||
label: BaserowFormulaObject
|
||||
required: bool
|
||||
@@ -1786,6 +1789,9 @@ class CheckboxElementType(InputElementType):
|
||||
serializer_field_names = ["label", "default_value", "required"]
|
||||
simple_formula_fields = ["label", "default_value"]
|
||||
|
||||
def get_event_names(self, instance: CheckboxElement) -> List[str]:
|
||||
return [EventTypes.CHANGE.value]
|
||||
|
||||
class SerializedDict(ElementDict):
|
||||
label: BaserowFormulaObject
|
||||
required: bool
|
||||
|
||||
+4
-2
@@ -168,6 +168,8 @@ def test_start_workflow_commits_history_before_scheduling(
|
||||
("simple_container", EventTypes.CLICK),
|
||||
("choice", EventTypes.CHANGE),
|
||||
("record_selector", EventTypes.CHANGE),
|
||||
("checkbox", EventTypes.CHANGE),
|
||||
("rating_input", EventTypes.CHANGE),
|
||||
],
|
||||
)
|
||||
def test_create_notification_workflow_action(
|
||||
@@ -348,8 +350,8 @@ def test_create_workflow_action_invalid_event(
|
||||
("record_selector", EventTypes.CLICK),
|
||||
("button", EventTypes.CHANGE),
|
||||
("input_text", EventTypes.CHANGE),
|
||||
("checkbox", EventTypes.CHANGE),
|
||||
("rating_input", EventTypes.CHANGE),
|
||||
("checkbox", EventTypes.CLICK),
|
||||
("rating_input", EventTypes.CLICK),
|
||||
],
|
||||
)
|
||||
def test_create_workflow_action_rejects_unsupported_change_event(
|
||||
|
||||
@@ -1765,6 +1765,12 @@ def test_element_type_get_event_names(data_fixture):
|
||||
assert get_event_names(button) == ["click"]
|
||||
assert get_event_names(choice) == ["change"]
|
||||
assert get_event_names(record_selector) == ["change"]
|
||||
checkbox = data_fixture.create_builder_checkbox_element(page=page)
|
||||
rating_input = data_fixture.create_builder_element(
|
||||
RatingInputElementType, page=page
|
||||
)
|
||||
assert get_event_names(checkbox) == ["change"]
|
||||
assert get_event_names(rating_input) == ["change"]
|
||||
assert get_event_names(form) == ["submit"]
|
||||
assert get_event_names(table) == [f"{button_field.uid}_click"]
|
||||
assert get_event_names(menu) == [f"{button_item_uid}_click"]
|
||||
|
||||
@@ -27,7 +27,7 @@ from baserow.core.graph.types import GraphPointPosition
|
||||
from baserow.core.utils import MirrorDict
|
||||
|
||||
|
||||
@pytest.fixture(params=["choice", "record_selector"])
|
||||
@pytest.fixture(params=["choice", "record_selector", "checkbox", "rating_input"])
|
||||
def change_action(data_fixture, request):
|
||||
user = data_fixture.create_user()
|
||||
draft = data_fixture.create_builder_application(user=user)
|
||||
@@ -62,11 +62,10 @@ def change_action(data_fixture, request):
|
||||
repeat = data_fixture.create_builder_repeat_element(
|
||||
page=page, data_source=record_source
|
||||
)
|
||||
element_kwargs = (
|
||||
{"data_source": option_source}
|
||||
if request.param == "record_selector"
|
||||
else {"options": [{"name": "Selected", "value": "selected"}]}
|
||||
)
|
||||
element_kwargs = {
|
||||
"choice": {"options": [{"name": "Selected", "value": "selected"}]},
|
||||
"record_selector": {"data_source": option_source},
|
||||
}.get(request.param, {})
|
||||
element = data_fixture.create_builder_element(
|
||||
type(element_type_registry.get(request.param)),
|
||||
page=page,
|
||||
@@ -75,9 +74,12 @@ def change_action(data_fixture, request):
|
||||
required=True,
|
||||
**element_kwargs,
|
||||
)
|
||||
selected = (
|
||||
str(option_rows[2].id) if request.param == "record_selector" else "selected"
|
||||
)
|
||||
selected, rendered = {
|
||||
"choice": ("selected", "selected"),
|
||||
"record_selector": (str(option_rows[2].id), str(option_rows[2].id)),
|
||||
"checkbox": (True, "true"),
|
||||
"rating_input": (3, "3"),
|
||||
}[request.param]
|
||||
service = data_fixture.create_local_baserow_upsert_row_service(
|
||||
integration=integration, table=output
|
||||
)
|
||||
@@ -103,6 +105,7 @@ def change_action(data_fixture, request):
|
||||
"output_field": output_fields[0],
|
||||
"action": action,
|
||||
"selected": selected,
|
||||
"rendered": rendered,
|
||||
}
|
||||
|
||||
|
||||
@@ -135,7 +138,7 @@ def test_public_change_action_reads_new_value_and_enclosing_record(
|
||||
fixture["output"]
|
||||
.get_model()
|
||||
.objects.values_list(fixture["output_field"].db_column, flat=True)
|
||||
) == [f"Beta:{fixture['selected']}"]
|
||||
) == [f"Beta:{fixture['rendered']}"]
|
||||
|
||||
|
||||
@pytest.mark.django_db
|
||||
|
||||
+8
@@ -43,6 +43,8 @@ from baserow.core.exceptions import PermissionDenied, UserNotInWorkspace
|
||||
("simple_container", EventTypes.CLICK),
|
||||
("choice", EventTypes.CHANGE),
|
||||
("record_selector", EventTypes.CHANGE),
|
||||
("checkbox", EventTypes.CHANGE),
|
||||
("rating_input", EventTypes.CHANGE),
|
||||
],
|
||||
)
|
||||
def test_create_workflow_action(data_fixture, element_type, event):
|
||||
@@ -117,6 +119,8 @@ def test_delete_workflow_action_no_permissions(data_fixture):
|
||||
("button", EventTypes.CLICK),
|
||||
("choice", EventTypes.CHANGE),
|
||||
("record_selector", EventTypes.CHANGE),
|
||||
("checkbox", EventTypes.CHANGE),
|
||||
("rating_input", EventTypes.CHANGE),
|
||||
],
|
||||
)
|
||||
def test_update_workflow_action(data_fixture, element_type, event):
|
||||
@@ -395,6 +399,8 @@ def test_dispatch_workflow_action_no_permissions(data_fixture):
|
||||
("simple_container", EventTypes.CLICK),
|
||||
("choice", EventTypes.CHANGE),
|
||||
("record_selector", EventTypes.CHANGE),
|
||||
("checkbox", EventTypes.CHANGE),
|
||||
("rating_input", EventTypes.CHANGE),
|
||||
],
|
||||
)
|
||||
def test_create_workflow_action_with_invalid_event(
|
||||
@@ -481,6 +487,8 @@ def test_create_workflow_action_without_element_only_accepts_static_events(
|
||||
("simple_container", EventTypes.CLICK),
|
||||
("choice", EventTypes.CHANGE),
|
||||
("record_selector", EventTypes.CHANGE),
|
||||
("checkbox", EventTypes.CHANGE),
|
||||
("rating_input", EventTypes.CHANGE),
|
||||
],
|
||||
)
|
||||
def test_update_workflow_action_with_invalid_event(
|
||||
|
||||
+9
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"type": "feature",
|
||||
"message": "Checkbox and Rating input elements can trigger actions when their value changes in the Application Builder.",
|
||||
"issue_origin": "github",
|
||||
"issue_number": 2748,
|
||||
"domain": "builder",
|
||||
"bullet_points": [],
|
||||
"created_at": "2026-11-16"
|
||||
}
|
||||
@@ -4,10 +4,11 @@
|
||||
:style="getStyleOverride('input')"
|
||||
>
|
||||
<ABCheckbox
|
||||
v-model="inputValue"
|
||||
:model-value="inputValue"
|
||||
:required="element.required"
|
||||
:read-only="isEditMode"
|
||||
@update:model-value="handleFormElementChange"
|
||||
:disabled="workflowActionsInProgress"
|
||||
@update:model-value="onSelectionChange"
|
||||
>
|
||||
<ABFormattedText
|
||||
:value="resolvedLabel"
|
||||
@@ -25,12 +26,12 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import formElement from '@baserow/modules/builder/mixins/formElement'
|
||||
import changeableFormElement from '@baserow/modules/builder/mixins/changeableFormElement'
|
||||
import { ensureString } from '@baserow/modules/core/utils/validator'
|
||||
|
||||
export default {
|
||||
name: 'CheckboxElement',
|
||||
mixins: [formElement],
|
||||
mixins: [changeableFormElement],
|
||||
computed: {
|
||||
resolvedLabel() {
|
||||
return ensureString(this.resolveFormula(this.element.label))
|
||||
|
||||
@@ -12,14 +12,15 @@
|
||||
:custom-color="resolveColor(element.color, colorVariables)"
|
||||
:rating-style="element.rating_style || 'star'"
|
||||
show-unselected
|
||||
@update="onRatingChange"
|
||||
:read-only="workflowActionsInProgress"
|
||||
@update="onSelectionChange"
|
||||
/>
|
||||
</ABFormGroup>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import Rating from '@baserow/modules/database/components/Rating'
|
||||
import formElement from '@baserow/modules/builder/mixins/formElement'
|
||||
import changeableFormElement from '@baserow/modules/builder/mixins/changeableFormElement'
|
||||
import { ensureString } from '@baserow/modules/core/utils/validator'
|
||||
import { useVuelidate } from '@vuelidate/core'
|
||||
import { required } from '@vuelidate/validators'
|
||||
@@ -29,7 +30,7 @@ export default {
|
||||
components: {
|
||||
Rating,
|
||||
},
|
||||
mixins: [formElement],
|
||||
mixins: [changeableFormElement],
|
||||
setup() {
|
||||
return { v$: useVuelidate() }
|
||||
},
|
||||
@@ -48,11 +49,5 @@ export default {
|
||||
validations() {
|
||||
return this.rules
|
||||
},
|
||||
methods: {
|
||||
onRatingChange(value) {
|
||||
this.inputValue = value
|
||||
this.handleFormElementChange()
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
@@ -2131,6 +2131,10 @@ export class CheckboxElementType extends FormElementType {
|
||||
return 'checkbox'
|
||||
}
|
||||
|
||||
getEvents(element) {
|
||||
return [new ChangeEvent({ app: this.app })]
|
||||
}
|
||||
|
||||
get name() {
|
||||
return this.app.$i18n.t('elementType.checkbox')
|
||||
}
|
||||
@@ -2721,6 +2725,10 @@ export class RatingInputElementType extends FormElementType {
|
||||
return 'rating_input'
|
||||
}
|
||||
|
||||
getEvents(element) {
|
||||
return [new ChangeEvent({ app: this.app })]
|
||||
}
|
||||
|
||||
get name() {
|
||||
return this.app.$i18n.t('elementType.ratingInput')
|
||||
}
|
||||
|
||||
+371
@@ -0,0 +1,371 @@
|
||||
import { reactive } from 'vue'
|
||||
import flushPromises from 'flush-promises'
|
||||
import { TestApp } from '@baserow/test/helpers/testApp'
|
||||
import CheckboxElement from '@baserow/modules/builder/components/elements/components/CheckboxElement.vue'
|
||||
import RatingInputElement from '@baserow/modules/builder/components/elements/components/RatingInputElement.vue'
|
||||
import PageElement from '@baserow/modules/builder/components/page/PageElement.vue'
|
||||
import { DATA_SCOPES } from '@baserow/modules/builder/constants'
|
||||
|
||||
const CASES = {
|
||||
checkbox: {
|
||||
component: CheckboxElement,
|
||||
initial: 'false',
|
||||
initialFormula: { default_value: { mode: 'raw', formula: 'false' } },
|
||||
// The first and second user changes and the value each one stores.
|
||||
changed: ['true', 'false'],
|
||||
// A click toggles the native checkbox, as a user would.
|
||||
change: async (wrapper) => {
|
||||
await wrapper.get('.ab-checkbox input').trigger('click')
|
||||
await flushPromises()
|
||||
},
|
||||
current: (wrapper) => wrapper.get('.ab-checkbox input').element.checked,
|
||||
initialValue: false,
|
||||
changedValue: true,
|
||||
isBlocked: (wrapper) =>
|
||||
wrapper.get('.ab-checkbox input').attributes('disabled') !== undefined,
|
||||
},
|
||||
rating_input: {
|
||||
component: RatingInputElement,
|
||||
initial: '1',
|
||||
initialFormula: { value: { mode: 'raw', formula: '1' } },
|
||||
changed: ['3', '4'],
|
||||
change: async (wrapper, step) => {
|
||||
await wrapper
|
||||
.findAll('.rating__star')
|
||||
[step === 0 ? 2 : 3].trigger('click')
|
||||
await flushPromises()
|
||||
},
|
||||
current: (wrapper) => wrapper.findAll('.rating__star--selected').length,
|
||||
initialValue: 1,
|
||||
changedValue: 3,
|
||||
isBlocked: (wrapper) =>
|
||||
!wrapper.get('.rating').classes().includes('editing'),
|
||||
},
|
||||
}
|
||||
|
||||
describe('Value change workflows', () => {
|
||||
let testApp
|
||||
|
||||
beforeEach(() => {
|
||||
testApp = new TestApp()
|
||||
})
|
||||
|
||||
afterEach(async () => {
|
||||
if (vi.isFakeTimers()) {
|
||||
await vi.runOnlyPendingTimersAsync()
|
||||
vi.useRealTimers()
|
||||
}
|
||||
vi.restoreAllMocks()
|
||||
await testApp.afterEach()
|
||||
})
|
||||
|
||||
const mountValueElement = async (
|
||||
type,
|
||||
{
|
||||
elementValues = {},
|
||||
mode = 'public',
|
||||
contextMode = mode,
|
||||
withForm = false,
|
||||
withRepeat = false,
|
||||
} = {}
|
||||
) => {
|
||||
const element = reactive({
|
||||
id: 12,
|
||||
type,
|
||||
page_id: 1,
|
||||
css_classes: 'qa-value',
|
||||
styles: {},
|
||||
style_background_file: null,
|
||||
visibility: 'all',
|
||||
label: { mode: 'raw', formula: 'Value' },
|
||||
required: false,
|
||||
max_value: 5,
|
||||
color: 'primary',
|
||||
rating_style: 'star',
|
||||
...CASES[type].initialFormula,
|
||||
...elementValues,
|
||||
})
|
||||
const form = {
|
||||
...element,
|
||||
id: 11,
|
||||
type: 'form_container',
|
||||
css_classes: 'qa-form',
|
||||
submit_button_label: { mode: 'raw', formula: 'Submit' },
|
||||
reset_initial_values_post_submission: true,
|
||||
}
|
||||
const repeat = {
|
||||
...element,
|
||||
id: 10,
|
||||
type: 'repeat',
|
||||
data_source_id: 2,
|
||||
schema_property: null,
|
||||
}
|
||||
const graph = { 12: {} }
|
||||
if (withForm) {
|
||||
graph[11] = { children: { '': [12] } }
|
||||
}
|
||||
if (withRepeat) {
|
||||
graph[10] = { children: { '': [withForm ? 11 : 12] } }
|
||||
}
|
||||
graph[0] = withRepeat ? 10 : withForm ? 11 : 12
|
||||
const page = reactive({
|
||||
id: 1,
|
||||
path: '/',
|
||||
path_params: [],
|
||||
query_params: [],
|
||||
shared: false,
|
||||
dataSources: [
|
||||
{
|
||||
id: 2,
|
||||
type: 'csv_file_reader',
|
||||
name: 'Records',
|
||||
schema: {
|
||||
type: 'array',
|
||||
items: {
|
||||
type: 'object',
|
||||
properties: {
|
||||
id: { type: 'number' },
|
||||
name: { type: 'string' },
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
],
|
||||
elements: [],
|
||||
workflowActions: [],
|
||||
graph,
|
||||
})
|
||||
const sharedPage = { id: 2, shared: true, elements: [], dataSources: [] }
|
||||
const builder = { id: 1, theme: {}, pages: [page, sharedPage] }
|
||||
for (const item of [
|
||||
...(withRepeat ? [repeat] : []),
|
||||
...(withForm ? [form] : []),
|
||||
element,
|
||||
]) {
|
||||
await testApp.store.dispatch('element/forceCreate', {
|
||||
page,
|
||||
element: item,
|
||||
})
|
||||
}
|
||||
if (withRepeat) {
|
||||
testApp.store.commit('elementContent/SET_CONTENT', {
|
||||
element: repeat,
|
||||
value: [
|
||||
{ id: 101, name: 'Outer Alpha' },
|
||||
{ id: 102, name: 'Outer Beta' },
|
||||
],
|
||||
})
|
||||
}
|
||||
await testApp.store.dispatch('builderWorkflowAction/forceCreate', {
|
||||
page,
|
||||
workflowAction: {
|
||||
id: 20,
|
||||
element_id: element.id,
|
||||
page_id: page.id,
|
||||
type: 'notification',
|
||||
event: 'change',
|
||||
order: 1,
|
||||
title: { formula: "get('form_data.12')" },
|
||||
description: withRepeat
|
||||
? { formula: "get('current_record.name')" }
|
||||
: { mode: 'raw', formula: 'Value changed' },
|
||||
},
|
||||
})
|
||||
if (withForm) {
|
||||
await testApp.store.dispatch('builderWorkflowAction/forceCreate', {
|
||||
page,
|
||||
workflowAction: {
|
||||
id: 21,
|
||||
element_id: form.id,
|
||||
page_id: page.id,
|
||||
type: 'notification',
|
||||
event: 'submit',
|
||||
order: 1,
|
||||
title: { mode: 'raw', formula: 'Form submitted' },
|
||||
description: { mode: 'raw', formula: '' },
|
||||
},
|
||||
})
|
||||
}
|
||||
const root = withForm ? form : element
|
||||
const wrapper = await testApp.mount(
|
||||
withForm ? PageElement : CASES[type].component,
|
||||
{
|
||||
props: { element: root },
|
||||
global: {
|
||||
provide: {
|
||||
workspace: {},
|
||||
builder,
|
||||
currentPage: page,
|
||||
elementPage: page,
|
||||
mode,
|
||||
applicationContext: {
|
||||
builder,
|
||||
page,
|
||||
element: root,
|
||||
mode: contextMode,
|
||||
dataScope: DATA_SCOPES.EXCLUDE_TARGET_SUBTREE,
|
||||
recordIndexPath: withRepeat ? [1] : [],
|
||||
...(withRepeat ? { recordId: 102 } : {}),
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
)
|
||||
await flushPromises()
|
||||
return { wrapper, element, page, builder }
|
||||
}
|
||||
|
||||
const notifications = () => testApp.store.getters['builderToast/all']
|
||||
const titles = () => notifications().map(({ title }) => title)
|
||||
|
||||
describe.each(Object.keys(CASES))('%s', (type) => {
|
||||
const { change, current, changed, initialValue, changedValue, isBlocked } =
|
||||
CASES[type]
|
||||
|
||||
test('runs one change workflow per user change with the new form value', async () => {
|
||||
const { wrapper } = await mountValueElement(type)
|
||||
expect(current(wrapper)).toBe(initialValue)
|
||||
expect(notifications()).toHaveLength(0)
|
||||
|
||||
await change(wrapper, 0)
|
||||
|
||||
expect(current(wrapper)).toBe(changedValue)
|
||||
expect(notifications()).toMatchObject([
|
||||
{ type: 'info-primary', title: changed[0], message: 'Value changed' },
|
||||
])
|
||||
|
||||
await change(wrapper, 1)
|
||||
|
||||
// Toasts are listed newest first.
|
||||
expect(titles()).toEqual([changed[1], changed[0]])
|
||||
})
|
||||
|
||||
test('exposes the changed value inside a form without firing on reset', async () => {
|
||||
const { wrapper } = await mountValueElement(type, { withForm: true })
|
||||
await change(wrapper, 0)
|
||||
expect(titles()).toEqual([changed[0]])
|
||||
|
||||
await wrapper
|
||||
.get('.form-container-element__submit-button button')
|
||||
.trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(current(wrapper)).toBe(initialValue)
|
||||
expect(titles()).toEqual(['Form submitted', changed[0]])
|
||||
})
|
||||
|
||||
test('reads the enclosing repeated record', async () => {
|
||||
const { wrapper } = await mountValueElement(type, { withRepeat: true })
|
||||
|
||||
await change(wrapper, 0)
|
||||
|
||||
expect(notifications()).toMatchObject([
|
||||
{ title: changed[0], message: 'Outer Beta' },
|
||||
])
|
||||
})
|
||||
|
||||
test.each(['editing', 'public'])(
|
||||
'does not run workflows in an editor copy rendered in %s mode',
|
||||
async (mode) => {
|
||||
const { wrapper } = await mountValueElement(type, {
|
||||
mode,
|
||||
contextMode: 'editing',
|
||||
withRepeat: true,
|
||||
})
|
||||
|
||||
await change(wrapper, 0)
|
||||
|
||||
expect(notifications()).toHaveLength(0)
|
||||
}
|
||||
)
|
||||
|
||||
test('does not fire on equal store updates or changed default formulas', async () => {
|
||||
const { wrapper, element, page, builder } = await mountValueElement(type)
|
||||
await change(wrapper, 0)
|
||||
expect(notifications()).toHaveLength(1)
|
||||
|
||||
await testApp.store.dispatch('formData/setFormData', {
|
||||
page,
|
||||
uniqueElementId: '12',
|
||||
payload: {
|
||||
value: changedValue,
|
||||
elementId: 12,
|
||||
type: type === 'checkbox' ? 'boolean' : 'number',
|
||||
isValid: true,
|
||||
},
|
||||
})
|
||||
await flushPromises()
|
||||
expect(notifications()).toHaveLength(1)
|
||||
|
||||
vi.useFakeTimers()
|
||||
const formulaKey = Object.keys(CASES[type].initialFormula)[0]
|
||||
await testApp.store.dispatch('element/forceUpdate', {
|
||||
builder,
|
||||
page,
|
||||
element,
|
||||
values: {
|
||||
[formulaKey]: {
|
||||
mode: 'raw',
|
||||
formula: type === 'checkbox' ? 'true' : '5',
|
||||
},
|
||||
},
|
||||
})
|
||||
await vi.advanceTimersByTimeAsync(600)
|
||||
await flushPromises()
|
||||
|
||||
expect(notifications()).toHaveLength(1)
|
||||
})
|
||||
|
||||
test('blocks changes until the current workflow completes', async () => {
|
||||
const actionType = testApp
|
||||
.getRegistry()
|
||||
.get('workflowAction', 'notification')
|
||||
const execute = actionType.execute.bind(actionType)
|
||||
let finish
|
||||
const pending = new Promise((resolve) => {
|
||||
finish = resolve
|
||||
})
|
||||
vi.spyOn(actionType, 'execute').mockImplementationOnce((args) => {
|
||||
const result = execute(args)
|
||||
return pending.then(() => result)
|
||||
})
|
||||
const { wrapper } = await mountValueElement(type)
|
||||
await change(wrapper, 0)
|
||||
expect(titles()).toEqual([changed[0]])
|
||||
expect(isBlocked(wrapper)).toBe(true)
|
||||
|
||||
await change(wrapper, 1)
|
||||
|
||||
expect(current(wrapper)).toBe(changedValue)
|
||||
expect(notifications()).toHaveLength(1)
|
||||
|
||||
finish()
|
||||
await flushPromises()
|
||||
expect(isBlocked(wrapper)).toBe(false)
|
||||
await change(wrapper, 1)
|
||||
|
||||
// Toasts are listed newest first.
|
||||
expect(titles()).toEqual([changed[1], changed[0]])
|
||||
})
|
||||
})
|
||||
|
||||
test('fires once when the checkbox label is clicked', async () => {
|
||||
const { wrapper } = await mountValueElement('checkbox')
|
||||
|
||||
await wrapper.get('.ab-checkbox__label').trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.get('.ab-checkbox input').element.checked).toBe(true)
|
||||
expect(titles()).toEqual(['true'])
|
||||
})
|
||||
|
||||
test('fires once when the selected rating is clicked to clear it', async () => {
|
||||
const { wrapper } = await mountValueElement('rating_input')
|
||||
|
||||
await wrapper.findAll('.rating__star')[0].trigger('click')
|
||||
await flushPromises()
|
||||
|
||||
expect(wrapper.findAll('.rating__star--selected')).toHaveLength(0)
|
||||
expect(titles()).toEqual(['0'])
|
||||
})
|
||||
})
|
||||
+1
-1
@@ -15,7 +15,7 @@ describe('CheckboxElement', () => {
|
||||
})
|
||||
|
||||
const mountCheckbox = async (label, { required = false } = {}) => {
|
||||
const page = reactive({ id: 1, elements: [] })
|
||||
const page = reactive({ id: 1, elements: [], workflowActions: [] })
|
||||
const builder = { id: 1, theme: { primary_color: '#ccc' }, pages: [page] }
|
||||
const mode = 'public'
|
||||
const element = {
|
||||
|
||||
+22
@@ -333,6 +333,28 @@ describe('Clickable containers', () => {
|
||||
expect(notifications()).toHaveLength(0)
|
||||
})
|
||||
|
||||
test('toggles a child checkbox without triggering a parent action', async () => {
|
||||
const { wrapper } = await mountTree({
|
||||
outerType,
|
||||
innerType,
|
||||
childType: 'checkbox',
|
||||
actionIds: [10, 11],
|
||||
elementValues: { default_value: { mode: 'raw', formula: 'false' } },
|
||||
})
|
||||
const checkbox = getElement(wrapper, 12)
|
||||
const input = checkbox.get('.ab-checkbox input')
|
||||
|
||||
await input.trigger('click')
|
||||
await flushPromises()
|
||||
expect(input.element.checked).toBe(true)
|
||||
|
||||
await checkbox.get('.ab-checkbox__label').trigger('click')
|
||||
await flushPromises()
|
||||
expect(input.element.checked).toBe(false)
|
||||
|
||||
expect(notifications()).toHaveLength(0)
|
||||
})
|
||||
|
||||
test('treats a read-only rating as noninteractive child content', async () => {
|
||||
const { wrapper } = await mountTree({
|
||||
outerType,
|
||||
|
||||
Reference in new issue
Block a user