@webship.co/workspace-filament 0.0.0-stage → 1.0.0

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.
@@ -0,0 +1,399 @@
1
+ #!/usr/bin/env bash
2
+
3
+ # Filament for the Webship Workspace: build a Laravel app with an admin panel (a new app with the
4
+ # panel installed, or the panel's official demo app), add its default accounts, and wire its step
5
+ # pack into the testing setup, next to the Laravel step pack it extends.
6
+ #
7
+ # Placed by `plugins.sh --install filament` in core/scripts/plugins/filament/functions/, where
8
+ # bootstrap sources it with the core's own functions and the Laravel plugin's: this plugin needs
9
+ # @webship.co/workspace-laravel. A new app starts from that plugin's laravel_build (the official
10
+ # installer and a starter kit), and the accounts are written with its laravel_write_accounts.
11
+ # Everything runs in the project's container (DDEV by default: `ddev artisan …`, `ddev composer …`),
12
+ # never on the host. The container tool writes the database settings of the app into its .env.
13
+ #
14
+ # The panel's CLI is Artisan, through the Laravel plugin's tool:
15
+ # bash cmd-tools-laravel-artisan.sh <app> --run "make:filament-resource Post --generate"
16
+ #
17
+ # Four names are the ones the core's tools look for:
18
+ # set_filament_users the default accounts (cmd-tools-add-users.sh <project> filament)
19
+ # add_filament_users create them through the app (the same tool, and --add-users of the builder)
20
+ # cancel_filament_users delete them (cmd-tools-cancel-users.sh <project> filament)
21
+ # testing_configure_filament the step pack in the testing stack (cmd-tools-testing.sh <project>)
22
+ # An app with a panel is a project of the DDEV type `laravel`: the row's Users menu hands the tools the
23
+ # Laravel plugin's list. The panel's own accounts come with the builder's --add-users, with the testing
24
+ # setup, and with `cmd-tools-add-users.sh <project> filament`.
25
+
26
+ # The step pack a panel is tested with, and the release line it is required at. It brings the Laravel
27
+ # step pack along; the Laravel plugin's hook adds that one too.
28
+ readonly FILAMENT_STEPS_PACKAGE='@webship-js/filament-steps';
29
+ readonly FILAMENT_STEPS_VERSION='^2.0.0';
30
+
31
+ # The release line of the panel the builder installs, and the branch of the demo app of that line.
32
+ readonly FILAMENT_LINE='5';
33
+
34
+ # The default accounts, the ones a scenario logs in as. A panel has no roles of its own: what the
35
+ # panel decides is whether an account may use it, so that is the "role" here. Accounts are
36
+ # configuration, created once on the app; a test suite never creates or deletes one.
37
+ # administrator a verified address: the panel lets it in
38
+ # unverified no verified address: the panel refuses it (its login form, and the 403 page)
39
+ function set_filament_users() {
40
+ users=(administrator unverified);
41
+ local user ;
42
+ for user in "${users[@]}" ; do
43
+ printf -v "user_${user}_name" '%s' "${user}" ;
44
+ printf -v "user_${user}_mail" '%s' "${user}@example.com" ;
45
+ printf -v "user_${user}_password" '%s' 'dD.123123ddd' ;
46
+ done
47
+ user_administrator_role='verified' ;
48
+ user_unverified_role='unverified' ;
49
+ }
50
+
51
+ # Is this folder an app with a panel? A Laravel project (its DDEV project type) with the panel in its
52
+ # Composer packages.
53
+ function filament_is_project() {
54
+ local project_path="$1";
55
+ grep -qE '^type:[[:space:]]*"?laravel"?[[:space:]]*$' "${project_path}/.ddev/config.yaml" 2>/dev/null || return 1 ;
56
+ grep -q '"filament/filament"' "${project_path}/composer.json" 2>/dev/null ;
57
+ }
58
+
59
+ # Go to the project a tool was asked about, or say why not.
60
+ function filament_enter_project() {
61
+ local project_path="${WORKSPACE_ROOT}/${doc_name}/${PROJECT_NAME}";
62
+ if [ ! -d "${project_path}" ] ; then
63
+ echo "No project ${PROJECT_NAME} in ${WORKSPACE_ROOT}/${doc_name}." ;
64
+ return 1 ;
65
+ fi
66
+ if ! filament_is_project "${project_path}" ; then
67
+ echo "${doc_name}/${PROJECT_NAME} is not an app with a panel: a Laravel project (type: laravel) with filament/filament in its composer.json." ;
68
+ return 1 ;
69
+ fi
70
+ cd "${project_path}" || return 1 ;
71
+ }
72
+
73
+ # The path of the admin panel of an app: "/" when its panel provider gives none (the demo app), else
74
+ # the one it gives ("/admin" for a new panel).
75
+ function filament_panel_path() {
76
+ local project_path="$1" provider path ;
77
+ provider="${project_path}/app/Providers/Filament/AdminPanelProvider.php" ;
78
+ path="$(grep -oE "\->path\('[^']*'\)" "${provider}" 2>/dev/null | head -1 | sed -E "s/->path\('([^']*)'\)/\1/")" ;
79
+ printf '/%s' "${path#/}" ;
80
+ }
81
+
82
+ # The changes a panel needs to run as a live app runs, as the panel's documentation describes them,
83
+ # in the project folder: the User model says which accounts the panel lets in (an address verified),
84
+ # and the panel checks it on every page (its own middleware); a new panel offers the password reset.
85
+ # Each change is marked "Webship Workspace" where it is made.
86
+ function filament_set_up_panel() {
87
+ python3 - <<'PYEOF' || return 1
88
+ import re
89
+ path = 'app/Models/User.php'
90
+ src = open(path).read()
91
+ count = 0
92
+ if 'Webship Workspace' in src:
93
+ # Changed by an earlier build.
94
+ count = 1
95
+ elif 'canAccessPanel' in src:
96
+ # The demo app lets every account in: an address verified for its admin panel.
97
+ src, count = re.subn(r"(public function canAccessPanel\(Panel \$panel\): bool\s*\{)\s*return true;",
98
+ r"\1\n // Changed by the Webship Workspace: the admin panel lets in an account whose address is\n // verified, and refuses the others.\n return $panel->getId() !== 'admin' || $this->hasVerifiedEmail();", src, count=1)
99
+ else:
100
+ src = src.replace("use Illuminate\\Foundation\\Auth\\User as Authenticatable;", "use Filament\\Models\\Contracts\\FilamentUser;\nuse Filament\\Panel;\nuse Illuminate\\Foundation\\Auth\\User as Authenticatable;", 1)
101
+ src, count = re.subn(r"class User extends Authenticatable\b(?! implements)", "class User extends Authenticatable implements FilamentUser", src, count=1)
102
+ src, n = re.subn(r"(class User extends Authenticatable implements )(?!FilamentUser)", r"\1FilamentUser, ", src, count=1) if count == 0 else (src, 0)
103
+ count = count or n
104
+ src = src.rstrip()
105
+ if count and src.endswith('}'):
106
+ src = src[:-1].rstrip() + """
107
+
108
+ // Added by the Webship Workspace: the panel lets in an account whose address is verified, and
109
+ // refuses the others.
110
+ public function canAccessPanel(Panel $panel): bool
111
+ {
112
+ return $this->hasVerifiedEmail();
113
+ }
114
+ }
115
+ """
116
+ if not count:
117
+ raise SystemExit(path + ': the User model is not one the Webship Workspace knows; add canAccessPanel by hand.')
118
+ open(path, 'w').write(src)
119
+ path = 'app/Providers/Filament/AdminPanelProvider.php'
120
+ src = open(path).read()
121
+ if 'use App\\Http\\Middleware\\Authenticate;' in src:
122
+ src = src.replace('use App\\Http\\Middleware\\Authenticate;', "// Changed by the Webship Workspace: the panel's own middleware, which checks canAccessPanel.\nuse Filament\\Http\\Middleware\\Authenticate;")
123
+ if '->passwordReset()' not in src and "->path('admin')" in src:
124
+ src = re.sub(r"->login\(\)", "->login()\n // Added by the Webship Workspace.\n ->passwordReset()", src, count=1)
125
+ open(path, 'w').write(src)
126
+ PYEOF
127
+ }
128
+
129
+ # The official demo app of the panel, at the head of the branch of its release line, as its README
130
+ # installs it, in the project folder: its packages (the panel at the newest release of the line), its
131
+ # key, its database with its own seed, its storage link and its theme.
132
+ function filament_get_demo() {
133
+ local tmp ;
134
+ tmp="$(mktemp -d)" ;
135
+ git clone --quiet --depth 1 --branch "${FILAMENT_LINE}.x" https://github.com/filamentphp/demo.git "${tmp}/demo" \
136
+ || { echo "The demo app could not be downloaded." ; rm -rf "${tmp}" ; return 1 ; } ;
137
+ (cd "${tmp}/demo" && git log -1 --format=' the demo app at %h (%ad)' --date=short) ;
138
+ rm -rf "${tmp}/demo/.git" ;
139
+ cp -a "${tmp}/demo/." ./ && rm -rf "${tmp}" ;
140
+ [ -f .env ] || cp .env.example .env ;
141
+ }
142
+
143
+ # Build an app with a panel from nothing. With --demo, the panel's official demo app; without it, a new
144
+ # app made by the Laravel plugin's builder (the official installer and a starter kit) with the panel
145
+ # installed the documented way. With --install the database is migrated and the workspace account is
146
+ # the panel's first account; with --add-users the default accounts.
147
+ function filament_build() {
148
+ trim_project_name ;
149
+ local base_url="https://${PROJECT_NAME}.ddev.site" ;
150
+ local php_version="${PHP_VERSION:-${site_php_version:-8.4}}" ;
151
+ local add_users="${ADD_USERS}" launch="${LAUNCH}" production="${PRODUCTION}" ;
152
+
153
+ if ! declare -f laravel_build > /dev/null || ! declare -f laravel_write_accounts > /dev/null ; then
154
+ echo "The Filament plugin builds on the Laravel plugin, which is not installed here:" ;
155
+ echo " bash core/scripts/plugins.sh --install laravel" ;
156
+ exit 1 ;
157
+ fi
158
+
159
+ if [ "${DEMO}" == 'yes' ] ; then
160
+ cd ${WORKSPACE_ROOT}/${doc_name} || exit 1 ;
161
+ drop_database ;
162
+ rm -rf "${PROJECT_NAME}" ;
163
+ mkdir -p "${PROJECT_NAME}" ;
164
+ cd ${WORKSPACE_ROOT}/${doc_name}/${PROJECT_NAME} || exit 1 ;
165
+ # PHP 8.4: the demo's lock file holds packages that need it.
166
+ ddev config --project-type=laravel --docroot=public --project-name=${PROJECT_NAME} \
167
+ --nodejs-version=$(ddev_nodejs_version) --php-version=${php_version} --auto || exit 1 ;
168
+ filament_get_demo || exit 1 ;
169
+ # The restart writes the database and the mail settings of the container into .env.
170
+ ddev_up start -y || exit 1 ;
171
+ ddev composer install --no-interaction --no-progress || { echo "composer install failed." ; exit 1 ; } ;
172
+ ddev composer update 'filament/*' --with-dependencies --no-interaction --no-progress || exit 1 ;
173
+ ddev artisan key:generate --ansi > /dev/null || exit 1 ;
174
+ ddev dotenv set .env --mail-from-address=webship@example.com > /dev/null ;
175
+ if [ "${INSTALL}" == 'yes' ] ; then
176
+ ddev artisan migrate --force --seed --no-interaction || { echo "The migrations and the demo's seed failed." ; exit 1 ; } ;
177
+ ddev artisan storage:link > /dev/null ;
178
+ fi
179
+ ddev npm ci --no-audit --no-fund || exit 1 ;
180
+ ddev npm run build || exit 1 ;
181
+ else
182
+ # A new app by the Laravel plugin's builder: its accounts and its browser come after the panel.
183
+ ADD_USERS='no' ; LAUNCH='no' ; PRODUCTION='no' ;
184
+ PHP_VERSION="${php_version}" ;
185
+ ( laravel_build ) || exit 1 ;
186
+ ADD_USERS="${add_users}" ; LAUNCH="${launch}" ; PRODUCTION="${production}" ;
187
+ cd ${WORKSPACE_ROOT}/${doc_name}/${PROJECT_NAME} || exit 1 ;
188
+ ddev composer require "filament/filament:^${FILAMENT_LINE}.0" --with-all-dependencies --no-interaction --no-progress \
189
+ || { echo "The panel could not be required." ; exit 1 ; } ;
190
+ ddev artisan filament:install --panels --no-interaction || { echo "The panel could not be installed." ; exit 1 ; } ;
191
+ ddev dotenv set .env --mail-from-address=webship@example.com > /dev/null ;
192
+ # The panel's mail (the password reset) is a queued notification, and a new app queues in its
193
+ # database: a local app runs no queue worker, so its queue runs in the request, as the demo's does.
194
+ ddev dotenv set .env --queue-connection=sync > /dev/null ;
195
+ fi
196
+
197
+ filament_set_up_panel || exit 1 ;
198
+ ddev artisan optimize:clear > /dev/null 2>&1 ;
199
+
200
+ if [ "${INSTALL}" == 'yes' ] ; then
201
+ # The workspace account is the panel's first account, its address verified.
202
+ printf '%s|%s|%s|verified\n' "${account_name}" "${account_mail}" "${account_pass}" | laravel_write_accounts save > /dev/null \
203
+ || { echo "The workspace account could not be written." ; exit 1 ; } ;
204
+ if [ "${ADD_USERS}" == 'yes' ] ; then
205
+ set_filament_users ;
206
+ add_filament_users ;
207
+ cd ${WORKSPACE_ROOT}/${doc_name}/${PROJECT_NAME} || exit 1 ;
208
+ fi
209
+ if [ "${PRODUCTION}" == 'yes' ] ; then
210
+ ddev dotenv set .env --app-env=production --app-debug=false > /dev/null ;
211
+ fi
212
+ local panel_path ;
213
+ panel_path="$(filament_panel_path "$(pwd)")" ;
214
+ echo "${doc_name} ${PROJECT_NAME} has been installed: $(ddev artisan --version 2>/dev/null), panel $(ddev composer show filament/filament 2>/dev/null | awk '$1 == "versions" {print $NF}')$( [ "${DEMO}" == 'yes' ] && echo ', the demo app').";
215
+ echo "Go to ${base_url}${panel_path%/}/login and log in as ${account_mail}";
216
+ else
217
+ [ "${ADD_USERS}" == 'yes' ] && echo "--add-users needs --install: there is no database to add accounts to yet." ;
218
+ echo "${doc_name} ${PROJECT_NAME} is ready: migrate its database with bash cmd-tools-laravel-artisan.sh ${PROJECT_NAME} --run \"migrate\"";
219
+ echo "Go to ${base_url}";
220
+ fi
221
+
222
+ if [ "${LAUNCH}" == 'yes' ] ; then
223
+ ddev launch "$(filament_panel_path "$(pwd)")" ;
224
+ fi
225
+
226
+ cd ${WORKSPACE_ROOT}/${doc_name};
227
+ }
228
+
229
+ # Create the default accounts through the app, with the Laravel plugin's writer (the password hashed
230
+ # with the app's own hasher). An account that is already there gets its name, password and state back.
231
+ # The list is loaded by the caller (set_filament_users): the core's add_users, the builder, the testing
232
+ # setup.
233
+ function add_filament_users() {
234
+ filament_enter_project || return 1 ;
235
+ local user user_name user_mail user_password user_role lines="" ;
236
+ for user in "${users[@]}" ; do
237
+ user_name="user_${user}_name"; user_mail="user_${user}_mail";
238
+ user_password="user_${user}_password"; user_role="user_${user}_role";
239
+
240
+ echo " ---------------------------------------------------------------- ";
241
+ echo " User name: ${!user_name}";
242
+ echo " User mail: ${!user_mail}";
243
+ echo " User password: ${!user_password}";
244
+ echo " User state: ${!user_role:-verified}";
245
+ echo " ================================================================= ";
246
+
247
+ lines="${lines}${!user_name}|${!user_mail}|${!user_password}|${!user_role:-verified}"$'\n' ;
248
+ done
249
+ printf '%s' "${lines}" | laravel_write_accounts save ;
250
+ cd ${WORKSPACE_ROOT}/${doc_name};
251
+ }
252
+
253
+ # Delete the default accounts.
254
+ function cancel_filament_users() {
255
+ filament_enter_project || return 1 ;
256
+ local user user_name user_mail lines="" ;
257
+ for user in "${users[@]}" ; do
258
+ user_name="user_${user}_name"; user_mail="user_${user}_mail";
259
+ echo " ---------------------------------------------------------------- ";
260
+ echo " User name: ${!user_name}";
261
+ echo " ================================================================= ";
262
+ lines="${lines}${!user_name}|${!user_mail}||"$'\n' ;
263
+ done
264
+ printf '%s' "${lines}" | laravel_write_accounts delete ;
265
+ cd ${WORKSPACE_ROOT}/${doc_name};
266
+ }
267
+
268
+ # The step pack in the testing stack of an app with a panel. The core's testing_configure calls this
269
+ # in the project folder once webship-js is scaffolded and before the dependencies are installed; for a
270
+ # project that is not one it changes nothing.
271
+ #
272
+ # The panel's pack extends the Laravel pack, and both go in the same profile. This hook runs before the
273
+ # Laravel plugin's (the core calls them in the order of their names) and writes what that one would
274
+ # write for a starter-kit app: the users registry of the panel's accounts, the panel's home and login
275
+ # page, the mailbox, the tags and a first feature for the panel; the Laravel hook then finds them there
276
+ # and adds its own pack beside this one. Every part is skipped when it is already there, so a second run
277
+ # adds what the first missed and never resets a suite.
278
+ function testing_configure_filament() {
279
+ local project_path="$1";
280
+ filament_is_project "${project_path}" || return 0 ;
281
+ if [ ! -f "${project_path}/cucumber.js" ] || [ ! -f "${project_path}/package.json" ] ; then
282
+ echo " Filament: cucumber.js is not here yet — run the testing setup again once webship-js is scaffolded." ;
283
+ return 1 ;
284
+ fi
285
+
286
+ echo "Adding the Filament step pack (${FILAMENT_STEPS_PACKAGE} ${FILAMENT_STEPS_VERSION}).";
287
+ set_filament_users ;
288
+ local registry="" user user_name user_mail user_password panel_path ;
289
+ for user in "${users[@]}" ; do
290
+ user_name="user_${user}_name"; user_mail="user_${user}_mail"; user_password="user_${user}_password";
291
+ registry="${registry}${user}|${!user_mail}|${!user_password}|${!user_name}"$'\n' ;
292
+ done
293
+ panel_path="$(filament_panel_path "${project_path}")" ;
294
+
295
+ python3 - "${project_path}" "${FILAMENT_STEPS_PACKAGE}" "${FILAMENT_STEPS_VERSION}" 'FILAMENT' "${registry}" "${panel_path}" <<'PYEOF' || return 1
296
+ import json, re, sys
297
+
298
+ project, pack, version, prefix, registry, panel = sys.argv[1:7]
299
+
300
+ # package.json: the pack as a dev dependency, at the release line this plugin was proven on.
301
+ pkg_file = project + '/package.json'
302
+ pkg = json.load(open(pkg_file))
303
+ if pack not in pkg.get('dependencies', {}) and pack not in pkg.get('devDependencies', {}):
304
+ pkg.setdefault('devDependencies', {})[pack] = version
305
+ open(pkg_file, 'w').write(json.dumps(pkg, indent=4) + '\n')
306
+ print(' package.json: %s %s' % (pack, version))
307
+
308
+ cucumber_file = project + '/cucumber.js'
309
+ src = open(cucumber_file).read()
310
+ before = src
311
+
312
+ # The pack's step definitions, after webship-js's own. The pack loads the Laravel pack's itself.
313
+ if ('node_modules/%s/' % pack) not in src:
314
+ line = "'node_modules/%s/tests/step-definitions/**/*.js'," % pack
315
+ anchor = re.search(r"^([ \t]*)'node_modules/webship-js/tests/step-definitions/[^']*',.*$", src, re.M)
316
+ opening = re.search(r"^([ \t]*)require:[ \t]*\[[ \t]*$", src, re.M)
317
+ if anchor:
318
+ src = src[:anchor.end()] + '\n' + anchor.group(1) + line + src[anchor.end():]
319
+ elif opening:
320
+ src = src[:opening.end()] + '\n' + opening.group(1) + ' ' + line + src[opening.end():]
321
+ else:
322
+ sys.exit(" cucumber.js has no require list this can add to. Add this line to it:\n " + line)
323
+ print(' cucumber.js: the step definitions of %s' % pack)
324
+
325
+ # The pack's assertions that must fail, and the Laravel pack's lanes, are no part of a normal run.
326
+ if not re.search(r"^[ \t]*tags:", src, re.M):
327
+ default = re.search(r"^([ \t]*)default:[ \t]*\{[ \t]*$", src, re.M)
328
+ if default:
329
+ pad = default.group(1) + ' '
330
+ src = src[:default.end()] + '\n' + pad + "// Work in progress, the assertions that must fail and the Laravel pack's lanes (@maintenance, @debug-page) stay out of a normal run.\n" \
331
+ + pad + "tags: process.env.CUCUMBER_TAGS || 'not @wip and not @must-fail and not @maintenance and not @debug-page'," + src[default.end():]
332
+ print(' cucumber.js: the tags that keep the assertions that must fail out of a normal run')
333
+
334
+ world = re.search(r"^([ \t]*)worldParameters:[ \t]*\{[ \t]*$", src, re.M)
335
+ if not world:
336
+ sys.exit(" cucumber.js has no worldParameters block to add the users registry to.")
337
+ pad = world.group(1) + ' '
338
+ additions = []
339
+ if not re.search(r"^[ \t]*homePath:", src, re.M):
340
+ login = (panel.rstrip('/') or '') + '/login'
341
+ additions += [
342
+ pad + "// The panel's home and its login page (the login steps of the Laravel pack read them).",
343
+ pad + "homePath: '%s'," % panel,
344
+ pad + "loginPath: '%s'," % login,
345
+ ]
346
+ if not re.search(r"^[ \t]*mailUrl:", src, re.M):
347
+ additions += [
348
+ pad + "// The mailbox that catches the mail of the app (the password reset steps read it).",
349
+ pad + "mailUrl: process.env.MAIL_URL || (process.env.LAUNCH_URL || '').replace(/\\/+$/, '') + ':8026',",
350
+ ]
351
+ if not re.search(r"^[ \t]*users:[ \t]*\{", src, re.M):
352
+ rows = [r.split('|') for r in registry.splitlines() if r.strip()]
353
+ additions += [
354
+ pad + "// The users registry: a handle a scenario reads, mapped to an account of this app (the default",
355
+ pad + "// accounts: cmd-tools-add-users.sh <project> filament). Override one with %s_<HANDLE>_EMAIL and %s_<HANDLE>_PASSWORD." % (prefix, prefix),
356
+ pad + "users: {",
357
+ ]
358
+ for handle, email, password, name in rows:
359
+ env = '%s_%s' % (prefix, handle.upper())
360
+ additions.append(pad + " %s: { email: process.env.%s_EMAIL || '%s', password: process.env.%s_PASSWORD || '%s', name: '%s' }," % (handle, env, email, env, password, name))
361
+ additions.append(pad + "},")
362
+ print(' cucumber.js: the users registry (%s)' % ', '.join(r[0] for r in rows))
363
+ if additions:
364
+ src = src[:world.end()] + '\n' + '\n'.join(additions) + src[world.end():]
365
+
366
+ # An app's package.json says "type": "module" (Vite's convention): cucumber.js becomes an ES module
367
+ # that exports the same default profile, and tests/ gets a package.json that keeps it CommonJS (the
368
+ # Laravel plugin's hook does the same; whichever runs first does it).
369
+ if pkg.get('type') == 'module':
370
+ if re.search(r"^module\.exports\s*=\s*\{", src, re.M) and not re.search(r"^export default ", src, re.M):
371
+ src = re.sub(r"^module\.exports\s*=\s*\{", "// The app's package.json says \"type\": \"module\": this file is an ES module, the profiles stay as they were.\nconst config = {", src, count=1, flags=re.M)
372
+ src = src.rstrip() + '\n\nexport default config.default;\n'
373
+ print(' cucumber.js: an ES module (the package.json of the app says "type": "module")')
374
+ import os
375
+ tests_pkg = project + '/tests/package.json'
376
+ if not os.path.exists(tests_pkg):
377
+ os.makedirs(project + '/tests', exist_ok=True)
378
+ open(tests_pkg, 'w').write(json.dumps({'type': 'commonjs'}, indent=2) + '\n')
379
+ print(' tests/package.json: the step definitions under tests/ stay CommonJS')
380
+
381
+ if src != before:
382
+ open(cucumber_file, 'w').write(src)
383
+ PYEOF
384
+
385
+ # A first feature for the panel, as the project's site.feature when it has none: the Laravel plugin's
386
+ # hook then keeps it, and places no starter-kit feature in a panel's project.
387
+ local feature="${WORKSPACE_SCRIPTS}/plugins/filament/panel.feature" login_path ;
388
+ login_path="${panel_path%/}/login" ;
389
+ if [ -f "${feature}" ] && [ ! -f "${project_path}/tests/features/site.feature" ] ; then
390
+ mkdir -p "${project_path}/tests/features" \
391
+ && sed -e "s#__PANEL_PATH__#${panel_path}#g" -e "s#__LOGIN_PATH__#${login_path}#g" "${feature}" > "${project_path}/tests/features/site.feature" \
392
+ && echo " tests/features/site.feature: a first feature for the panel" ;
393
+ fi
394
+
395
+ # The scenarios log in as the default accounts: make sure a migrated app has them.
396
+ if ddev artisan migrate:status > /dev/null 2>&1 ; then
397
+ ( add_filament_users > /dev/null ) && echo " the panel's default accounts are on the app (${users[*]})" ;
398
+ fi
399
+ }
@@ -0,0 +1,34 @@
1
+ Feature: The panel answers and its accounts work
2
+ As the owner of the app
3
+ I want the panel's login page, its dashboard and each default account to work
4
+ So that a build that came out broken is caught before anything else is tested
5
+
6
+ # Placed by the workspace's testing setup as a starting point: it is yours to change.
7
+ # The accounts are the default ones (cmd-tools-add-users.sh <project> filament); a scenario logs in by
8
+ # a handle of the users registry in cucumber.js, so no password is written here.
9
+
10
+ @critical
11
+ Scenario: A visitor is sent to the login form of the panel
12
+ Given I am an anonymous user
13
+ When I go to "__PANEL_PATH__"
14
+ Then I should see the login form
15
+
16
+ @critical
17
+ Scenario: The administrator logs in, and the panel names it
18
+ Given I am a logged in user with the "administrator" user
19
+ Then I should be logged in as "administrator"
20
+ And the user menu should offer "Sign out"
21
+
22
+ @js-off
23
+ Scenario: The panel refuses the account whose address is not verified
24
+ Given I am an anonymous user
25
+ When I go to "__LOGIN_PATH__"
26
+ And I fill in "Email address" with the email of "unverified"
27
+ And I fill in "Password" with the password of "unverified"
28
+ And I press "Sign in"
29
+ Then the "Email address" field should have the error "These credentials do not match our records."
30
+
31
+ Scenario: The health route answers that the app is up
32
+ Given I am an anonymous user
33
+ When I go to "/up"
34
+ Then the response status code should be 200