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/urlResolution.spec.js
2024-10-17 15:49:51 +00:00

100 lines
2.6 KiB
JavaScript

import { resolveFormula } from '@baserow/modules/core/formula'
import resolveElementUrl from '@baserow/modules/builder/utils/urlResolution'
describe('resolveElementUrl tests', () => {
test('Should return empty resolvedContext with page navigation type where page is not found.', () => {
const element = {
navigation_type: 'page',
navigate_to_page_id: 42,
}
const builder = { pages: [{ id: 1 }] }
const result = resolveElementUrl(
element,
builder,
builder.pages,
resolveFormula,
'preview'
)
expect(result).toEqual('')
})
test('Should return resolvedContext with page navigation type where page is found and has no params.', () => {
const element = {
navigation_type: 'page',
navigate_to_page_id: 1,
page_parameters: [],
}
const builder = {
id: 123,
pages: [{ id: 1, path: '/contact-us/', path_params: [] }],
}
const result = resolveElementUrl(
element,
builder,
builder.pages,
resolveFormula,
'preview'
)
expect(result).toEqual('/builder/123/preview/contact-us/')
})
test('Should return resolvedContext with page navigation type where page is found and has params.', () => {
const element = {
navigation_type: 'page',
navigate_to_page_id: 1,
page_parameters: [{ name: 'id', value: "'10'" }],
}
const builder = {
id: 123,
pages: [
{
id: 1,
path: '/product/:id/',
path_params: [{ name: 'id', type: 'numeric' }],
},
],
}
const result = resolveElementUrl(
element,
builder,
builder.pages,
resolveFormula,
'preview'
)
expect(result).toEqual('/builder/123/preview/product/10/')
})
test('Should return resolvedContext for external custom navigation type.', () => {
const element = {
navigation_type: 'custom',
navigate_to_url: "'https://baserow.io'",
}
const builder = { pages: [] }
const result = resolveElementUrl(
element,
builder,
builder.pages,
resolveFormula,
'preview'
)
expect(result).toEqual('https://baserow.io')
})
test('Should return resolvedContext for internal custom navigation type.', () => {
const element = {
navigation_type: 'custom',
navigate_to_url: "'/contact/'",
}
const builder = { id: 123, pages: [] }
const result = resolveElementUrl(
element,
builder,
builder.pages,
resolveFormula,
'preview'
)
expect(result).toEqual('/builder/123/preview/contact/')
})
})