1
0
mirror of https://gitlab.com/bramw/baserow.git synced 2024-11-22 07:42:36 +00:00
bramw_baserow/web-frontend/test/unit/builder/utils/params.spec.js
2024-10-17 15:49:51 +00:00

95 lines
2.6 KiB
JavaScript

import { pathParametersInError } from '@baserow/modules/builder/utils/params'
describe('Builder parameter util tests', () => {
describe('pathParametersInError', () => {
test('should return false when element is not a page navigation', () => {
const element = {
navigation_type: 'link',
navigate_to_page_id: 1,
}
const pages = [
{ id: 1, path_params: [] },
{ id: 2, path_params: [] },
]
const result = pathParametersInError(element, pages)
expect(result).toBe(false)
})
test('should return false when destinationPage is not found', () => {
const element = {
navigation_type: 'page',
navigate_to_page_id: 3,
}
const pages = [{ id: 1, path_params: [] }]
const result = pathParametersInError(element, pages)
expect(result).toBe(false)
})
test('should return false when page parameters and destinationPage path parameters match', () => {
const element = {
navigation_type: 'page',
navigate_to_page_id: 1,
page_parameters: [
{ name: 'param1', value: '10' },
{ name: 'param2', value: 'abc' },
],
}
const pages = [
{
id: 1,
path_params: [
{ name: 'param1', type: 'numeric' },
{ name: 'param2', type: 'text' },
],
},
]
const result = pathParametersInError(element, pages)
expect(result).toBe(false)
})
test('should return true when destinationPage path parameters length does not match page parameters length', () => {
const element = {
navigation_type: 'page',
navigate_to_page_id: 1,
page_parameters: [
{ name: 'param1', value: '10' },
{ name: 'param2', value: 'abc' },
],
}
const pages = [
{ id: 1, path_params: [{ name: 'param1', type: 'numeric' }] },
]
const result = pathParametersInError(element, pages)
expect(result).toBe(true)
})
test('should return true when page parameter name does not match destinationPage path parameters', () => {
const element = {
navigation_type: 'page',
navigate_to_page_id: 1,
page_parameters: [
{ name: 'param1', value: '10' },
{ name: 'param3', value: 'abc' },
],
}
const pages = [
{
id: 1,
path_params: [
{ name: 'param1', type: 'numeric' },
{ name: 'param2', type: 'text' },
],
},
]
const result = pathParametersInError(element, pages)
expect(result).toBe(true)
})
})
})