@stacksjs/defaults 0.75.539 → 0.75.541
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/ai/AGENTS.md +2 -0
- package/ai/skills/stacks-actions/SKILL.md +1 -1
- package/ai/skills/stacks-auth/SKILL.md +8 -1
- package/ai/skills/stacks-dashboard/SKILL.md +196 -3
- package/ai/skills/stacks-dependencies/SKILL.md +46 -0
- package/ai/skills/stacks-development/SKILL.md +1 -1
- package/ai/skills/stacks-flow/SKILL.md +7 -0
- package/ai/skills/stacks-hq/SKILL.md +146 -0
- package/ai/skills/stacks-models/SKILL.md +21 -3
- package/ai/skills/stacks-native/CATALOG.md +22 -9
- package/ai/skills/stacks-new-app/SKILL.md +175 -0
- package/ai/skills/stacks-repl/SKILL.md +61 -43
- package/ai/skills/stacks-stx/SKILL.md +6 -2
- package/ai/skills/stacks-upstream/SKILL.md +188 -0
- package/ai/skills/stacks-writing-for-agents/SKILL.md +1 -1
- package/app/Actions/Dashboard/Data/UserIndexAction.ts +20 -2
- package/app/Actions/Dashboard/Models/ModelDestroyAction.ts +48 -12
- package/app/Actions/Dashboard/Models/ModelOptionsAction.ts +103 -0
- package/app/Actions/Dashboard/Models/ModelRelatedAction.ts +42 -0
- package/app/Actions/Dashboard/Models/ModelShowAction.ts +75 -12
- package/app/Actions/Dashboard/Models/ModelStoreAction.ts +7 -1
- package/app/Actions/Dashboard/Models/ModelUpdateAction.ts +16 -2
- package/app/Actions/Dashboard/Models/model-destroy.ts +75 -0
- package/app/Actions/Dashboard/Models/model-options.ts +56 -0
- package/app/Actions/Dashboard/Models/model-related.ts +202 -0
- package/app/Actions/Dashboard/Models/model-relations.ts +172 -0
- package/app/Actions/Dashboard/Models/model-write.ts +240 -51
- package/app/Actions/Dashboard/Users/UserInviteAction.ts +50 -0
- package/app/Actions/Dashboard/Users/user-invitation.ts +110 -0
- package/app/Models/Activity.ts +4 -0
- package/app/Models/AnalyticsEvent.ts +4 -0
- package/app/Models/Automation.ts +4 -0
- package/app/Models/AutomationRun.ts +4 -0
- package/app/Models/Board.ts +4 -1
- package/app/Models/BoardColumn.ts +4 -1
- package/app/Models/Campaign.ts +4 -0
- package/app/Models/CampaignSend.ts +4 -0
- package/app/Models/CampaignVariant.ts +4 -0
- package/app/Models/Card.ts +4 -1
- package/app/Models/CardAttachment.ts +4 -0
- package/app/Models/CommunicationSuppression.ts +4 -0
- package/app/Models/ConsentEvent.ts +4 -0
- package/app/Models/Deployment.ts +1 -0
- package/app/Models/EmailList.ts +4 -0
- package/app/Models/EmailListSubscriber.ts +4 -0
- package/app/Models/Error.ts +4 -0
- package/app/Models/FailedJob.ts +4 -0
- package/app/Models/FeedbackToken.ts +4 -0
- package/app/Models/GdprRequest.ts +4 -0
- package/app/Models/Job.ts +4 -0
- package/app/Models/Log.ts +4 -0
- package/app/Models/MagicLinkToken.ts +4 -0
- package/app/Models/MailPreference.ts +4 -0
- package/app/Models/Notification.ts +4 -0
- package/app/Models/NotificationDelivery.ts +4 -0
- package/app/Models/PersonalAccessToken.ts +4 -0
- package/app/Models/QueryLog.ts +4 -0
- package/app/Models/Referral.ts +4 -0
- package/app/Models/Release.ts +1 -0
- package/app/Models/Request.ts +4 -0
- package/app/Models/SenderDomain.ts +4 -0
- package/app/Models/Site.ts +1 -0
- package/app/Models/SiteDomain.ts +4 -0
- package/app/Models/SocialPost.ts +4 -0
- package/app/Models/StorageItemTask.ts +4 -1
- package/app/Models/Subscriber.ts +4 -0
- package/app/Models/Subscription.ts +4 -0
- package/app/Models/Team.ts +1 -0
- package/app/Models/TeamInvitation.ts +1 -0
- package/app/Models/TeamMember.ts +1 -0
- package/app/Models/UsageEvent.ts +4 -0
- package/app/Models/User.ts +15 -3
- package/functions/dashboard-model-record.test.ts +276 -18
- package/functions/dashboard-model-record.ts +412 -55
- package/functions/data.ts +2 -0
- package/ide/vscode/package.json +1 -1
- package/package.json +5 -5
- package/resources/components/Dashboard/Analytics/AnalyticsHub.stx +1 -1
- package/resources/components/Dashboard/Analytics/CampaignAnalytics.stx +1 -1
- package/resources/components/Dashboard/Analytics/EventAnalytics.stx +1 -1
- package/resources/components/Dashboard/Analytics/SalesAnalytics.stx +1 -1
- package/resources/components/Dashboard/Analytics/WebAnalyticsBreakdown.stx +1 -1
- package/resources/components/Dashboard/App/RequestsOverview.stx +1 -1
- package/resources/components/Dashboard/App/SourceInventory.stx +1 -1
- package/resources/components/Dashboard/Auth/AccessTokens.stx +1 -1
- package/resources/components/Dashboard/Buddy/BuddyAssistant.stx +1 -1
- package/resources/components/Dashboard/Ci/CiDashboard.stx +1 -1
- package/resources/components/Dashboard/Commerce/Delivery/DeliveryPagination.stx +1 -1
- package/resources/components/Dashboard/Commerce/ProductWaitlistDashboard.stx +1 -1
- package/resources/components/Dashboard/Commerce/RestaurantWaitlistDashboard.stx +1 -1
- package/resources/components/Dashboard/Content/BlogDashboard.stx +1 -1
- package/resources/components/Dashboard/DashboardLayout.stx +1 -1
- package/resources/components/Dashboard/Data/DataRecords.stx +43 -22
- package/resources/components/Dashboard/Data/UserInvite.stx +107 -0
- package/resources/components/Dashboard/Email/CapturedMailDashboard.stx +1 -1
- package/resources/components/Dashboard/Email/EmailActivityDashboard.stx +1 -1
- package/resources/components/Dashboard/Email/InboxDashboard.stx +1 -1
- package/resources/components/Dashboard/Email/InboxMessageDetail.stx +2 -2
- package/resources/components/Dashboard/Email/InboxSettingsDashboard.stx +1 -1
- package/resources/components/Dashboard/Home/DashboardHome.stx +6 -1
- package/resources/components/Dashboard/Infrastructure/CloudDashboard.stx +1 -1
- package/resources/components/Dashboard/Infrastructure/DnsDashboard.stx +1 -1
- package/resources/components/Dashboard/Infrastructure/HealthDashboard.stx +1 -1
- package/resources/components/Dashboard/Infrastructure/InsightsDashboard.stx +1 -1
- package/resources/components/Dashboard/Infrastructure/LogsDashboard.stx +1 -1
- package/resources/components/Dashboard/Infrastructure/MailboxesDashboard.stx +1 -1
- package/resources/components/Dashboard/Infrastructure/ServerDetailsDashboard.stx +1 -1
- package/resources/components/Dashboard/Infrastructure/ServerlessDashboard.stx +1 -1
- package/resources/components/Dashboard/Infrastructure/ServersDashboard.stx +1 -1
- package/resources/components/Dashboard/Jobs/JobDetail.stx +1 -1
- package/resources/components/Dashboard/Jobs/JobTable.stx +2 -2
- package/resources/components/Dashboard/Kanban/KanbanBoardDashboard.stx +1 -1
- package/resources/components/Dashboard/Kanban/KanbanBoardsDashboard.stx +1 -1
- package/resources/components/Dashboard/Management/PermissionsDashboard.stx +1 -1
- package/resources/components/Dashboard/Marketing/AbandonedCartsDashboard.stx +1 -1
- package/resources/components/Dashboard/Marketing/CampaignsDashboard.stx +1 -1
- package/resources/components/Dashboard/Marketing/MarketingListsDashboard.stx +1 -1
- package/resources/components/Dashboard/Marketing/SocialPostsDashboard.stx +1 -1
- package/resources/components/Dashboard/Models/ModelFieldInputs.stx +125 -0
- package/resources/components/Dashboard/Models/ModelRecordCreate.stx +24 -66
- package/resources/components/Dashboard/Models/ModelRecordDetail.stx +36 -8
- package/resources/components/Dashboard/Models/ModelRecordEdit.stx +36 -32
- package/resources/components/Dashboard/Models/ModelRecordsDashboard.stx +72 -28
- package/resources/components/Dashboard/Models/ModelRelatedPanels.stx +99 -0
- package/resources/components/Dashboard/Models/ModelRelationPicker.stx +247 -0
- package/resources/components/Dashboard/Models/ModelsOverview.stx +1 -1
- package/resources/components/Dashboard/Notifications/NotificationDeliveries.stx +1 -1
- package/resources/components/Dashboard/Notifications/NotificationDeliveryHistory.stx +1 -1
- package/resources/components/Dashboard/Notifications/NotificationDeliveryOverview.stx +1 -1
- package/resources/components/Dashboard/Queries/QueryDashboard.stx +1 -1
- package/resources/components/Dashboard/Queries/QueryDetail.stx +1 -1
- package/resources/components/Dashboard/Queue/QueueDashboard.stx +1 -1
- package/resources/components/Dashboard/Realtime/RealtimeDashboard.stx +1 -1
- package/resources/components/Dashboard/Releases/ReleaseDashboard.stx +1 -1
- package/resources/components/Dashboard/Search/SearchEngineDashboard.stx +1 -1
- package/resources/components/Dashboard/Settings/MailSettingsDashboard.stx +1 -1
- package/resources/components/Dashboard/Settings/SettingsDashboard.stx +1 -1
- package/resources/components/Dashboard/Teams/TeamPeopleDashboard.stx +1 -1
- package/resources/components/Dashboard/UI/Drawer.stx +1 -1
- package/resources/components/Dashboard/UI/Input.stx +3 -2
- package/resources/components/Dashboard/UI/Modal.stx +1 -1
- package/resources/components/Dashboard/UI/Select.stx +8 -4
- package/resources/components/Dashboard/UI/Textarea.stx +18 -12
- package/resources/emails/password-reset.stx +3 -1
- package/routes/dashboard-api.ts +9 -0
- package/scaffold/config/analytics.ts +5 -3
- package/scaffold/resources/components/NextStep.stx +13 -0
- package/scaffold/resources/partials/head.stx +31 -0
- package/scaffold/resources/views/index.stx +23 -47
- package/scaffold/resources/views/layouts/default.stx +23 -0
- package/views/dashboard/data/users/invite.stx +8 -0
- package/views/dashboard/layouts/default.stx +21 -2
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import { describe, expect, it } from 'bun:test'
|
|
2
2
|
import { DashboardApiError } from './dashboard-api'
|
|
3
|
-
import {
|
|
4
|
-
import type { ModelRecord } from './dashboard-model-record'
|
|
3
|
+
import { modelDeleteNotice, modelDeleteWarning, modelFieldColumn, modelFieldError, modelFieldInputValue, modelFieldPayloadValue, modelFormPayload, modelFormPrefill, modelFormValues, modelListColumnNames, modelListFilters, modelRecordBackHref, modelRecordCreateHref, modelRecordEditHref, modelRecordHref, modelRecordListLabel, modelRecordSections, modelRecordTitle, modelRelatedCreateHref, modelRelatedListHref, modelRelationCell, modelWriteFailure, userInviteHref } from './dashboard-model-record'
|
|
4
|
+
import type { ModelCreateField, ModelRecord, ModelRelatedPanel } from './dashboard-model-record'
|
|
5
5
|
|
|
6
6
|
const record: ModelRecord = {
|
|
7
7
|
modelName: 'Team',
|
|
@@ -14,21 +14,86 @@ const record: ModelRecord = {
|
|
|
14
14
|
{ name: 'created_at', label: 'Created At', type: 'date' },
|
|
15
15
|
],
|
|
16
16
|
updateColumns: ['name', 'description', 'status'],
|
|
17
|
-
|
|
17
|
+
fields: [],
|
|
18
|
+
relations: {},
|
|
19
|
+
relationNames: {},
|
|
20
|
+
writeCapabilities: { create: true, update: true, destroy: true, invite: false, anonymize: false },
|
|
21
|
+
anonymized: false,
|
|
18
22
|
}
|
|
19
23
|
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
expect(
|
|
25
|
-
expect(
|
|
24
|
+
const field = (name: string, type: ModelCreateField['type'], extra: Partial<ModelCreateField> = {}): ModelCreateField => ({ name, label: name, type, required: false, defaultValue: type === 'boolean' ? false : '', options: [], ...extra })
|
|
25
|
+
|
|
26
|
+
describe('what a form holds for a stored value', () => {
|
|
27
|
+
it('finds a field in its column', () => {
|
|
28
|
+
expect(modelFieldColumn('firstName')).toBe('first_name')
|
|
29
|
+
expect(modelFieldColumn('published_at')).toBe('published_at')
|
|
30
|
+
const values = modelFormValues([field('firstName', 'text'), field('status', 'enum')], { first_name: 'Ada', status: 'active' })
|
|
31
|
+
expect(values).toEqual({ firstName: 'Ada', status: 'active' })
|
|
32
|
+
})
|
|
33
|
+
|
|
34
|
+
it('a checkbox is on or off, however the driver spelled yes', () => {
|
|
35
|
+
for (const yes of [true, 1, '1', 'true'])
|
|
36
|
+
expect(modelFieldInputValue(field('archived', 'boolean'), yes)).toBe(true)
|
|
37
|
+
for (const no of [false, 0, '0', null, undefined, ''])
|
|
38
|
+
expect(modelFieldInputValue(field('archived', 'boolean'), no)).toBe(false)
|
|
39
|
+
})
|
|
40
|
+
|
|
41
|
+
it('a date is its calendar day, never shifted by a time zone', () => {
|
|
42
|
+
// A driver hands a DATE back as midnight UTC, which is the day before
|
|
43
|
+
// for everyone west of it if it goes through `Date`.
|
|
44
|
+
expect(modelFieldInputValue(field('opensAt', 'date'), '2026-10-01')).toBe('2026-10-01')
|
|
45
|
+
expect(modelFieldInputValue(field('opensAt', 'date'), '2026-10-01T00:00:00.000Z')).toBe('2026-10-01')
|
|
46
|
+
expect(modelFieldInputValue(field('opensAt', 'date'), new Date('2026-10-01T00:00:00.000Z'))).toBe('2026-10-01')
|
|
47
|
+
})
|
|
48
|
+
|
|
49
|
+
it('a moment is shown on the visitor\'s own clock, and comes back as the same instant', () => {
|
|
50
|
+
const moment = field('scheduledAt', 'datetime')
|
|
51
|
+
// Stored without an offset is UTC, as the framework writes it.
|
|
52
|
+
for (const stored of ['2026-08-14 07:33:04', '2026-08-14T07:33:04.000Z', 1786692784]) {
|
|
53
|
+
const shown = modelFieldInputValue(moment, stored) as string
|
|
54
|
+
expect(shown).toMatch(/^2026-08-1[34]T\d{2}:33$/)
|
|
55
|
+
// Whatever zone this runs in: the input's local time is that instant, to the minute.
|
|
56
|
+
expect(new Date(shown).toISOString()).toBe('2026-08-14T07:33:00.000Z')
|
|
57
|
+
expect(modelFieldPayloadValue(moment, shown)).toBe('2026-08-14T07:33:00.000Z')
|
|
58
|
+
}
|
|
59
|
+
expect(modelFieldInputValue(moment, null)).toBe('')
|
|
60
|
+
expect(modelFieldInputValue(moment, 'not a date')).toBe('')
|
|
61
|
+
})
|
|
62
|
+
|
|
63
|
+
it('JSON is indented so it can be read, whether stored as text or as a value', () => {
|
|
64
|
+
const json = field('settings', 'json')
|
|
65
|
+
expect(modelFieldInputValue(json, '{"theme":"dark"}')).toBe('{\n "theme": "dark"\n}')
|
|
66
|
+
expect(modelFieldInputValue(json, { theme: 'dark' })).toBe('{\n "theme": "dark"\n}')
|
|
67
|
+
// Not JSON at all: shown as it is, for the visitor to repair.
|
|
68
|
+
expect(modelFieldInputValue(json, '{theme')).toBe('{theme')
|
|
69
|
+
})
|
|
70
|
+
|
|
71
|
+
it('a create starts from each field\'s default', () => {
|
|
72
|
+
expect(modelFormValues([field('status', 'enum', { defaultValue: 'draft' }), field('featured', 'boolean', { defaultValue: true }), field('title', 'text')]))
|
|
73
|
+
.toEqual({ status: 'draft', featured: true, title: '' })
|
|
74
|
+
})
|
|
75
|
+
})
|
|
76
|
+
|
|
77
|
+
describe('what a form sends', () => {
|
|
78
|
+
const fields = [field('name', 'text'), field('description', 'longtext'), field('status', 'enum'), field('archived', 'boolean'), field('scheduledAt', 'datetime')]
|
|
79
|
+
const row = { name: 'PrimeSoft Ltd', description: null, status: 'active', archived: 0, scheduled_at: '2026-08-14 07:33:04' }
|
|
80
|
+
|
|
81
|
+
it('an edit sends only what was changed, an emptied field as null', () => {
|
|
82
|
+
const initial = modelFormValues(fields, row)
|
|
83
|
+
expect(modelFormPayload(fields, { ...initial }, initial)).toEqual({})
|
|
84
|
+
expect(modelFormPayload(fields, { ...initial, status: 'inactive' }, initial)).toEqual({ status: 'inactive' })
|
|
85
|
+
expect(modelFormPayload(fields, { ...initial, name: '', description: 'Cloud' }, initial)).toEqual({ name: null, description: 'Cloud' })
|
|
86
|
+
expect(modelFormPayload(fields, { ...initial, archived: true }, initial)).toEqual({ archived: true })
|
|
87
|
+
expect(modelFormPayload(fields, { ...initial, scheduledAt: '' }, initial)).toEqual({ scheduledAt: null })
|
|
26
88
|
})
|
|
27
89
|
|
|
28
|
-
it('
|
|
29
|
-
expect(
|
|
30
|
-
|
|
31
|
-
|
|
90
|
+
it('a create sends every field, with no and empty said plainly', () => {
|
|
91
|
+
expect(modelFormPayload(fields, modelFormValues(fields))).toEqual({ name: null, description: null, status: null, archived: false, scheduledAt: null })
|
|
92
|
+
})
|
|
93
|
+
|
|
94
|
+
it('a moment goes with its offset, so it is the one the visitor picked', () => {
|
|
95
|
+
const picked = '2026-12-24T09:30'
|
|
96
|
+
expect(modelFieldPayloadValue(field('scheduledAt', 'datetime'), picked)).toBe(new Date(picked).toISOString())
|
|
32
97
|
})
|
|
33
98
|
})
|
|
34
99
|
|
|
@@ -53,7 +118,11 @@ describe('a model record on its own page', () => {
|
|
|
53
118
|
{ name: 'email_verified_at', label: 'Email Verified At', type: 'text' },
|
|
54
119
|
],
|
|
55
120
|
updateColumns: [],
|
|
56
|
-
|
|
121
|
+
fields: [],
|
|
122
|
+
relations: {},
|
|
123
|
+
relationNames: {},
|
|
124
|
+
writeCapabilities: { create: true, update: false, destroy: false, invite: false, anonymize: false },
|
|
125
|
+
anonymized: false,
|
|
57
126
|
}
|
|
58
127
|
|
|
59
128
|
it('groups the fields into the cards of the page', () => {
|
|
@@ -131,9 +200,198 @@ describe('creating a model record', () => {
|
|
|
131
200
|
})
|
|
132
201
|
|
|
133
202
|
it('reports a refusal in one shape, with each field\'s message under its field', () => {
|
|
134
|
-
expect(
|
|
135
|
-
.toEqual({ ok: false, error: '
|
|
136
|
-
expect(
|
|
137
|
-
|
|
203
|
+
expect(modelWriteFailure(new DashboardApiError('Validation failed.', 422, { name: 'The name is required.' })))
|
|
204
|
+
.toEqual({ ok: false, error: 'Check the field marked below.', errors: { name: ['The name is required.'] } })
|
|
205
|
+
expect(modelWriteFailure(new DashboardApiError('Validation failed.', 422, { name: 'Too short.', email: 'Already in use.' })).error)
|
|
206
|
+
.toBe('Check the 2 fields marked below.')
|
|
207
|
+
expect(modelWriteFailure(new DashboardApiError('Server error', 500))).toEqual({ ok: false, error: 'Server error', errors: {} })
|
|
208
|
+
expect(modelWriteFailure(new Error('offline'))).toEqual({ ok: false, error: 'offline', errors: {} })
|
|
209
|
+
})
|
|
210
|
+
})
|
|
211
|
+
|
|
212
|
+
describe('a refused edit', () => {
|
|
213
|
+
it('finds a field\'s message whichever way the field is spelled', () => {
|
|
214
|
+
// The API names fields as the model does; an edit form's inputs are columns.
|
|
215
|
+
const errors = { firstName: ['Too short.'], email: ['Already in use.'] }
|
|
216
|
+
expect(modelFieldError(errors, 'first_name')).toBe('Too short.')
|
|
217
|
+
expect(modelFieldError(errors, 'firstName')).toBe('Too short.')
|
|
218
|
+
expect(modelFieldError(errors, 'email')).toBe('Already in use.')
|
|
219
|
+
expect(modelFieldError(errors, 'avatar')).toBe('')
|
|
220
|
+
expect(modelFieldError({}, 'email')).toBe('')
|
|
221
|
+
})
|
|
222
|
+
})
|
|
223
|
+
|
|
224
|
+
describe('the delete confirmation', () => {
|
|
225
|
+
it('says what happens in plain words', () => {
|
|
226
|
+
expect(modelDeleteWarning('Ava')).toBe('Ava will be deleted. This cannot be undone from the dashboard.')
|
|
227
|
+
})
|
|
228
|
+
|
|
229
|
+
it('says beforehand that an account other records refer to is anonymized instead', () => {
|
|
230
|
+
expect(modelDeleteWarning('Ava', true)).toBe('Ava will be deleted. This cannot be undone from the dashboard. If other records still refer to this account, it is anonymized instead: the name and email are removed, sign-in is revoked and those records are kept.')
|
|
231
|
+
expect(modelDeleteWarning('Ava', false)).toBe(modelDeleteWarning('Ava'))
|
|
232
|
+
})
|
|
233
|
+
|
|
234
|
+
it('reports afterwards which of the two happened', () => {
|
|
235
|
+
expect(modelDeleteNotice('User Ava', 'deleted')).toEqual({ title: 'User Ava deleted' })
|
|
236
|
+
// The account is still in the list, so "deleted" would be contradicted by the page.
|
|
237
|
+
expect(modelDeleteNotice('User Ava', 'anonymized')).toEqual({
|
|
238
|
+
title: 'User Ava anonymized',
|
|
239
|
+
detail: 'Other records still refer to this account, so it was kept with its name and email removed. It can no longer sign in.',
|
|
240
|
+
})
|
|
241
|
+
})
|
|
242
|
+
})
|
|
243
|
+
|
|
244
|
+
describe('inviting a user', () => {
|
|
245
|
+
it('links to the invite page, remembering the list to return to', () => {
|
|
246
|
+
expect(userInviteHref()).toBe('/data/users/invite')
|
|
247
|
+
expect(userInviteHref('/data/users')).toBe('/data/users/invite?from=%2Fdata%2Fusers')
|
|
248
|
+
expect(userInviteHref('/models/user')).toBe('/data/users/invite?from=%2Fmodels%2Fuser')
|
|
249
|
+
})
|
|
250
|
+
})
|
|
251
|
+
|
|
252
|
+
describe('a field that points at another model\'s record', () => {
|
|
253
|
+
const team = field('teamId', 'relation', { relation: { model: 'Team', slug: 'team', label: 'Team' } })
|
|
254
|
+
|
|
255
|
+
it('holds its id as text in the form and sends it as a number', () => {
|
|
256
|
+
expect(modelFormValues([team], { team_id: 5 })).toEqual({ teamId: '5' })
|
|
257
|
+
expect(modelFieldPayloadValue(team, '5')).toBe(5)
|
|
258
|
+
expect(modelFieldPayloadValue(team, '')).toBeNull()
|
|
259
|
+
})
|
|
260
|
+
|
|
261
|
+
it('a cleared choice is sent as null, an untouched one not at all', () => {
|
|
262
|
+
const initial = modelFormValues([team], { team_id: 5 })
|
|
263
|
+
expect(modelFormPayload([team], { teamId: '' }, initial)).toEqual({ teamId: null })
|
|
264
|
+
expect(modelFormPayload([team], { teamId: '5' }, initial)).toEqual({})
|
|
265
|
+
expect(modelFormPayload([team], { teamId: '8' }, initial)).toEqual({ teamId: 8 })
|
|
266
|
+
})
|
|
267
|
+
})
|
|
268
|
+
|
|
269
|
+
describe('a record\'s page names the records it points at', () => {
|
|
270
|
+
const member: ModelRecord = {
|
|
271
|
+
modelName: 'Team Member',
|
|
272
|
+
row: { id: 9, team_id: 3, user_id: null, role: 'member' },
|
|
273
|
+
columns: [
|
|
274
|
+
{ name: 'id', label: 'ID', type: 'number' },
|
|
275
|
+
{ name: 'team_id', label: 'Team ID', type: 'number' },
|
|
276
|
+
{ name: 'user_id', label: 'User ID', type: 'number' },
|
|
277
|
+
{ name: 'role', label: 'Role', type: 'text' },
|
|
278
|
+
],
|
|
279
|
+
updateColumns: [],
|
|
280
|
+
fields: [],
|
|
281
|
+
relations: { team_id: { model: 'Team', slug: 'team', label: 'Team' }, user_id: { model: 'User', slug: 'user', label: 'User' } },
|
|
282
|
+
relationNames: {},
|
|
283
|
+
writeCapabilities: { create: true, update: true, destroy: true, invite: false, anonymize: false },
|
|
284
|
+
anonymized: false,
|
|
285
|
+
}
|
|
286
|
+
const identifiers = (names?: Record<string, string>) => modelRecordSections(member, names).find(section => section.id === 'identifiers')!.details
|
|
287
|
+
|
|
288
|
+
it('as a link to it, called by its name', () => {
|
|
289
|
+
const team = identifiers({ team_id: 'PrimeSoft Ltd' }).find(detail => detail.name === 'team_id')!
|
|
290
|
+
// "Team", not "Team ID": the page says which team.
|
|
291
|
+
expect(team).toMatchObject({ label: 'Team', value: 'PrimeSoft Ltd', kind: 'link', href: '/models/team/3', empty: false })
|
|
292
|
+
})
|
|
293
|
+
|
|
294
|
+
it('by its id until the name arrives, and for a record that is gone', () => {
|
|
295
|
+
expect(identifiers().find(detail => detail.name === 'team_id')).toMatchObject({ value: 'Team #3', kind: 'link', href: '/models/team/3' })
|
|
296
|
+
})
|
|
297
|
+
|
|
298
|
+
it('says so when it points at nothing', () => {
|
|
299
|
+
expect(identifiers().find(detail => detail.name === 'user_id')).toMatchObject({ label: 'User', value: 'No user', kind: 'text', empty: true })
|
|
300
|
+
})
|
|
301
|
+
|
|
302
|
+
it('leaves the record\'s own id alone', () => {
|
|
303
|
+
expect(identifiers().find(detail => detail.name === 'id')).toMatchObject({ label: 'ID', value: '9', kind: 'text' })
|
|
304
|
+
})
|
|
305
|
+
})
|
|
306
|
+
|
|
307
|
+
describe('a panel of the records that point at a record', () => {
|
|
308
|
+
const members: ModelRelatedPanel = {
|
|
309
|
+
kind: 'many',
|
|
310
|
+
model: 'TeamMember',
|
|
311
|
+
slug: 'team-member',
|
|
312
|
+
title: 'Team Members',
|
|
313
|
+
label: 'Team Member',
|
|
314
|
+
foreignKey: 'team_id',
|
|
315
|
+
field: 'teamId',
|
|
316
|
+
total: 7,
|
|
317
|
+
columns: [],
|
|
318
|
+
rows: [],
|
|
319
|
+
canCreate: true,
|
|
320
|
+
}
|
|
321
|
+
|
|
322
|
+
it('"View all" is the related model\'s list, narrowed to this record', () => {
|
|
323
|
+
const href = modelRelatedListHref(members, 3)
|
|
324
|
+
expect(href).toBe('/models/team-member?filters=%7B%22team_id%22%3A%223%22%7D')
|
|
325
|
+
// What the list reads back from that address.
|
|
326
|
+
expect(modelListFilters(new URL(href, 'http://dashboard.test').searchParams.get('filters'))).toEqual({ team_id: '3' })
|
|
327
|
+
})
|
|
328
|
+
|
|
329
|
+
it('"Add" is its create form with this record chosen, coming back here', () => {
|
|
330
|
+
const href = modelRelatedCreateHref(members, 3, '/models/team/3')
|
|
331
|
+
expect(href).toBe('/models/team-member/create?from=%2Fmodels%2Fteam%2F3&teamId=3')
|
|
332
|
+
const query = new URL(href, 'http://dashboard.test').searchParams
|
|
333
|
+
const fields = [field('teamId', 'relation'), field('userId', 'relation'), field('role', 'enum'), field('featured', 'boolean')]
|
|
334
|
+
expect(modelFormPrefill(fields, name => query.get(name))).toEqual({ teamId: '3' })
|
|
335
|
+
})
|
|
336
|
+
|
|
337
|
+
it('a form opened from a record names that record as the way back', () => {
|
|
338
|
+
expect(modelRecordListLabel({ tableName: 'team_members' }, '/models/team/3')).toBe('Team 3')
|
|
339
|
+
expect(modelRecordListLabel({ tableName: 'team_members' }, '/models/board-column/12')).toBe('Board Column 12')
|
|
340
|
+
// Its own list is still called by its table.
|
|
341
|
+
expect(modelRecordListLabel({ tableName: 'team_members' }, '/models/team-member')).toBe('Team Members')
|
|
342
|
+
})
|
|
343
|
+
})
|
|
344
|
+
|
|
345
|
+
describe('what an address may set', () => {
|
|
346
|
+
it('a list\'s filters: a flat object of text, and nothing else', () => {
|
|
347
|
+
expect(modelListFilters('{"team_id":"3","status":"active"}')).toEqual({ team_id: '3', status: 'active' })
|
|
348
|
+
expect(modelListFilters('{"team_id":3}')).toEqual({ team_id: '3' })
|
|
349
|
+
for (const bad of [null, '', 'not json', '[1,2]', '"text"', '{"team_id":{"$gt":0}}', '{"a b":"1"}', '{"team_id":""}', '{"id; drop":"1"}'])
|
|
350
|
+
expect(modelListFilters(bad)).toEqual({})
|
|
351
|
+
})
|
|
352
|
+
|
|
353
|
+
it('a form\'s starting values: only fields the form has, and never a checkbox', () => {
|
|
354
|
+
const fields = [field('teamId', 'relation'), field('name', 'text'), field('archived', 'boolean')]
|
|
355
|
+
const query = (values: Record<string, string>) => (name: string) => values[name] ?? null
|
|
356
|
+
expect(modelFormPrefill(fields, query({ teamId: '3', name: 'Red', archived: 'true', password: 'x', from: '/models/team/3' }))).toEqual({ teamId: '3', name: 'Red' })
|
|
357
|
+
expect(modelFormPrefill(fields, query({ teamId: '' }))).toEqual({})
|
|
358
|
+
})
|
|
359
|
+
})
|
|
360
|
+
|
|
361
|
+
describe('the columns a list draws', () => {
|
|
362
|
+
const all = ['id', 'name', 'email', 'team_id', 'created_at']
|
|
363
|
+
|
|
364
|
+
it('the ones the model chose, or every one', () => {
|
|
365
|
+
expect(modelListColumnNames(all, ['name', 'email'])).toEqual(['name', 'email'])
|
|
366
|
+
expect(modelListColumnNames(all, undefined)).toEqual(all)
|
|
367
|
+
expect(modelListColumnNames(all, [])).toEqual(all)
|
|
368
|
+
// A choice the table no longer has is not drawn.
|
|
369
|
+
expect(modelListColumnNames(all, ['name', 'gone'])).toEqual(['name'])
|
|
370
|
+
})
|
|
371
|
+
|
|
372
|
+
it('and a column the list is narrowed by, so what narrowed it can be seen and cleared', () => {
|
|
373
|
+
expect(modelListColumnNames(all, ['name', 'email'], { team_id: '3' })).toEqual(['name', 'email', 'team_id'])
|
|
374
|
+
// Already drawn, cleared, or not a column at all: nothing added.
|
|
375
|
+
expect(modelListColumnNames(all, ['name', 'email'], { email: 'a', team_id: '', nope: '1' })).toEqual(['name', 'email'])
|
|
376
|
+
})
|
|
377
|
+
})
|
|
378
|
+
|
|
379
|
+
describe('a cell that points at another model\'s record', () => {
|
|
380
|
+
const relations = { team_id: { model: 'Team', slug: 'team', label: 'Team' } }
|
|
381
|
+
const names = { team_id: { 3: 'PrimeSoft Ltd' } }
|
|
382
|
+
|
|
383
|
+
it('is that record\'s name, linked to its page', () => {
|
|
384
|
+
expect(modelRelationCell('team_id', 3, relations, names)).toEqual({ text: 'PrimeSoft Ltd', href: '/models/team/3' })
|
|
385
|
+
expect(modelRelationCell('team_id', '3', relations, names)).toEqual({ text: 'PrimeSoft Ltd', href: '/models/team/3' })
|
|
386
|
+
})
|
|
387
|
+
|
|
388
|
+
it('is called by its id when the name is not known', () => {
|
|
389
|
+
expect(modelRelationCell('team_id', 9, relations, names)).toEqual({ text: 'Team #9', href: '/models/team/9' })
|
|
390
|
+
})
|
|
391
|
+
|
|
392
|
+
it('is nothing for an empty cell, and for a column that is not a relation', () => {
|
|
393
|
+
expect(modelRelationCell('team_id', null, relations, names)).toBeNull()
|
|
394
|
+
expect(modelRelationCell('team_id', '', relations, names)).toBeNull()
|
|
395
|
+
expect(modelRelationCell('name', 'Ada', relations, names)).toBeNull()
|
|
138
396
|
})
|
|
139
397
|
})
|