-
Notifications
You must be signed in to change notification settings - Fork 147
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #290 from appwrite/test-cron-input
test: add cron input tests
- Loading branch information
Showing
1 changed file
with
121 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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); | ||
}); | ||
}); |
1796de0
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Successfully deployed to the following URLs:
console – ./
svelte-console.vercel.app
demo.appwriters.com
console-appwrite.vercel.app
brand-new-console.torsten.appwrite.org
console-git-main-appwrite.vercel.app