1
0
mirror of https://gitlab.com/bramw/baserow.git synced 2024-11-21 23:37:55 +00:00
bramw_baserow/web-frontend/test/unit/database/publicView.spec.js
2023-09-13 08:43:36 +00:00

92 lines
2.2 KiB
JavaScript

import { TestApp } from '@baserow/test/helpers/testApp'
import PublicGrid from '@baserow/modules/database/pages/publicView'
// Mock out debounce so we dont have to wait or simulate waiting for the various
// debounces in the search functionality.
jest.mock('lodash/debounce', () => jest.fn((fn) => fn))
describe('Public View Page Tests', () => {
let testApp = null
let mockServer = null
beforeAll(() => {
testApp = new TestApp()
mockServer = testApp.mockServer
})
afterEach(() => testApp.afterEach())
test('Can see a publicly shared grid view', async () => {
const slug = 'testSlug'
const gridViewName = 'my public grid view name'
givenAPubliclySharedGridViewWithSlug(gridViewName, slug)
const publicGridViewPage = await testApp.mount(PublicGrid, {
asyncDataParams: {
slug,
},
})
expect(publicGridViewPage.html()).toContain(gridViewName)
expect(publicGridViewPage.element).toMatchSnapshot()
})
test('Publicly shared view is not saved as a last visited view', async () => {
const slug = 'testSlug'
const gridViewName = 'my public grid view name'
givenAPubliclySharedGridViewWithSlug(gridViewName, slug)
await testApp.mount(PublicGrid, {
asyncDataParams: {
slug,
},
})
const allCookies = testApp.store.$cookies
const cookieValue = allCookies.get('defaultViewId')
expect(cookieValue.length).toBe(0)
})
function givenAPubliclySharedGridViewWithSlug(name, slug) {
const fields = [
{
id: 0,
name: 'Name',
type: 'text',
primary: true,
},
{
id: 1,
name: 'Last name',
type: 'text',
},
{
id: 2,
name: 'Notes',
type: 'long_text',
},
{
id: 3,
name: 'Active',
type: 'boolean',
},
]
const gridView = mockServer.createPublicGridView(slug, {
name,
fields,
})
mockServer.createPublicGridViewRows(slug, fields, [
{
id: 1,
order: 0,
field_1: 'name',
field_2: 'last_name',
field_3: 'notes',
field_4: false,
},
])
return { gridView }
}
})