mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 08:18:42 +00:00
* fix: keep published page data when a refresh is refused * Review feedback
87 lines
2.6 KiB
JavaScript
87 lines
2.6 KiB
JavaScript
import MockAdapter from 'axios-mock-adapter'
|
|
|
|
describe('dataSourceContent store', () => {
|
|
let client
|
|
let mock
|
|
let store
|
|
|
|
beforeEach(() => {
|
|
const nuxtApp = useNuxtApp()
|
|
client = nuxtApp.$client
|
|
store = nuxtApp.$store
|
|
mock = new MockAdapter(client, { onNoMatch: 'throwException' })
|
|
})
|
|
|
|
afterEach(() => {
|
|
mock.restore()
|
|
vi.useRealTimers()
|
|
})
|
|
|
|
test('dispatches preview content through the builder-scoped URL', async () => {
|
|
const builder = { id: 123, _: { selected: false } }
|
|
const page = { id: 42, _: {}, contents: {} }
|
|
store.commit('application/SET_ITEMS', [builder])
|
|
store.commit('application/SET_SELECTED', builder)
|
|
await store.dispatch('publicBuilder/setPageMode', 'preview')
|
|
mock
|
|
.onPost('builder/preview/123/pages/42/dispatch-data-sources/', {
|
|
metadata: { page_parameter: 'value' },
|
|
})
|
|
.replyOnce(200, {})
|
|
|
|
await store.dispatch('dataSourceContent/fetchPageDataSourceContent', {
|
|
page,
|
|
data: { page_parameter: 'value' },
|
|
mode: 'preview',
|
|
})
|
|
|
|
expect(mock.history.post).toHaveLength(1)
|
|
})
|
|
|
|
test('a refused refresh clears the page content, ends loading and the next one loads', async () => {
|
|
vi.useFakeTimers()
|
|
await store.dispatch('publicBuilder/setPageMode', 'public')
|
|
const page = { id: 43, _: {}, contents: { 1: { name: 'Table' } } }
|
|
const url = 'builder/domains/published/page/43/dispatch-data-sources/'
|
|
const throttled = [429, { detail: 'Request was throttled.' }]
|
|
mock.onPost(url).replyOnce(...throttled)
|
|
mock.onPost(url).replyOnce(200, { 1: { name: 'Chair' } })
|
|
mock
|
|
.onPost('builder/domains/published/data-source/1/dispatch/')
|
|
.replyOnce(...throttled)
|
|
const refresh = async () => {
|
|
store.dispatch('dataSourceContent/debouncedFetchPageDataSourceContent', {
|
|
page,
|
|
data: { page_parameter: { q: 'chair' } },
|
|
mode: 'public',
|
|
})
|
|
await vi.runAllTimersAsync()
|
|
}
|
|
|
|
await refresh()
|
|
|
|
expect(page.contents).toEqual({})
|
|
expect(store.getters['dataSourceContent/getLoading'](page)).toBe(false)
|
|
expect(store.getters['builderToast/all']).toMatchObject([
|
|
{ type: 'error', title: 'builderToast.defaultTitle' },
|
|
])
|
|
|
|
await refresh()
|
|
|
|
expect(page.contents).toEqual({ 1: { name: 'Chair' } })
|
|
|
|
await expect(
|
|
store.dispatch('dataSourceContent/fetchPageDataSourceContentById', {
|
|
page,
|
|
dataSourceId: 1,
|
|
dispatchContext: {},
|
|
mode: 'public',
|
|
replace: true,
|
|
})
|
|
).rejects.toThrow()
|
|
|
|
expect(page.contents).toEqual({})
|
|
expect(store.getters['dataSourceContent/getLoading'](page)).toBe(false)
|
|
})
|
|
})
|