Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

description-validation.test.tsx 3.7KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. /**
  2. * Description Validation Test
  3. *
  4. * Tests for the 400-character description validation across App and Dataset
  5. * creation and editing workflows to ensure consistent validation behavior.
  6. */
  7. describe('Description Validation Logic', () => {
  8. // Simulate backend validation function
  9. const validateDescriptionLength = (description?: string | null) => {
  10. if (description && description.length > 400)
  11. throw new Error('Description cannot exceed 400 characters.')
  12. return description
  13. }
  14. describe('Backend Validation Function', () => {
  15. test('allows description within 400 characters', () => {
  16. const validDescription = 'x'.repeat(400)
  17. expect(() => validateDescriptionLength(validDescription)).not.toThrow()
  18. expect(validateDescriptionLength(validDescription)).toBe(validDescription)
  19. })
  20. test('allows empty description', () => {
  21. expect(() => validateDescriptionLength('')).not.toThrow()
  22. expect(() => validateDescriptionLength(null)).not.toThrow()
  23. expect(() => validateDescriptionLength(undefined)).not.toThrow()
  24. })
  25. test('rejects description exceeding 400 characters', () => {
  26. const invalidDescription = 'x'.repeat(401)
  27. expect(() => validateDescriptionLength(invalidDescription)).toThrow(
  28. 'Description cannot exceed 400 characters.',
  29. )
  30. })
  31. })
  32. describe('Backend Validation Consistency', () => {
  33. test('App and Dataset have consistent validation limits', () => {
  34. const maxLength = 400
  35. const validDescription = 'x'.repeat(maxLength)
  36. const invalidDescription = 'x'.repeat(maxLength + 1)
  37. // Both should accept exactly 400 characters
  38. expect(validDescription.length).toBe(400)
  39. expect(() => validateDescriptionLength(validDescription)).not.toThrow()
  40. // Both should reject 401 characters
  41. expect(invalidDescription.length).toBe(401)
  42. expect(() => validateDescriptionLength(invalidDescription)).toThrow()
  43. })
  44. test('validation error messages are consistent', () => {
  45. const expectedErrorMessage = 'Description cannot exceed 400 characters.'
  46. // This would be the error message from both App and Dataset backend validation
  47. expect(expectedErrorMessage).toBe('Description cannot exceed 400 characters.')
  48. const invalidDescription = 'x'.repeat(401)
  49. try {
  50. validateDescriptionLength(invalidDescription)
  51. }
  52. catch (error) {
  53. expect((error as Error).message).toBe(expectedErrorMessage)
  54. }
  55. })
  56. })
  57. describe('Character Length Edge Cases', () => {
  58. const testCases = [
  59. { length: 0, shouldPass: true, description: 'empty description' },
  60. { length: 1, shouldPass: true, description: '1 character' },
  61. { length: 399, shouldPass: true, description: '399 characters' },
  62. { length: 400, shouldPass: true, description: '400 characters (boundary)' },
  63. { length: 401, shouldPass: false, description: '401 characters (over limit)' },
  64. { length: 500, shouldPass: false, description: '500 characters' },
  65. { length: 1000, shouldPass: false, description: '1000 characters' },
  66. ]
  67. testCases.forEach(({ length, shouldPass, description }) => {
  68. test(`handles ${description} correctly`, () => {
  69. const testDescription = length > 0 ? 'x'.repeat(length) : ''
  70. expect(testDescription.length).toBe(length)
  71. if (shouldPass) {
  72. expect(() => validateDescriptionLength(testDescription)).not.toThrow()
  73. expect(validateDescriptionLength(testDescription)).toBe(testDescription)
  74. }
  75. else {
  76. expect(() => validateDescriptionLength(testDescription)).toThrow(
  77. 'Description cannot exceed 400 characters.',
  78. )
  79. }
  80. })
  81. })
  82. })
  83. })