@rimori/playwright-testing 0.2.2 → 0.2.3-next.2
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/dist/core/MessageChannelSimulator.d.ts +18 -82
- package/dist/core/MessageChannelSimulator.js +70 -106
- package/dist/core/RimoriTestEnvironment.d.ts +137 -24
- package/dist/core/RimoriTestEnvironment.js +350 -129
- package/dist/core/SettingsStateManager.d.ts +41 -0
- package/dist/core/SettingsStateManager.js +74 -0
- package/dist/fixtures/default-user-info.js +1 -0
- package/dist/test/translator.test.js +1 -1
- package/package.json +7 -2
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
/**
|
|
3
|
+
* Manages plugin settings state for test environment.
|
|
4
|
+
* Provides a single source of truth for settings that can be modified by mocked API calls.
|
|
5
|
+
*/
|
|
6
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
7
|
+
exports.SettingsStateManager = void 0;
|
|
8
|
+
class SettingsStateManager {
|
|
9
|
+
constructor(initialSettings, pluginId, guildId) {
|
|
10
|
+
this.settings = {
|
|
11
|
+
id: initialSettings?.id ?? 'settings-id',
|
|
12
|
+
plugin_id: initialSettings?.plugin_id ?? pluginId,
|
|
13
|
+
guild_id: initialSettings?.guild_id ?? guildId,
|
|
14
|
+
settings: initialSettings?.settings ?? {},
|
|
15
|
+
is_guild_setting: initialSettings?.is_guild_setting ?? false,
|
|
16
|
+
user_id: initialSettings?.user_id ?? null,
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Get current settings state (for GET requests)
|
|
21
|
+
* Returns null if no settings exist, otherwise returns the full settings object
|
|
22
|
+
*/
|
|
23
|
+
getSettings() {
|
|
24
|
+
return this.settings;
|
|
25
|
+
}
|
|
26
|
+
/**
|
|
27
|
+
* Update settings (for PATCH requests)
|
|
28
|
+
* @param updates - Partial settings to update
|
|
29
|
+
* @returns Array with updated row if settings exist, empty array if no settings exist
|
|
30
|
+
*/
|
|
31
|
+
updateSettings(updates) {
|
|
32
|
+
if (this.settings === null) {
|
|
33
|
+
// No settings exist - PATCH returns empty array (triggers INSERT flow)
|
|
34
|
+
return [];
|
|
35
|
+
}
|
|
36
|
+
// Update existing settings
|
|
37
|
+
this.settings = {
|
|
38
|
+
...this.settings,
|
|
39
|
+
...updates,
|
|
40
|
+
// Ensure these fields are preserved
|
|
41
|
+
id: this.settings.id,
|
|
42
|
+
plugin_id: this.settings.plugin_id,
|
|
43
|
+
guild_id: this.settings.guild_id,
|
|
44
|
+
};
|
|
45
|
+
// PATCH returns array with updated row
|
|
46
|
+
return [this.settings];
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Insert new settings (for POST requests)
|
|
50
|
+
* @param newSettings - Settings to insert
|
|
51
|
+
* @returns The inserted settings object
|
|
52
|
+
*/
|
|
53
|
+
insertSettings(newSettings) {
|
|
54
|
+
// Update existing settings with new values
|
|
55
|
+
this.settings = {
|
|
56
|
+
...this.settings,
|
|
57
|
+
...newSettings,
|
|
58
|
+
};
|
|
59
|
+
return this.settings;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Manually set settings (useful for test setup)
|
|
63
|
+
*/
|
|
64
|
+
setSettings(settings) {
|
|
65
|
+
this.settings = settings;
|
|
66
|
+
}
|
|
67
|
+
/**
|
|
68
|
+
* Check if settings exist
|
|
69
|
+
*/
|
|
70
|
+
hasSettings() {
|
|
71
|
+
return this.settings !== null;
|
|
72
|
+
}
|
|
73
|
+
}
|
|
74
|
+
exports.SettingsStateManager = SettingsStateManager;
|
|
@@ -7,7 +7,7 @@ const pluginUrl = 'http://localhost:3009';
|
|
|
7
7
|
test_1.test.describe('Translator Plugin', () => {
|
|
8
8
|
let env;
|
|
9
9
|
test_1.test.beforeEach(async ({ page }) => {
|
|
10
|
-
env = new RimoriTestEnvironment_1.RimoriTestEnvironment({ page, pluginId });
|
|
10
|
+
env = new RimoriTestEnvironment_1.RimoriTestEnvironment({ page, pluginId, pluginUrl });
|
|
11
11
|
env.ai.mockGetObject({
|
|
12
12
|
gramatically_corrected_input_text: 'tree',
|
|
13
13
|
detected_language: 'English',
|
package/package.json
CHANGED
|
@@ -1,13 +1,18 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@rimori/playwright-testing",
|
|
3
|
-
"version": "0.2.2",
|
|
3
|
+
"version": "0.2.3-next.2",
|
|
4
4
|
"description": "Playwright testing utilities for Rimori plugins and workers",
|
|
5
5
|
"license": "Apache-2.0",
|
|
6
|
+
"repository": {
|
|
7
|
+
"type": "git",
|
|
8
|
+
"url": "https://github.com/rimori-org/playwright-testing.git"
|
|
9
|
+
},
|
|
6
10
|
"main": "dist/index.js",
|
|
7
11
|
"types": "dist/index.d.ts",
|
|
8
12
|
"source": "src/index.ts",
|
|
9
13
|
"scripts": {
|
|
10
14
|
"build": "tsc -p tsconfig.json",
|
|
15
|
+
"dev": "tsc -w --preserveWatchOutput -p tsconfig.json",
|
|
11
16
|
"clean": "rimraf dist",
|
|
12
17
|
"lint": "eslint \"src/**/*.{ts,tsx}\"",
|
|
13
18
|
"test": "playwright test",
|
|
@@ -20,7 +25,7 @@
|
|
|
20
25
|
"@playwright/test": "^1.40.0"
|
|
21
26
|
},
|
|
22
27
|
"dependencies": {
|
|
23
|
-
"@rimori/client": "
|
|
28
|
+
"@rimori/client": "2.2.0-next.1"
|
|
24
29
|
},
|
|
25
30
|
"devDependencies": {
|
|
26
31
|
"@playwright/test": "^1.40.0",
|