@webship-js/codeigniter-steps 0.0.0-stage → 2.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.
- package/LICENSE +21 -0
- package/README.md +448 -2
- package/package.json +62 -4
- package/tests/features/README.md +24 -0
- package/tests/features/access.feature +52 -0
- package/tests/features/accessibility.feature +32 -0
- package/tests/features/development.feature +59 -0
- package/tests/features/forgery.feature +36 -0
- package/tests/features/framework-pages.feature +42 -0
- package/tests/features/login-link.feature +43 -0
- package/tests/features/registration.feature +65 -0
- package/tests/features/session.feature +104 -0
- package/tests/step-definitions/README.md +37 -0
- package/tests/step-definitions/codeigniter-access.steps.js +122 -0
- package/tests/step-definitions/codeigniter-forms.steps.js +217 -0
- package/tests/step-definitions/codeigniter-helpers.js +702 -0
- package/tests/step-definitions/codeigniter-mail.steps.js +117 -0
- package/tests/step-definitions/codeigniter-pages.steps.js +209 -0
- package/tests/step-definitions/codeigniter-session.steps.js +277 -0
- package/tests/step-definitions/codeigniter-toolbar.steps.js +154 -0
|
@@ -0,0 +1,154 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
// The debug toolbar an app shows on its pages while it runs in development:
|
|
4
|
+
// that a page has it (and that a live page has none), its panels, and what a
|
|
5
|
+
// panel shows. The toolbar is the icon in a corner of the page that opens a
|
|
6
|
+
// bar of tabs (the time, the logs, the views, the files, the routes, the
|
|
7
|
+
// events, the history, the variables, the configuration, and the panels of
|
|
8
|
+
// the libraries the app uses); a tab opens its panel.
|
|
9
|
+
|
|
10
|
+
const { When, Then } = require('@cucumber/cucumber');
|
|
11
|
+
const { friendly } = require('webship-js/tests/step-definitions/webship');
|
|
12
|
+
const {
|
|
13
|
+
budget,
|
|
14
|
+
clean,
|
|
15
|
+
listed,
|
|
16
|
+
currentPath,
|
|
17
|
+
assertPresence,
|
|
18
|
+
} = require('./codeigniter-helpers');
|
|
19
|
+
|
|
20
|
+
const TOOLBAR_HINT = 'The debug toolbar is on the pages of an app that runs in the development environment (CI_ENVIRONMENT = development): the icon at the corner of the page opens it.';
|
|
21
|
+
|
|
22
|
+
/**
|
|
23
|
+
* The tabs of the toolbar that open a panel: their name (the panel they open)
|
|
24
|
+
* and the text of their label. A tab without a panel of its own (the views
|
|
25
|
+
* tab outlines the views on the page instead) is left out.
|
|
26
|
+
*/
|
|
27
|
+
async function toolbarTabs(world) {
|
|
28
|
+
return world.page.evaluate(() => [...document.querySelectorAll('#debug-bar a[data-tab]')].map((a) => ({
|
|
29
|
+
name: String(a.getAttribute('data-tab') || '').replace(/^ci-/, ''),
|
|
30
|
+
label: (a.textContent || '').replace(/\s+/g, ' ').trim(),
|
|
31
|
+
panel: !!document.querySelector(`#debug-bar .tab#${a.getAttribute('data-tab')}`),
|
|
32
|
+
})).filter((t) => t.panel)).catch(() => []);
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
/** The tab a person means by a name: the label that starts with it ("Routes 12"), else the panel it opens ("Timeline"). */
|
|
36
|
+
async function findTab(world, name) {
|
|
37
|
+
const wanted = clean(name).toLowerCase();
|
|
38
|
+
const tabs = await toolbarTabs(world);
|
|
39
|
+
const tab = tabs.find((t) => t.label.toLowerCase() === wanted || t.label.toLowerCase().startsWith(wanted + ' '))
|
|
40
|
+
|| tabs.find((t) => t.name.toLowerCase() === wanted);
|
|
41
|
+
return { tab, tabs };
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/** The tabs as a person reads them, for an error message. */
|
|
45
|
+
function tabNames(tabs) {
|
|
46
|
+
return listed(tabs.map((t) => (/^[A-Za-z]/.test(t.label) ? t.label.replace(/\s+\d+$/, '') : `${t.name} (${t.label})`)));
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
/** Open the toolbar from its icon, unless it is open already. */
|
|
50
|
+
async function openToolbar(world) {
|
|
51
|
+
const icon = world.page.locator('#debug-icon');
|
|
52
|
+
try {
|
|
53
|
+
await icon.waitFor({ state: 'attached', timeout: budget(world) });
|
|
54
|
+
} catch {
|
|
55
|
+
throw friendly({ message: `The page has no debug toolbar (${currentPath(world)}).`, hint: TOOLBAR_HINT });
|
|
56
|
+
}
|
|
57
|
+
const bar = world.page.locator('#debug-bar');
|
|
58
|
+
if (!(await bar.isVisible().catch(() => false))) {
|
|
59
|
+
await world.page.locator('#debug-icon a, #debug-icon').first().click();
|
|
60
|
+
await bar.waitFor({ state: 'visible', timeout: budget(world) });
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
/**
|
|
65
|
+
* Assert that the page has, or has not, the debug toolbar: its icon at the
|
|
66
|
+
* corner of the page, put there by the script that loads it. A page of a live
|
|
67
|
+
* app has neither.
|
|
68
|
+
*
|
|
69
|
+
* Example #1: Then I should see the debug toolbar
|
|
70
|
+
* Example #2: Then I should not see the debug toolbar
|
|
71
|
+
* Example #3: And we should see the debug toolbar
|
|
72
|
+
* Example #4: But I should not see the debug toolbar
|
|
73
|
+
* Example #5: Then we should not see the debug toolbar
|
|
74
|
+
*/
|
|
75
|
+
Then(/^(I |we )*should( not)* see the debug toolbar$/, async function (pronounCase, notCase) {
|
|
76
|
+
if (notCase) {
|
|
77
|
+
const left = await this.page.evaluate(() => [
|
|
78
|
+
document.getElementById('debugbar_loader') ? 'the script that loads it' : '',
|
|
79
|
+
document.getElementById('debug-icon') ? 'its icon' : '',
|
|
80
|
+
document.getElementById('debug-bar') ? 'its bar' : '',
|
|
81
|
+
].filter(Boolean)).catch(() => []);
|
|
82
|
+
if (left.length) {
|
|
83
|
+
throw friendly({ message: `Expected no debug toolbar, but the page has ${left.join(', ')} (${currentPath(this)}).`, hint: 'A live app runs in the production environment (CI_ENVIRONMENT = production in its .env): its pages carry no debug toolbar.' });
|
|
84
|
+
}
|
|
85
|
+
return;
|
|
86
|
+
}
|
|
87
|
+
// The icon while the toolbar is closed, the bar while it is open (the toolbar keeps its state).
|
|
88
|
+
await assertPresence(this.page.locator('#debug-icon, #debug-bar').filter({ visible: true }), false, {
|
|
89
|
+
label: 'the debug toolbar (its icon at the corner of the page, or its bar)',
|
|
90
|
+
hint: TOOLBAR_HINT,
|
|
91
|
+
timeout: budget(this),
|
|
92
|
+
found: async () => `The page is ${this.page.url()} ("${clean(await this.page.title())}").`,
|
|
93
|
+
});
|
|
94
|
+
});
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Open a panel of the debug toolbar, as a person does: the icon opens the
|
|
98
|
+
* toolbar, then the tab of that name opens its panel. A tab is named by the
|
|
99
|
+
* word of its label ("Routes", "Auth", "Vars"); the two tabs without a word
|
|
100
|
+
* by the panel they open ("Timeline", "Config").
|
|
101
|
+
*
|
|
102
|
+
* Example #1: When I open the "Routes" panel of the debug toolbar
|
|
103
|
+
* Example #2: When we open the "Auth" panel of the debug toolbar
|
|
104
|
+
* Example #3: And I open the "Timeline" panel of the debug toolbar
|
|
105
|
+
* Example #4: When I open the "Vars" panel of the debug toolbar
|
|
106
|
+
* Example #5: And we open the "Config" panel of the debug toolbar
|
|
107
|
+
*/
|
|
108
|
+
When(/^(I |we )*open the "([^"]*)" panel of the debug toolbar$/, async function (pronounCase, name) {
|
|
109
|
+
await openToolbar(this);
|
|
110
|
+
const { tab, tabs } = await findTab(this, name);
|
|
111
|
+
if (!tab) {
|
|
112
|
+
throw friendly({ message: `The debug toolbar has no "${name}" tab. Its tabs: ${tabNames(tabs)}.`, hint: 'Name a tab by the word of its label; a library adds its own tab (a database tab appears once the page ran a query).' });
|
|
113
|
+
}
|
|
114
|
+
// The toolbar keeps the tab that was open (a cookie): a second click would close it again.
|
|
115
|
+
const panel = this.page.locator(`#debug-bar #ci-${tab.name}`);
|
|
116
|
+
if (!(await panel.isVisible().catch(() => false))) {
|
|
117
|
+
await this.page.locator(`#debug-bar a[data-tab="ci-${tab.name}"]`).first().click();
|
|
118
|
+
}
|
|
119
|
+
try {
|
|
120
|
+
await panel.waitFor({ state: 'visible', timeout: budget(this) });
|
|
121
|
+
} catch {
|
|
122
|
+
throw friendly({ message: `The "${name}" tab of the debug toolbar did not open its panel.`, hint: 'A tab opens its panel above the toolbar; a second click closes it again.' });
|
|
123
|
+
}
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
/**
|
|
127
|
+
* Assert what an open panel of the debug toolbar shows, or does not show: a
|
|
128
|
+
* text of the panel (a route, a view, the name of the signed-in account),
|
|
129
|
+
* white space collapsed. Open the panel first.
|
|
130
|
+
*
|
|
131
|
+
* Example #1: Then the "Routes" panel of the debug toolbar should show "TestFixtures::account"
|
|
132
|
+
* Example #2: Then the "Auth" panel of the debug toolbar should show "user@example.com"
|
|
133
|
+
* Example #3: And the "Timeline" panel of the debug toolbar should show "welcome_message"
|
|
134
|
+
* Example #4: Then the "Routes" panel of the debug toolbar should not show "admin/settings"
|
|
135
|
+
* Example #5: And the "Config" panel of the debug toolbar should show "Environment: development"
|
|
136
|
+
*/
|
|
137
|
+
Then(/^the "([^"]*)" panel of the debug toolbar should( not)* show "([^"]*)"$/, async function (name, notCase, text) {
|
|
138
|
+
const { tab, tabs } = await findTab(this, name);
|
|
139
|
+
if (!tab) {
|
|
140
|
+
throw friendly({ message: `The debug toolbar has no "${name}" tab. Its tabs: ${tabNames(tabs)}.`, hint: TOOLBAR_HINT });
|
|
141
|
+
}
|
|
142
|
+
const panel = this.page.locator(`#debug-bar #ci-${tab.name}`);
|
|
143
|
+
if (!(await panel.isVisible().catch(() => false))) {
|
|
144
|
+
throw friendly({ message: `The "${name}" panel of the debug toolbar is not open.`, hint: `Open it first: When I open the "${name}" panel of the debug toolbar.` });
|
|
145
|
+
}
|
|
146
|
+
const shown = clean(await panel.innerText().catch(() => ''));
|
|
147
|
+
const has = shown.toLowerCase().includes(clean(text).toLowerCase());
|
|
148
|
+
if (notCase && has) {
|
|
149
|
+
throw friendly({ message: `Expected the "${name}" panel of the debug toolbar not to show "${text}", but it does.`, hint: 'The step reads the text of the open panel, letter case ignored.' });
|
|
150
|
+
}
|
|
151
|
+
if (!notCase && !has) {
|
|
152
|
+
throw friendly({ message: `Expected the "${name}" panel of the debug toolbar to show "${text}". It shows: "${shown.slice(0, 240)}…".`, hint: 'The step reads the text of the open panel, letter case ignored.' });
|
|
153
|
+
}
|
|
154
|
+
});
|