diff --git a/src/lib/elements/forms/inputCron.svelte b/src/lib/elements/forms/inputCron.svelte
index f8eddaa53..078b5b7be 100644
--- a/src/lib/elements/forms/inputCron.svelte
+++ b/src/lib/elements/forms/inputCron.svelte
@@ -18,7 +18,7 @@
let element: HTMLInputElement;
let error: string;
- const pattern = String.raw`^[^]+\s+[^]+\s+[^]+\s+[^]+\s+[^]`;
+ const pattern = String.raw`^[^]+\s+[^]+\s+[^]+\s+[^]+\s+[^]+`;
onMount(() => {
if (element && autofocus) {
diff --git a/src/lib/helpers/timeConversion.ts b/src/lib/helpers/timeConversion.ts
index f43460240..0ae6387ed 100644
--- a/src/lib/helpers/timeConversion.ts
+++ b/src/lib/helpers/timeConversion.ts
@@ -1,3 +1,10 @@
+/**
+ * Formats the time in a human readable format.
+ *
+ * @export
+ * @param {number} time - The time in seconds.
+ * @returns {string} The formatted time string.
+ */
export function calculateTime(time: number) {
const milliseconds = Math.floor(time * 1000);
const seconds = Math.floor(time);
@@ -20,11 +27,13 @@ export function calculateTime(time: number) {
} else if (months < 12) {
return `${months}M`;
} else {
- return `${years} y`;
+ return `${years}y`;
}
}
-export function timeToSeconds(time: number, unit: string) {
+type Unit = 'ms' | 's' | 'm' | 'h' | 'd' | 'M' | 'y';
+
+export function timeToSeconds(time: number, unit: Unit) {
switch (unit) {
case 'ms':
return time / 1000;
@@ -44,7 +53,7 @@ export function timeToSeconds(time: number, unit: string) {
return time;
}
}
-export function timeToMinutes(time: number, unit: string) {
+export function timeToMinutes(time: number, unit: Unit) {
switch (unit) {
case 'ms':
return time / 1000 / 60;
@@ -64,3 +73,24 @@ export function timeToMinutes(time: number, unit: string) {
return time;
}
}
+
+export function secsToUnit(time: number, unit: Unit) {
+ switch (unit) {
+ case 'ms':
+ return time * 1000;
+ case 's':
+ return time;
+ case 'm':
+ return time / 60;
+ case 'h':
+ return time / 60 / 60;
+ case 'd':
+ return time / 60 / 60 / 24;
+ case 'M':
+ return time / 60 / 60 / 24 / 30;
+ case 'y':
+ return time / 60 / 60 / 24 / 30 / 12;
+ default:
+ return time;
+ }
+}
diff --git a/src/routes/console/project-[project]/auth/security/+page.svelte b/src/routes/console/project-[project]/auth/security/+page.svelte
index 60360d7df..beea9ce44 100644
--- a/src/routes/console/project-[project]/auth/security/+page.svelte
+++ b/src/routes/console/project-[project]/auth/security/+page.svelte
@@ -1,237 +1,12 @@
-
- Users Limit
-
- Limit new users from signing up for your project, regardless of authentication method.
- You can still create users and team memberships from your Appwrite console.
- The maximum limit is 10,000 users.
-
-
-
-
-
-
-
- {
- updateLimit();
- }}>Update
-
-
-
-
- Session Length
-
- If you reduce the limit, users who are currently logged in will be logged out of the
- application.
-
-
-
-
-
-
- {
- updateSessionLength();
- }}>
- Update
-
-
-
-
-
+
+
+
diff --git a/src/routes/console/project-[project]/auth/security/updateSessionLength.svelte b/src/routes/console/project-[project]/auth/security/updateSessionLength.svelte
new file mode 100644
index 000000000..d6b34d872
--- /dev/null
+++ b/src/routes/console/project-[project]/auth/security/updateSessionLength.svelte
@@ -0,0 +1,105 @@
+
+
+
+ Session Length
+
+
+ If you reduce the limit, users who are currently logged in will be logged out of the
+ application.
+
+
+
+
+
+
+ {
+ updateSessionLength();
+ }}>
+ Update
+
+
+
diff --git a/src/routes/console/project-[project]/auth/security/updateSessionsLimit.svelte b/src/routes/console/project-[project]/auth/security/updateSessionsLimit.svelte
new file mode 100644
index 000000000..46e8e3f3d
--- /dev/null
+++ b/src/routes/console/project-[project]/auth/security/updateSessionsLimit.svelte
@@ -0,0 +1,46 @@
+
+
+
diff --git a/src/routes/console/project-[project]/auth/security/updateUsersLimit.svelte b/src/routes/console/project-[project]/auth/security/updateUsersLimit.svelte
new file mode 100644
index 000000000..807630fdb
--- /dev/null
+++ b/src/routes/console/project-[project]/auth/security/updateUsersLimit.svelte
@@ -0,0 +1,117 @@
+
+
+
+ Users Limit
+
+ Limit new users from signing up for your project, regardless of authentication method. You
+ can still create users and team memberships from your Appwrite console.
+ The maximum limit is 10,000 users.
+
+
+
+
+
+
+
+ {
+ updateLimit();
+ }}>Update
+
+
diff --git a/src/routes/console/project-[project]/overview/platforms/wizard/flutter/step1.svelte b/src/routes/console/project-[project]/overview/platforms/wizard/flutter/step1.svelte
index 812d2a1ff..3f7b37a27 100644
--- a/src/routes/console/project-[project]/overview/platforms/wizard/flutter/step1.svelte
+++ b/src/routes/console/project-[project]/overview/platforms/wizard/flutter/step1.svelte
@@ -113,7 +113,7 @@
Register your Flutter app
-
+
(platform = Platform.Android)}
diff --git a/tests/unit/elements/inputCron.test.ts b/tests/unit/elements/inputCron.test.ts
new file mode 100644
index 000000000..5cfc01594
--- /dev/null
+++ b/tests/unit/elements/inputCron.test.ts
@@ -0,0 +1,121 @@
+import '@testing-library/jest-dom';
+import { render } from '@testing-library/svelte';
+import userEvent from '@testing-library/user-event';
+import { InputCron } from '../../../src/lib/elements/forms';
+
+const validStrings = [
+ '*/2 */2 * * *',
+ '* * * * *',
+ '* 20,21,22 * * *',
+ // Handles CSV values
+ '* 20,22 * * *',
+ // CSV values can be complex
+ '7-9 * */9 * *',
+ // 15th minute, of the second hour, every 15 days, in January, every Friday
+ '1 * * * 7',
+ // Test with exact times
+ '47 21 * * *',
+ // Test Day of the week
+ // According cron implementation, 0|7 = sunday, 1 => monday, etc
+ '* * * * 0',
+ '* * * * 7',
+ '* * * * 1',
+ // Should return the sunday date as 7 equals 0
+ '0 0 * * MON,SUN',
+ '0 0 * * 1,7',
+ '0 0 * * 0-4',
+ '0 0 * * 7-4',
+ '0 0 * * 4-7',
+ '0 0 * * 7-3',
+ '0 0 * * 3-7',
+ '0 0 * * 3-7',
+ // Test lists of values and ranges (Abhoryo)
+ '0 0 * * 2-7',
+ '0 0 * * 2-7',
+ '0 0 * * 4-7',
+ // Test increments of ranges
+ '0-12/4 * * * *',
+ '4-59/2 * * * *',
+ '4-59/2 * * * *',
+ '4-59/3 * * * *',
+ // Test Day of the Week and the Day of the Month
+ '0 0 1 1 0',
+ '0 0 1 JAN 0',
+ '0 0 1 * 0',
+ // Test the W day of the week modifier for day of the month field
+ '0 0 2W * *',
+ '0 0 1W * *',
+ '0 0 1W * *',
+ '0 0 3W * *',
+ '0 0 16W * *',
+ '0 0 28W * *',
+ '0 0 30W * *',
+ '0 0 31W * *',
+ // Test the last weekday of a month
+ '* * * * 5L',
+ '* * * * 6L',
+ '* * * * 7L',
+ '* * * * 1L',
+ '* * * 1 5L',
+ // Test the hash symbol for the nth weekday of a given month
+ '* * * * 5#2',
+ '* * * * 5#1',
+ '* * * * 3#4',
+ // make sure that casing is less relevant for shortcuts, months, and days
+ '0 1 15 JUL mon,Wed,FRi',
+ '0 1 15 jul mon,Wed,FRi',
+ //DOW and DOM do not support ?
+ '0 12 * * ?',
+ '0 12 ? * *',
+ '0-59/59 10 * * *',
+ '0-59/59 10 * * *',
+ '0-59/59 10 * * *',
+ '0-59/65 10 * * *',
+ '41-59/24 5 * * *'
+];
+const invalidStrings = ['invalid', '*', '* *', '* * *', '* * * *'];
+
+test('shows id input', () => {
+ const { getByPlaceholderText } = render(InputCron, { label: 'Cron', id: 'cron' });
+ const input = getByPlaceholderText('* * * * *');
+
+ expect(input).toBeInTheDocument();
+ expect(input).toHaveAttribute('type', 'text');
+});
+
+test('state', async () => {
+ const { component, getByPlaceholderText } = render(InputCron, {
+ value: '',
+ label: 'Cron',
+ id: 'cron'
+ });
+ const input = getByPlaceholderText('* * * * *');
+
+ expect(component.value).toEqual('');
+ await userEvent.type(input, 'lorem');
+ expect(component.value).toEqual('lorem');
+});
+
+validStrings.forEach((validString) => {
+ test(`validates ${validString} as valid`, () => {
+ const { getByPlaceholderText } = render(InputCron, {
+ value: validString,
+ label: 'Cron',
+ id: 'cron'
+ });
+ const input = getByPlaceholderText('* * * * *') as HTMLInputElement;
+ expect(input.checkValidity()).toBe(true);
+ });
+});
+
+invalidStrings.forEach((invalidString) => {
+ test(`validates ${invalidString} as invalid`, () => {
+ const { getByPlaceholderText } = render(InputCron, {
+ value: invalidString,
+ label: 'Cron',
+ id: 'cron'
+ });
+ const input = getByPlaceholderText('* * * * *') as HTMLInputElement;
+ expect(input.checkValidity()).toBe(false);
+ });
+});
diff --git a/tests/unit/helpers/timeConversion.test.ts b/tests/unit/helpers/timeConversion.test.ts
new file mode 100644
index 000000000..b1ae225ee
--- /dev/null
+++ b/tests/unit/helpers/timeConversion.test.ts
@@ -0,0 +1,170 @@
+import {
+ calculateTime,
+ timeToSeconds,
+ timeToMinutes,
+ secsToUnit
+} from '$lib/helpers/timeConversion';
+
+describe('Calculate time', () => {
+ const tests: Array<[number, string]> = [
+ [0.5, '500ms'],
+ [1, '1s'],
+ [1.5, '1s'],
+ [59, '59s'],
+ [60, '1m'],
+ [61, '1m'],
+ [119, '1m'],
+ [120, '2m'],
+ [121, '2m'],
+ [3599, '59m'],
+ [3600, '1h'],
+ [3601, '1h'],
+ [7199, '1h'],
+ [7200, '2h'],
+ [7201, '2h'],
+ [86399, '23h'],
+ [86400, '1d'],
+ [86401, '1d'],
+ [172799, '1d'],
+ [172800, '2d'],
+ [172801, '2d'],
+ [2591999, '29d'],
+ [2592000, '1M'],
+ [2592001, '1M'],
+ [31103999, '11M'],
+ [31104000, '1y'],
+ [31104001, '1y']
+ ];
+
+ tests.forEach(([input, expected]) => {
+ it(`should return ${expected} for ${input}`, () => {
+ expect(calculateTime(input)).toBe(expected);
+ });
+ });
+});
+
+describe('Time to seconds', () => {
+ const tests: Array<{
+ args: Parameters;
+ expected: ReturnType;
+ }> = [
+ // ms
+ { args: [0, 'ms'], expected: 0 },
+ { args: [1000, 'ms'], expected: 1 },
+ { args: [1000 * 60, 'ms'], expected: 60 },
+ // seconds
+ { args: [0, 's'], expected: 0 },
+ { args: [1, 's'], expected: 1 },
+ { args: [60, 's'], expected: 60 },
+ // minutes
+ { args: [0, 'm'], expected: 0 },
+ { args: [1, 'm'], expected: 60 },
+ { args: [60, 'm'], expected: 60 * 60 },
+ // hours
+ { args: [0, 'h'], expected: 0 },
+ { args: [1, 'h'], expected: 60 * 60 },
+ { args: [24, 'h'], expected: 60 * 60 * 24 },
+ // days
+ { args: [0, 'd'], expected: 0 },
+ { args: [1, 'd'], expected: 60 * 60 * 24 },
+ { args: [30, 'd'], expected: 60 * 60 * 24 * 30 },
+ // months
+ { args: [0, 'M'], expected: 0 },
+ { args: [1, 'M'], expected: 60 * 60 * 24 * 30 },
+ { args: [12, 'M'], expected: 60 * 60 * 24 * 30 * 12 },
+ // years
+ { args: [0, 'y'], expected: 0 },
+ { args: [1, 'y'], expected: 60 * 60 * 24 * 30 * 12 },
+ { args: [10, 'y'], expected: 60 * 60 * 24 * 30 * 12 * 10 }
+ ];
+
+ tests.forEach(({ args, expected }) => {
+ it(`should return ${expected} for ${args}`, () => {
+ expect(timeToSeconds(...args)).toBe(expected);
+ });
+ });
+});
+
+describe('Time to minutes', () => {
+ const tests: Array<{
+ args: Parameters;
+ expected: ReturnType;
+ }> = [
+ // ms
+ { args: [0, 'ms'], expected: 0 },
+ { args: [1000 * 60, 'ms'], expected: 1 },
+ { args: [1000 * 60 * 60, 'ms'], expected: 60 },
+ // seconds
+ { args: [0, 's'], expected: 0 },
+ { args: [60, 's'], expected: 1 },
+ { args: [60 * 60, 's'], expected: 60 },
+ // minutes
+ { args: [0, 'm'], expected: 0 },
+ { args: [60, 'm'], expected: 60 },
+ { args: [60 * 24, 'm'], expected: 60 * 24 },
+ // hours
+ { args: [0, 'h'], expected: 0 },
+ { args: [1, 'h'], expected: 60 },
+ { args: [24, 'h'], expected: 60 * 24 },
+ // days
+ { args: [0, 'd'], expected: 0 },
+ { args: [1, 'd'], expected: 60 * 24 },
+ { args: [30, 'd'], expected: 60 * 24 * 30 },
+ // months
+ { args: [0, 'M'], expected: 0 },
+ { args: [1, 'M'], expected: 60 * 24 * 30 },
+ { args: [12, 'M'], expected: 60 * 24 * 30 * 12 },
+ // years
+ { args: [0, 'y'], expected: 0 },
+ { args: [1, 'y'], expected: 60 * 24 * 30 * 12 },
+ { args: [2, 'y'], expected: 60 * 24 * 30 * 12 * 2 }
+ ];
+
+ tests.forEach(({ args, expected }) => {
+ it(`should return ${expected} for ${args}`, () => {
+ expect(timeToMinutes(...args)).toBe(expected);
+ });
+ });
+});
+
+describe('Seconds to unit', () => {
+ const tests: Array<{
+ args: Parameters;
+ expected: ReturnType;
+ }> = [
+ // ms
+ { args: [0, 'ms'], expected: 0 },
+ { args: [1, 'ms'], expected: 1000 },
+ { args: [60, 'ms'], expected: 60 * 1000 },
+ // seconds
+ { args: [0, 's'], expected: 0 },
+ { args: [1, 's'], expected: 1 },
+ { args: [60, 's'], expected: 60 },
+ // minutes
+ { args: [0, 'm'], expected: 0 },
+ { args: [1, 'm'], expected: 1 / 60 },
+ { args: [60, 'm'], expected: 1 },
+ // hours
+ { args: [0, 'h'], expected: 0 },
+ { args: [1, 'h'], expected: 1 / 60 / 60 },
+ { args: [60 * 60, 'h'], expected: 1 },
+ // days
+ { args: [0, 'd'], expected: 0 },
+ { args: [1, 'd'], expected: 1 / 60 / 60 / 24 },
+ { args: [60 * 60 * 24, 'd'], expected: 1 },
+ // months
+ { args: [0, 'M'], expected: 0 },
+ { args: [1, 'M'], expected: 1 / 60 / 60 / 24 / 30 },
+ { args: [60 * 60 * 24 * 30, 'M'], expected: 1 },
+ // years
+ { args: [0, 'y'], expected: 0 },
+ { args: [1, 'y'], expected: 1 / 60 / 60 / 24 / 30 / 12 },
+ { args: [60 * 60 * 24 * 30 * 12, 'y'], expected: 1 }
+ ];
+
+ tests.forEach(({ args, expected }) => {
+ it(`should return ${expected} for ${args}`, () => {
+ expect(secsToUnit(...args)).toBe(expected);
+ });
+ });
+});