@koloseum/utils 0.1.1 → 0.1.3
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/package.json +5 -3
- package/src/utils.ts +32 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@koloseum/utils",
|
|
3
|
-
"version": "0.1.
|
|
3
|
+
"version": "0.1.3",
|
|
4
4
|
"author": "Koloseum Technologies Limited",
|
|
5
5
|
"description": "Utility logic for use across Koloseum web apps (TypeScript)",
|
|
6
6
|
"keywords": [
|
|
@@ -25,7 +25,7 @@
|
|
|
25
25
|
"test": "vitest --run"
|
|
26
26
|
},
|
|
27
27
|
"dependencies": {
|
|
28
|
-
"@koloseum/types": "^0.1.
|
|
28
|
+
"@koloseum/types": "^0.1.2",
|
|
29
29
|
"@supabase/supabase-js": "^2.48.1",
|
|
30
30
|
"@sveltejs/kit": "^2.17.1",
|
|
31
31
|
"any-date-parser": "^2.0.3",
|
|
@@ -33,8 +33,10 @@
|
|
|
33
33
|
"validator": "^13.12.0"
|
|
34
34
|
},
|
|
35
35
|
"devDependencies": {
|
|
36
|
+
"@playwright/test": "^1.50.1",
|
|
36
37
|
"@types/sanitize-html": "^2.13.0",
|
|
37
38
|
"@types/validator": "^13.12.2",
|
|
38
|
-
"typescript": "^5.0.0"
|
|
39
|
+
"typescript": "^5.0.0",
|
|
40
|
+
"vitest": "^3.0.5"
|
|
39
41
|
}
|
|
40
42
|
}
|
package/src/utils.ts
CHANGED
|
@@ -1,9 +1,11 @@
|
|
|
1
1
|
import type { Database } from "@koloseum/types/database";
|
|
2
|
-
import type { CustomError, SocialMediaPlatform } from "@koloseum/types/public/auth
|
|
2
|
+
import type { CustomError, SocialMediaPlatform } from "@koloseum/types/public/auth";
|
|
3
3
|
|
|
4
|
+
import type { Page, Locator } from "@playwright/test";
|
|
4
5
|
import type { PostgrestError, SupabaseClient } from "@supabase/supabase-js";
|
|
5
6
|
import type { MobilePhoneLocale } from "validator";
|
|
6
7
|
|
|
8
|
+
import { expect } from "@playwright/test";
|
|
7
9
|
import { FunctionsFetchError, FunctionsHttpError, FunctionsRelayError } from "@supabase/supabase-js";
|
|
8
10
|
import { error as svelteError } from "@sveltejs/kit";
|
|
9
11
|
|
|
@@ -262,3 +264,32 @@ export const Utility = {
|
|
|
262
264
|
*/
|
|
263
265
|
validateSocialMediaHandle: (handle: string) => !isURL(handle, { require_protocol: false }) && !handle.startsWith("@") && Boolean(handle.match(Utility.socialMediaHandleRegex)),
|
|
264
266
|
};
|
|
267
|
+
|
|
268
|
+
/* Testing functions */
|
|
269
|
+
export const Testing = {
|
|
270
|
+
/**
|
|
271
|
+
* Asserts the absence of a field on the page.
|
|
272
|
+
* @param {Locator[]} fields - The fields to check for absence
|
|
273
|
+
* @returns A promise that resolves when the check is complete
|
|
274
|
+
*/
|
|
275
|
+
assertFieldAbsence: async (...fields: Locator[]) => {
|
|
276
|
+
for (const field of fields) await expect(field).not.toBeVisible();
|
|
277
|
+
},
|
|
278
|
+
/**
|
|
279
|
+
* Clicks a locator and waits for a response.
|
|
280
|
+
* @param {Page} page - The page on which to click the locator
|
|
281
|
+
* @param {Locator} locator - The locator to click
|
|
282
|
+
* @param {string} endpoint - The endpoint to wait for
|
|
283
|
+
* @returns A promise that resolves when the click and response are complete
|
|
284
|
+
*/
|
|
285
|
+
clickAndWait: async (page: Page, locator: Locator, endpoint: string) => {
|
|
286
|
+
// Ensure the locator is visible
|
|
287
|
+
await expect(locator).toBeVisible();
|
|
288
|
+
|
|
289
|
+
// Click with force option to ensure the click happens
|
|
290
|
+
await locator.click({ force: true });
|
|
291
|
+
|
|
292
|
+
// Wait for the API response
|
|
293
|
+
await page.waitForResponse(endpoint);
|
|
294
|
+
},
|
|
295
|
+
};
|