mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 08:18:42 +00:00
* feat: review user templates from the admin page, with an approval setting * Review feedback * Review feedback 2 * Review feedback 3
124 lines
4.3 KiB
JavaScript
124 lines
4.3 KiB
JavaScript
import { flushPromises } from '@vue/test-utils'
|
|
import { afterEach, beforeEach, describe, expect, test } from 'vitest'
|
|
|
|
import { TestApp } from '@baserow/test/helpers/testApp'
|
|
import { ModalStub } from '@baserow/test/helpers/modalStub'
|
|
import { heldBack } from '@baserow/test/helpers/heldBack'
|
|
import MakeTemplatePublicModal from '@baserow/modules/core/components/template/MakeTemplatePublicModal'
|
|
|
|
const template = {
|
|
id: 3,
|
|
slug: 'sprint-tracker',
|
|
type: 'user',
|
|
name: 'Sprint Tracker',
|
|
state: 'private',
|
|
}
|
|
|
|
describe('MakeTemplatePublicModal', () => {
|
|
let testApp = null
|
|
|
|
beforeEach(() => {
|
|
testApp = new TestApp()
|
|
testApp.authenticate({ id: 1, first_name: 'Ada', username: 'ada@a.b' })
|
|
})
|
|
|
|
afterEach(async () => {
|
|
await testApp.afterEach()
|
|
})
|
|
|
|
const mountAndShow = async (props = { template }) => {
|
|
const wrapper = await testApp.mount(MakeTemplatePublicModal, {
|
|
props,
|
|
global: {
|
|
stubs: { Modal: ModalStub },
|
|
// Shows the parameters, so that the names in the text can be checked.
|
|
mocks: {
|
|
$t: (key, params) =>
|
|
params ? `${key} ${JSON.stringify(params)}` : key,
|
|
},
|
|
},
|
|
})
|
|
await wrapper.vm.show()
|
|
await flushPromises()
|
|
return wrapper
|
|
}
|
|
|
|
const button = (wrapper, label) =>
|
|
wrapper.findAll('button').find((button) => button.text() === label)
|
|
|
|
test('makes the template public with the consent once confirmed', async () => {
|
|
const row = { ...template, state: 'public' }
|
|
testApp.mock.onPatch('/templates/sprint-tracker/').reply(200, row)
|
|
const wrapper = await mountAndShow()
|
|
|
|
const description = wrapper.find('.user-template-modal__description')
|
|
expect(description.text()).toContain('“Sprint Tracker”')
|
|
expect(description.find('strong').text()).toBe('Ada')
|
|
|
|
await button(wrapper, 'makeTemplatePublicModal.makePublic').trigger('click')
|
|
await flushPromises()
|
|
|
|
expect(
|
|
testApp.mock.history.patch.map(({ data }) => JSON.parse(data))
|
|
).toStrictEqual([{ visibility: 'public', public_listing_consent: true }])
|
|
expect(wrapper.emitted('made-public')).toStrictEqual([[row]])
|
|
// The template shows as public, which needs no toast.
|
|
expect(testApp.store.state.toast.items).toHaveLength(0)
|
|
expect(wrapper.findComponent({ name: 'Modal' }).vm.open).toBe(false)
|
|
})
|
|
|
|
test.each([
|
|
[false, 'once an instance admin approves it', 'title', 'makePublic'],
|
|
[true, 'stays listed', 'resubmitTitle', 'submitForReviewAgain'],
|
|
])(
|
|
'asks to make public a template that needs review, with the review copy (listed: %s)',
|
|
async (listed, description, title, confirm) => {
|
|
const row = { ...template, state: 'in_review' }
|
|
testApp.mock.onPatch('/templates/sprint-tracker/').reply(200, row)
|
|
const wrapper = await mountAndShow({
|
|
template: {
|
|
...template,
|
|
state: 'rejected',
|
|
can_make_public: true,
|
|
make_public_needs_review: true,
|
|
listed,
|
|
},
|
|
})
|
|
|
|
expect(wrapper.find('.user-template-modal__title').text()).toBe(
|
|
`makeTemplatePublicModal.${title} {"name":"Sprint Tracker"}`
|
|
)
|
|
expect(
|
|
wrapper.find('.user-template-modal__description').text()
|
|
).toContain(description)
|
|
|
|
await button(wrapper, `makeTemplatePublicModal.${confirm}`).trigger(
|
|
'click'
|
|
)
|
|
await flushPromises()
|
|
|
|
expect(wrapper.emitted('made-public')).toStrictEqual([[row]])
|
|
expect(testApp.store.state.toast.items).toHaveLength(0)
|
|
}
|
|
)
|
|
|
|
test('sends one request when clicked twice, and stays open for another template', async () => {
|
|
const reply = heldBack()
|
|
testApp.mock.onPatch('/templates/sprint-tracker/').reply(reply.reply)
|
|
const wrapper = await mountAndShow()
|
|
|
|
const makePublic = button(wrapper, 'makeTemplatePublicModal.makePublic')
|
|
// Both clicks land before the button is disabled.
|
|
makePublic.trigger('click')
|
|
makePublic.trigger('click')
|
|
await flushPromises()
|
|
await wrapper.setProps({ template: { ...template, id: 4, slug: 'other' } })
|
|
reply.send([200, { ...template, state: 'public' }])
|
|
await flushPromises()
|
|
|
|
expect(testApp.mock.history.patch).toHaveLength(1)
|
|
expect(wrapper.emitted('made-public')).toHaveLength(1)
|
|
expect(wrapper.findComponent({ name: 'Modal' }).vm.open).toBe(true)
|
|
})
|
|
})
|