mirror of
https://github.com/baserow/baserow.git
synced 2026-12-04 00:08:25 +00:00
feat: Suggest installing template when skipping onboarding (#5864)
This commit is contained in:
13 files changed
+537
-36
No files matched your search
+9
@@ -0,0 +1,9 @@
|
||||
{
|
||||
"type": "feature",
|
||||
"message": "Suggests installing a template when you skip the onboarding",
|
||||
"issue_origin": "github",
|
||||
"issue_number": null,
|
||||
"domain": "core",
|
||||
"bullet_points": [],
|
||||
"created_at": "2026-08-07"
|
||||
}
|
||||
@@ -2,6 +2,10 @@
|
||||
display: grid;
|
||||
grid-template-columns: repeat(3, minmax(0, 1fr));
|
||||
gap: 14px;
|
||||
|
||||
&.template-import-items--wide {
|
||||
grid-template-columns: repeat(4, minmax(0, 1fr));
|
||||
}
|
||||
}
|
||||
|
||||
.template-import-item {
|
||||
|
||||
@@ -93,6 +93,20 @@ export class OnboardingType extends Registerable {
|
||||
canSkip() {
|
||||
return false
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the user clicks on the cancel button while this step is active, before
|
||||
* the onboarding is actually cancelled. It gives the step the opportunity to offer an
|
||||
* alternative to cancelling, like choosing a template. Must resolve with `null` if
|
||||
* the onboarding must be cancelled as normal, or with an object containing the
|
||||
* `component` of the modal that must be shown, and optionally the `props` that are
|
||||
* passed into it. The modal must emit `selected` with the data of this step if the
|
||||
* onboarding must be completed with it, and `hidden` if the user dismissed it. It
|
||||
* can emit `cancel` if it offers a way to cancel the onboarding after all.
|
||||
*/
|
||||
async getCancelModal() {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export class MoreOnboardingType extends OnboardingType {
|
||||
|
||||
@@ -23,7 +23,7 @@
|
||||
type="danger"
|
||||
size="large"
|
||||
:loading="cancelling"
|
||||
@click="cancel"
|
||||
@click="forceCancel()"
|
||||
>{{ $t('onboarding.failedSkip') }}</Button
|
||||
>
|
||||
</div>
|
||||
@@ -100,6 +100,14 @@
|
||||
></component>
|
||||
</div>
|
||||
</template>
|
||||
<component
|
||||
:is="cancelModal.component"
|
||||
v-if="cancelModal"
|
||||
v-bind="cancelModal.props"
|
||||
@selected="cancelSelected"
|
||||
@cancel="forceCancel(false)"
|
||||
@hidden="cancelModal = null"
|
||||
></component>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
@@ -138,6 +146,7 @@ export default {
|
||||
reloading: false,
|
||||
message: null,
|
||||
component: null,
|
||||
cancelModal: null,
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
@@ -278,11 +287,53 @@ export default {
|
||||
}
|
||||
},
|
||||
/**
|
||||
* Called when the user clicks on the cancel button. This will stop the onboarding,
|
||||
* create an initial workspace, and mark it as completed.
|
||||
* Called when the user clicks on the cancel button. Before actually cancelling, the
|
||||
* step gets the opportunity to offer the user an alternative, like choosing a
|
||||
* template. If it doesn't, the onboarding is cancelled immediately.
|
||||
*/
|
||||
async cancel() {
|
||||
this.cancelling = true
|
||||
|
||||
let modal = null
|
||||
try {
|
||||
modal = await this.step.getCancelModal()
|
||||
} catch (error) {
|
||||
// Failing to offer an alternative must never block the user from leaving the
|
||||
// onboarding, so we're falling back on cancelling it.
|
||||
console.error(error)
|
||||
}
|
||||
|
||||
if (modal) {
|
||||
this.cancelModal = {
|
||||
stepType: this.step.getType(),
|
||||
component: markRaw(modal.component),
|
||||
props: modal.props || {},
|
||||
}
|
||||
this.cancelling = false
|
||||
return
|
||||
}
|
||||
|
||||
await this.forceCancel()
|
||||
},
|
||||
/**
|
||||
* Called when the user chose an alternative to cancelling the onboarding. The data
|
||||
* belongs to the step that offered the alternative, so that the onboarding can be
|
||||
* completed as if the user filled out that step.
|
||||
*/
|
||||
async cancelSelected(data) {
|
||||
const { stepType } = this.cancelModal
|
||||
this.cancelModal = null
|
||||
this.data = { ...this.data, [stepType]: data }
|
||||
await this.complete()
|
||||
},
|
||||
/**
|
||||
* Stops the onboarding, creates an initial workspace, and marks it as completed. A
|
||||
* modal offering an alternative can cancel with `showLoading = false` if it shows
|
||||
* a loading state of its own, because it stays mounted until the user is
|
||||
* redirected.
|
||||
*/
|
||||
async forceCancel(showLoading = true) {
|
||||
this.cancelling = showLoading
|
||||
try {
|
||||
const { data: workspace } = await WorkspaceService(
|
||||
this.$client
|
||||
|
||||
@@ -10,7 +10,10 @@
|
||||
:placeholder="$t('templateCategories.search')"
|
||||
class="margin-bottom-2"
|
||||
></FormInput>
|
||||
<div class="template-import-items">
|
||||
<div
|
||||
class="template-import-items"
|
||||
:class="{ 'template-import-items--wide': wide }"
|
||||
>
|
||||
<a
|
||||
v-for="template in templates"
|
||||
:key="template.id"
|
||||
@@ -31,12 +34,39 @@
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import uniqBy from 'lodash/uniqBy'
|
||||
import TemplateService from '@baserow/modules/core/services/template'
|
||||
import { notifyIf } from '@baserow/modules/core/utils/error'
|
||||
import { escapeRegExp } from '@baserow/modules/core/utils/string'
|
||||
|
||||
export default {
|
||||
name: 'TemplateImportForm',
|
||||
props: {
|
||||
// Can be provided if the templates have already been fetched, to avoid fetching
|
||||
// them a second time.
|
||||
providedCategories: {
|
||||
type: Array,
|
||||
required: false,
|
||||
default: null,
|
||||
},
|
||||
// Additionally moves the default template to the front, so that it's always
|
||||
// visible when it's selected.
|
||||
autoSelectDefault: {
|
||||
type: Boolean,
|
||||
required: false,
|
||||
default: false,
|
||||
},
|
||||
limit: {
|
||||
type: Number,
|
||||
required: false,
|
||||
default: 6,
|
||||
},
|
||||
wide: {
|
||||
type: Boolean,
|
||||
required: false,
|
||||
default: false,
|
||||
},
|
||||
},
|
||||
emits: ['selected-template'],
|
||||
data() {
|
||||
return {
|
||||
@@ -47,48 +77,88 @@ export default {
|
||||
}
|
||||
},
|
||||
computed: {
|
||||
databaseTemplates() {
|
||||
// Categories can contain the same templates, so they must be deduplicated. If
|
||||
// `open_application == null`, then it falls back on the normal behavior, which
|
||||
// is opening the first database. An `open_application` is typically set if an
|
||||
// application must be opened first, and the onboarding experience works best by
|
||||
// starting with a database, so we're filtering those out.
|
||||
const templates = this.categories.flatMap(
|
||||
(category) => category.templates
|
||||
)
|
||||
return uniqBy(templates, 'id').filter(
|
||||
(template) => template.open_application === null
|
||||
)
|
||||
},
|
||||
templates() {
|
||||
let allTemplates = []
|
||||
this.categories.forEach((category) => {
|
||||
category.templates.forEach((template) => {
|
||||
// Categories can have the same templates. We should not have duplicates.
|
||||
if (allTemplates.findIndex((t) => t.id === template.id) === -1) {
|
||||
allTemplates.push(template)
|
||||
}
|
||||
})
|
||||
})
|
||||
if (this.search) {
|
||||
return this.matchingTemplates(this.search).slice(0, this.limit)
|
||||
}
|
||||
|
||||
// A few selected templates have the keyword `onboarding`. These are shown when
|
||||
// no search query is provided.
|
||||
const search = this.search || 'onboarding'
|
||||
allTemplates = allTemplates
|
||||
.filter((template) => {
|
||||
// If `open_application == null`, then it falls back on the normal behavior,
|
||||
// which is opening the first database. An `open_application` is typically
|
||||
// set, if an application must be opened first. The onboarding experience
|
||||
// works best by starting with a database, so we're filtering those out.
|
||||
return template.open_application === null
|
||||
})
|
||||
.filter((template) => {
|
||||
const keywords = template.keywords.split(',')
|
||||
keywords.push(template.name)
|
||||
const regex = new RegExp('(' + escapeRegExp(search) + ')', 'i')
|
||||
return keywords.some((value) => value.match(regex))
|
||||
})
|
||||
// A few selected templates have the keyword `onboarding`. Those are the ones
|
||||
// that are suggested if the user isn't searching.
|
||||
const suggested = this.matchingTemplates('onboarding')
|
||||
// The default template doesn't necessarily have the `onboarding` keyword, so it's
|
||||
// added first to make sure the automatically selected one is visible.
|
||||
const defaultTemplates = this.autoSelectDefault
|
||||
? this.databaseTemplates.filter((template) => template.is_default)
|
||||
: []
|
||||
|
||||
return allTemplates.slice(0, 6)
|
||||
return uniqBy(
|
||||
[
|
||||
...defaultTemplates,
|
||||
...suggested,
|
||||
...this.sameCategoryTemplates(suggested),
|
||||
],
|
||||
'id'
|
||||
).slice(0, this.limit)
|
||||
},
|
||||
},
|
||||
async mounted() {
|
||||
try {
|
||||
const { data } = await TemplateService(this.$client).fetchAll()
|
||||
this.categories = data
|
||||
} catch (error) {
|
||||
notifyIf(error, 'templates')
|
||||
if (this.providedCategories !== null) {
|
||||
this.categories = this.providedCategories
|
||||
} else {
|
||||
try {
|
||||
const { data } = await TemplateService(this.$client).fetchAll()
|
||||
this.categories = data
|
||||
} catch (error) {
|
||||
notifyIf(error, 'templates')
|
||||
}
|
||||
}
|
||||
this.loading = false
|
||||
|
||||
if (this.autoSelectDefault && this.templates.length > 0) {
|
||||
this.selectTemplate(this.templates[0])
|
||||
}
|
||||
},
|
||||
methods: {
|
||||
matchingTemplates(search) {
|
||||
const regex = new RegExp('(' + escapeRegExp(search) + ')', 'i')
|
||||
return this.databaseTemplates.filter((template) =>
|
||||
[...template.keywords.split(','), template.name].some((value) =>
|
||||
value.match(regex)
|
||||
)
|
||||
)
|
||||
},
|
||||
/**
|
||||
* There can be fewer suggestions than can be shown. The remaining spots are filled
|
||||
* up with the templates of the categories the suggestions are in, because the other
|
||||
* categories can contain templates that only demonstrate a specific feature.
|
||||
*/
|
||||
sameCategoryTemplates(templates) {
|
||||
const ids = new Set(templates.map((template) => template.id))
|
||||
const relatedIds = new Set(
|
||||
this.categories
|
||||
.filter((category) =>
|
||||
category.templates.some((template) => ids.has(template.id))
|
||||
)
|
||||
.flatMap((category) => category.templates)
|
||||
.map((template) => template.id)
|
||||
)
|
||||
return this.databaseTemplates.filter((template) =>
|
||||
relatedIds.has(template.id)
|
||||
)
|
||||
},
|
||||
selectTemplate(template) {
|
||||
this.selectedTemplate = template.id
|
||||
this.$emit('selected-template', template)
|
||||
|
||||
@@ -0,0 +1,77 @@
|
||||
<template>
|
||||
<Modal ref="modal" wide @hidden="$emit('hidden')">
|
||||
<h2 class="box__title">
|
||||
{{ $t('templateOnboardingCancelModal.title') }}
|
||||
</h2>
|
||||
<p>{{ $t('templateOnboardingCancelModal.description') }}</p>
|
||||
<TemplateImportForm
|
||||
:provided-categories="categories"
|
||||
auto-select-default
|
||||
wide
|
||||
:limit="8"
|
||||
@selected-template="selectTemplate"
|
||||
></TemplateImportForm>
|
||||
<div class="margin-top-3">
|
||||
<Button
|
||||
ph-autocapture="onboarding-cancel-template-continue"
|
||||
type="primary"
|
||||
size="large"
|
||||
full-width
|
||||
:disabled="selectedTemplate === null"
|
||||
:loading="installing"
|
||||
@click="install()"
|
||||
>{{ $t('templateOnboardingCancelModal.continue') }}</Button
|
||||
>
|
||||
</div>
|
||||
</Modal>
|
||||
</template>
|
||||
|
||||
<script>
|
||||
import modal from '@baserow/modules/core/mixins/modal'
|
||||
import TemplateImportForm from '@baserow/modules/database/components/onboarding/TemplateImportForm'
|
||||
|
||||
export default {
|
||||
name: 'TemplateOnboardingCancelModal',
|
||||
components: { TemplateImportForm },
|
||||
mixins: [modal],
|
||||
props: {
|
||||
categories: {
|
||||
type: Array,
|
||||
required: true,
|
||||
},
|
||||
// The `databaseOnboardingStep` type the emitted data belongs to. Note that this is
|
||||
// not the same as the `onboarding` step type the data is stored under.
|
||||
databaseStepType: {
|
||||
type: String,
|
||||
required: true,
|
||||
},
|
||||
},
|
||||
emits: ['selected', 'hidden'],
|
||||
data() {
|
||||
return {
|
||||
selectedTemplate: null,
|
||||
installing: false,
|
||||
}
|
||||
},
|
||||
mounted() {
|
||||
this.show()
|
||||
},
|
||||
beforeUnmount() {
|
||||
// The parent unmounts this component when the onboarding continues, so the modal
|
||||
// must clean up after itself without emitting that the user dismissed it.
|
||||
this.hide(false)
|
||||
},
|
||||
methods: {
|
||||
selectTemplate(template) {
|
||||
this.selectedTemplate = template
|
||||
},
|
||||
install() {
|
||||
this.installing = true
|
||||
this.$emit('selected', {
|
||||
type: this.databaseStepType,
|
||||
template: this.selectedTemplate,
|
||||
})
|
||||
},
|
||||
},
|
||||
}
|
||||
</script>
|
||||
@@ -1,6 +1,7 @@
|
||||
import { Registerable } from '@baserow/modules/core/registry'
|
||||
import AirtableImportForm from '@baserow/modules/database/components/airtable/AirtableImportForm'
|
||||
import TemplateImportForm from '@baserow/modules/database/components/onboarding/TemplateImportForm'
|
||||
import TemplateOnboardingCancelModal from '@baserow/modules/database/components/onboarding/TemplateOnboardingCancelModal'
|
||||
import DatabaseTemplatePreview from '@baserow/modules/database/components/onboarding/DatabaseTemplatePreview'
|
||||
import { DatabaseOnboardingType } from '@baserow/modules/database/onboardingTypes'
|
||||
import { DatabaseApplicationType } from '@baserow/modules/database/applicationTypes'
|
||||
@@ -123,6 +124,17 @@ export class DatabaseOnboardingStepType extends Registerable {
|
||||
getCompletedRoute(data, responses) {
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Called when the user cancels the onboarding, before it's actually cancelled. Can
|
||||
* return an object containing the `component` of a modal offering this step type as
|
||||
* an alternative to cancelling, and optionally the `props` passed into it. The modal
|
||||
* must emit `selected` with the step data, and `hidden` if the user dismissed it. It
|
||||
* can emit `cancel` if it offers a way to cancel the onboarding after all.
|
||||
*/
|
||||
async getCancelModal() {
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export class ScratchDatabaseOnboardingStepType extends DatabaseOnboardingStepType {
|
||||
@@ -279,6 +291,30 @@ export class TemplateDatabaseOnboardingStepType extends DatabaseOnboardingStepTy
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Cancelling the onboarding results in an empty workspace, which doesn't help the
|
||||
* user to get started. Installing a template does, so it's offered as an alternative
|
||||
* as long as the instance actually has templates.
|
||||
*/
|
||||
async getCancelModal() {
|
||||
if (!this.isVisible()) {
|
||||
return null
|
||||
}
|
||||
|
||||
const { data: categories } = await TemplateService(
|
||||
this.app.$client
|
||||
).fetchAll()
|
||||
|
||||
if (categories.every((category) => category.templates.length === 0)) {
|
||||
return null
|
||||
}
|
||||
|
||||
return {
|
||||
component: TemplateOnboardingCancelModal,
|
||||
props: { categories, databaseStepType: this.getType() },
|
||||
}
|
||||
}
|
||||
|
||||
async completeAfterWorkspace(workspace, stepData) {
|
||||
const template = stepData.template
|
||||
const { data: job } = await TemplateService(this.app.$client).asyncInstall(
|
||||
|
||||
@@ -1150,6 +1150,11 @@
|
||||
"template": "Template",
|
||||
"workspaceName": "{name}'s workspace"
|
||||
},
|
||||
"templateOnboardingCancelModal": {
|
||||
"title": "Select a template to get started",
|
||||
"description": "To skip the onboarding, select one of the templates below. Starting with a template is the best way to get to know Baserow because it sets up tables, fields and example data for you. You can always change or delete it later.",
|
||||
"continue": "Use this template"
|
||||
},
|
||||
"ViewFilterTypeDateUpgradeToMultiStep": {
|
||||
"migrateButtonText": "Migrate to multi-step date filter",
|
||||
"migrateButtonTooltip": "New filter available. Click to upgrade. It works the same."
|
||||
|
||||
@@ -117,6 +117,21 @@ export class DatabaseOnboardingType extends OnboardingType {
|
||||
}
|
||||
return null
|
||||
}
|
||||
|
||||
async getCancelModal() {
|
||||
// No type has been chosen yet at this point, so every step type gets the chance to
|
||||
// offer an alternative to cancelling the onboarding.
|
||||
const stepTypes = this.app.$registry.getOrderedList(
|
||||
'databaseOnboardingStep'
|
||||
)
|
||||
for (const stepType of stepTypes) {
|
||||
const modal = await stepType.getCancelModal()
|
||||
if (modal) {
|
||||
return modal
|
||||
}
|
||||
}
|
||||
return null
|
||||
}
|
||||
}
|
||||
|
||||
export class DatabaseScratchTrackOnboardingType extends OnboardingType {
|
||||
|
||||
@@ -0,0 +1,12 @@
|
||||
export function createTemplate(id, name, values = {}) {
|
||||
return {
|
||||
id,
|
||||
name,
|
||||
slug: name.toLowerCase(),
|
||||
icon: 'iconoir-table',
|
||||
keywords: 'onboarding',
|
||||
open_application: null,
|
||||
is_default: false,
|
||||
...values,
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import { flushPromises } from '@vue/test-utils'
|
||||
|
||||
import { TestApp } from '@baserow/test/helpers/testApp'
|
||||
import TemplateImportForm from '@baserow/modules/database/components/onboarding/TemplateImportForm'
|
||||
import { createTemplate } from '@baserow/test/unit/database/components/onboarding/helpers'
|
||||
|
||||
describe('TemplateImportForm', () => {
|
||||
let testApp = null
|
||||
|
||||
beforeEach(() => {
|
||||
testApp = new TestApp()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
testApp.afterEach()
|
||||
})
|
||||
|
||||
const categories = [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Category',
|
||||
templates: [
|
||||
...[1, 2, 3, 4, 5, 6, 7].map((id) =>
|
||||
createTemplate(id, `Suggested ${id}`)
|
||||
),
|
||||
createTemplate(8, 'Default', { keywords: 'crm', is_default: true }),
|
||||
createTemplate(9, 'Application', {
|
||||
keywords: 'crm',
|
||||
open_application: 12,
|
||||
}),
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
const mount = async (props = {}) => {
|
||||
const wrapper = await testApp.mount(TemplateImportForm, {
|
||||
propsData: { providedCategories: categories, ...props },
|
||||
})
|
||||
await flushPromises()
|
||||
return wrapper
|
||||
}
|
||||
|
||||
const names = (wrapper) =>
|
||||
wrapper.findAll('.template-import-item').map((item) => item.text())
|
||||
|
||||
test('suggests the first six templates with the onboarding keyword', async () => {
|
||||
const wrapper = await mount()
|
||||
|
||||
expect(names(wrapper)).toStrictEqual([
|
||||
'Suggested 1',
|
||||
'Suggested 2',
|
||||
'Suggested 3',
|
||||
'Suggested 4',
|
||||
'Suggested 5',
|
||||
'Suggested 6',
|
||||
])
|
||||
expect(wrapper.emitted()['selected-template']).toBeUndefined()
|
||||
})
|
||||
|
||||
test('searching also finds templates without the onboarding keyword', async () => {
|
||||
const wrapper = await mount()
|
||||
|
||||
await wrapper.find('input').setValue('crm')
|
||||
|
||||
// The template that must open an application is never shown.
|
||||
expect(names(wrapper)).toStrictEqual(['Default'])
|
||||
})
|
||||
})
|
||||
+102
@@ -0,0 +1,102 @@
|
||||
import { flushPromises } from '@vue/test-utils'
|
||||
|
||||
import { TestApp } from '@baserow/test/helpers/testApp'
|
||||
import TemplateOnboardingCancelModal from '@baserow/modules/database/components/onboarding/TemplateOnboardingCancelModal'
|
||||
import TemplateImportForm from '@baserow/modules/database/components/onboarding/TemplateImportForm'
|
||||
import { createTemplate } from '@baserow/test/unit/database/components/onboarding/helpers'
|
||||
|
||||
describe('TemplateOnboardingCancelModal', () => {
|
||||
let testApp = null
|
||||
|
||||
beforeEach(() => {
|
||||
testApp = new TestApp()
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
testApp.afterEach()
|
||||
})
|
||||
|
||||
const categories = [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Category',
|
||||
templates: [
|
||||
createTemplate(1, 'First'),
|
||||
createTemplate(2, 'Second'),
|
||||
// Just like the real default template, this one doesn't have the `onboarding`
|
||||
// keyword.
|
||||
createTemplate(3, 'Default', { keywords: 'project', is_default: true }),
|
||||
],
|
||||
},
|
||||
]
|
||||
|
||||
const mount = async (props = { categories }) => {
|
||||
const wrapper = await testApp.mount(TemplateOnboardingCancelModal, {
|
||||
propsData: { databaseStepType: 'template', ...props },
|
||||
// The modal content is teleported into the body, and the globally stubbed
|
||||
// teleport doesn't keep the content interactive.
|
||||
global: { stubs: { Teleport: false } },
|
||||
})
|
||||
await flushPromises()
|
||||
return wrapper
|
||||
}
|
||||
|
||||
const templateItems = (wrapper) =>
|
||||
wrapper.findComponent(TemplateImportForm).findAll('.template-import-item')
|
||||
|
||||
test('shows the default template first and selects it', async () => {
|
||||
const wrapper = await mount()
|
||||
|
||||
const items = templateItems(wrapper)
|
||||
expect(items).toHaveLength(3)
|
||||
expect(items[0].text()).toBe('Default')
|
||||
expect(items[0].classes()).toContain('template-import-item--active')
|
||||
expect(items[1].classes()).not.toContain('template-import-item--active')
|
||||
})
|
||||
|
||||
test('emits the selected template when continuing', async () => {
|
||||
const wrapper = await mount()
|
||||
|
||||
await wrapper.findComponent({ name: 'Button' }).trigger('click')
|
||||
|
||||
expect(wrapper.emitted().selected).toHaveLength(1)
|
||||
expect(wrapper.emitted().selected[0][0].type).toBe('template')
|
||||
expect(wrapper.emitted().selected[0][0].template.id).toBe(3)
|
||||
})
|
||||
|
||||
test('emits the chosen template instead of the default one', async () => {
|
||||
const wrapper = await mount()
|
||||
|
||||
await templateItems(wrapper)[1].trigger('click')
|
||||
await wrapper.findComponent({ name: 'Button' }).trigger('click')
|
||||
|
||||
expect(wrapper.emitted().selected[0][0].template.id).toBe(1)
|
||||
})
|
||||
|
||||
test('fills up to eight templates with the related categories', async () => {
|
||||
const wrapper = await mount({
|
||||
categories: [
|
||||
{
|
||||
id: 1,
|
||||
name: 'Related',
|
||||
templates: [
|
||||
createTemplate(1, 'Curated'),
|
||||
...[2, 3, 4, 5, 6, 7, 8, 9].map((id) =>
|
||||
createTemplate(id, `Related ${id}`, { keywords: 'other' })
|
||||
),
|
||||
],
|
||||
},
|
||||
{
|
||||
id: 2,
|
||||
name: 'Unrelated',
|
||||
templates: [createTemplate(10, 'Unrelated', { keywords: 'other' })],
|
||||
},
|
||||
],
|
||||
})
|
||||
|
||||
const names = templateItems(wrapper).map((item) => item.text())
|
||||
expect(names).toHaveLength(8)
|
||||
expect(names[0]).toBe('Curated')
|
||||
expect(names).not.toContain('Unrelated')
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,38 @@
|
||||
import { TestApp } from '@baserow/test/helpers/testApp'
|
||||
import TemplateOnboardingCancelModal from '@baserow/modules/database/components/onboarding/TemplateOnboardingCancelModal'
|
||||
|
||||
describe('TemplateDatabaseOnboardingStepType.getCancelModal', () => {
|
||||
let testApp = null
|
||||
let stepType = null
|
||||
|
||||
beforeEach(() => {
|
||||
testApp = new TestApp()
|
||||
stepType = testApp.getRegistry().get('databaseOnboardingStep', 'template')
|
||||
})
|
||||
|
||||
afterEach(() => {
|
||||
testApp.afterEach()
|
||||
})
|
||||
|
||||
test('offers the template modal when the instance has templates', async () => {
|
||||
testApp.mockServer.mock
|
||||
.onGet('/templates/')
|
||||
.reply(200, [
|
||||
{ id: 1, name: 'Category', templates: [{ id: 1, name: 'Template' }] },
|
||||
])
|
||||
|
||||
const modal = await stepType.getCancelModal()
|
||||
|
||||
expect(modal.component).toBe(TemplateOnboardingCancelModal)
|
||||
expect(modal.props.categories).toHaveLength(1)
|
||||
expect(modal.props.databaseStepType).toBe('template')
|
||||
})
|
||||
|
||||
test('does not offer a modal when the instance has no templates', async () => {
|
||||
testApp.mockServer.mock
|
||||
.onGet('/templates/')
|
||||
.reply(200, [{ id: 1, name: 'Category', templates: [] }])
|
||||
|
||||
expect(await stepType.getCancelModal()).toBe(null)
|
||||
})
|
||||
})
|
||||
Reference in new issue
Block a user