More test cases and breaking out valid/invalid values to be reusable

This commit is contained in:
Jonathan Putney
2019-11-13 13:09:01 -05:00
parent 54b56e905f
commit 755259afdf
13 changed files with 1417 additions and 845 deletions

View File

@@ -0,0 +1,334 @@
const common_values = {
validResult: [
'correct',
'wrong',
'unanticipated',
'neutral',
],
invalidResult: [
'-10000',
'10000',
'invalid',
],
valid0To1Range: [
'0.0',
'0.25',
'0.5',
'1.0',
],
invalid0To1Range: [
'-1',
'-0.1',
'1.1',
'.25',
],
valid0To100Range: [
'1',
'50',
'100',
],
invalid0To100Range: [
'invalid',
'a100',
'-1',
],
validScaledRange: [
'1',
'0.5',
'0',
'-0.5',
'-1',
],
invalidScaledRange: [
'-101',
'25.1',
'50.5',
'75',
'100',
],
validIntegerScaledRange: [
'1',
'0',
'-1',
],
invalidIntegerScaledRange: [
'-101',
'-0.5',
'0.5',
'25.1',
'50.5',
'75',
'100',
],
};
export const scorm12_values = {
...common_values, ...{
validLessonStatus: [
'passed',
'completed',
'failed',
'incomplete',
'browsed',
],
invalidLessonStatus: [
'Passed',
'P',
'F',
'p',
'true',
'false',
'complete',
],
validExit: [
'time-out',
'suspend',
'logout',
],
invalidExit: [
'close',
'exit',
'crash',
],
validType: [
'true-false',
'choice',
'fill-in',
'matching',
'performance',
'sequencing',
'likert',
'numeric',
],
invalidType: [
'correct',
'wrong',
'logout',
],
validSpeedRange: [
'1',
'50',
'100',
'-1',
'-50',
'-100',
],
invalidSpeedRange: [
'invalid',
'a100',
'-101',
'101',
'-100000',
'100000',
],
validScoreRange: [
'1',
'50.25',
'100',
],
invalidScoreRange: [
'invalid',
'a100',
'-1',
'101',
'-100000',
'100000',
],
invalid0To100Range: [
'invalid',
'a100',
'-2',
],
validTime: [
'10:06:57',
'23:59:59',
'00:00:00',
],
invalidTime: [
'47:59:59',
'00:00:01.56',
'06:5:13',
'23:59:59.123',
'P1DT23H59M59S',
],
validTimestamp: [
'10:06:57',
'00:00:01.56',
'23:59:59',
'47:59:59',
],
invalidTimestamp: [
'06:5:13',
'23:59:59.123',
'P1DT23H59M59S',
],
},
};
export const scorm2004_values = {
...common_values, ...{
// valid field values
validTimestamps: [
'2019-06-25',
'2019-06-25T23:59',
'2019-06-25T23:59:59.99',
'1970-01-01',
],
invalidTimestamps: [
'2019-06-25T',
'2019-06-25T23:59:59.999',
'2019-06-25T25:59:59.99',
'2019-13-31',
'1969-12-31',
'-00:00:30',
'0:50:30',
'23:00:30.',
],
validCStatus: [
'completed',
'incomplete',
'not attempted',
'unknown',
],
invalidCStatus: [
'complete',
'passed',
'failed',
],
validSStatus: [
'passed',
'failed',
'unknown',
],
invalidSStatus: [
'complete',
'incomplete',
'P',
'f',
],
validExit: [
'time-out',
'suspend',
'logout',
'normal',
],
invalidExit: [
'close',
'exit',
'crash',
],
validType: [
'true-false',
'choice',
'fill-in',
'long-fill-in',
'matching',
'performance',
'sequencing',
'likert',
'numeric',
'other',
],
invalidType: [
'correct',
'wrong',
'logout',
],
validScoreRange: [
'1',
'50',
'100',
'-10000',
'-1',
'10000',
],
invalidScoreRange: [
'invalid',
'a100',
'-100000',
'100000',
],
validISO8601Durations: [
'P1Y34DT23H45M15S',
'PT1M45S',
'P0S',
'PT75M',
],
invalidISO8601Durations: [
'00:08:45',
'-P1H',
'1y45D',
'0',
],
validComment: [
'{lang=en-98} learner comment',
'{lang=eng-98-9} learner comment',
'{lang=eng-98-9fhgj}' + 'x'.repeat(4000),
'learner comment',
'learner comment}',
'{lang=i-xx}',
'{lang=i}',
'',
],
invalidComment: [
'{lang=i-}',
'{lang=i-x}',
'{lang=eng-98-9fhgj}{ learner comment',
'{learner comment',
'{lang=eng-98-9fhgj}' + 'x'.repeat(4001),
'{lang=eng-98-9fhgj}{' + 'x'.repeat(3999),
],
validDescription: [
'{lang=en-98} learner comment',
'{lang=eng-98-9} learner comment',
'{lang=eng-98-9fhgj}' + 'x'.repeat(250),
'learner comment',
'learner comment}',
'{lang=i-xx}',
'{lang=i}',
'',
],
invalidDescription: [
'{lang=i-}',
'{lang=i-x}',
'{lang=eng-98-9fhgj}{ learner comment',
'{learner comment',
'{lang=eng-98-9fhgj}' + 'x'.repeat(251),
'{lang=eng-98-9fhgj}{' + 'x'.repeat(249),
],
validNavRequest: [
'previous',
'continue',
'exit',
'exitAll',
'abandon',
'abandonAll',
'suspendAll',
],
invalidNavRequest: [
'close',
'quit',
'next',
'before',
],
},
};

78
src/constants/regex.js Normal file
View File

@@ -0,0 +1,78 @@
// @flow
import {scorm12_values, scorm2004_values} from './field_values';
export const scorm12_regex = {
CMIString256: '^.{0,255}$',
CMIString4096: '^.{0,4096}$',
CMITime: '^(?:[01]\\d|2[0123]):(?:[012345]\\d):(?:[012345]\\d)$', // eslint-disable-line
CMITimespan: '^([0-9]{2,}):([0-9]{2}):([0-9]{2})(\.[0-9]{1,2})?$', // eslint-disable-line
CMIInteger: '^\\d+$',
CMISInteger: '^-?([0-9]+)$',
CMIDecimal: '^-?([0-9]{0,3})(\.[0-9]*)?$', // eslint-disable-line
CMIIdentifier: '^[\\u0021-\\u007E]{0,255}$',
CMIFeedback: '^.{0,255}$', // This must be redefined
CMIIndex: '[._](\\d+).',
// Vocabulary Data Type Definition
CMIStatus: '^(' + scorm12_values.validLessonStatus.join('|') + ')$',
CMIStatus2: '^(' + scorm12_values.validLessonStatus.join('|') + '|not attempted)$',
CMIExit: '^(' + scorm12_values.validExit.join('|') + '|)$',
CMIType: '^(' + scorm12_values.validType.join('|') + ')$',
CMIResult: '^(' + scorm12_values.validResult.join('|') + '|([0-9]{0,3})?(\\.[0-9]*)?)$', // eslint-disable-line
NAVEvent: '^(previous|continue)$',
// Data ranges
score_range: '0#100',
audio_range: '-1#100',
speed_range: '-100#100',
weighting_range: '-100#100',
text_range: '-1#1',
};
export const aicc_regex = {
...scorm12_regex, ...{
CMIIdentifier: '^\\w{1,255}$',
},
};
export const scorm2004_regex = {
CMIString200: '^[\\u0000-\\uFFFF]{0,200}$',
CMIString250: '^[\\u0000-\\uFFFF]{0,250}$',
CMIString1000: '^[\\u0000-\\uFFFF]{0,1000}$',
CMIString4000: '^[\\u0000-\\uFFFF]{0,4000}$',
CMIString64000: '^[\\u0000-\\uFFFF]{0,64000}$',
CMILang: '^([a-zA-Z]{2,3}|i|x)(\-[a-zA-Z0-9\-]{2,8})?$|^$', // eslint-disable-line
CMILangString250: '^(\{lang=([a-zA-Z]{2,3}|i|x)(\-[a-zA-Z0-9\-]{2,8})?\})?((?!\{.*$).{0,250}$)?$', // eslint-disable-line
CMILangcr: '^((\{lang=([a-zA-Z]{2,3}|i|x)?(\-[a-zA-Z0-9\-]{2,8})?\}))(.*?)$', // eslint-disable-line
CMILangString250cr: '^((\{lang=([a-zA-Z]{2,3}|i|x)?(\-[a-zA-Z0-9\-]{2,8})?\})?(.{0,250})?)?$', // eslint-disable-line
CMILangString4000: '^(\{lang=([a-zA-Z]{2,3}|i|x)(\-[a-zA-Z0-9\-]{2,8})?\})?((?!\{.*$).{0,4000}$)?$', // eslint-disable-line
CMITime: '^(19[7-9]{1}[0-9]{1}|20[0-2]{1}[0-9]{1}|203[0-8]{1})((-(0[1-9]{1}|1[0-2]{1}))((-(0[1-9]{1}|[1-2]{1}[0-9]{1}|3[0-1]{1}))(T([0-1]{1}[0-9]{1}|2[0-3]{1})((:[0-5]{1}[0-9]{1})((:[0-5]{1}[0-9]{1})((\\.[0-9]{1,2})((Z|([+|-]([0-1]{1}[0-9]{1}|2[0-3]{1})))(:[0-5]{1}[0-9]{1})?)?)?)?)?)?)?)?$',
CMITimespan: '^P(?:([.,\\d]+)Y)?(?:([.,\\d]+)M)?(?:([.,\\d]+)W)?(?:([.,\\d]+)D)?(?:T?(?:([.,\\d]+)H)?(?:([.,\\d]+)M)?(?:([.,\\d]+)S)?)?$',
CMIInteger: '^\\d+$',
CMISInteger: '^-?([0-9]+)$',
CMIDecimal: '^-?([0-9]{1,5})(\\.[0-9]{1,18})?$',
CMIIdentifier: '^\\S{1,250}[a-zA-Z0-9]$',
CMIShortIdentifier: '^[\\w\.]{1,250}$', // eslint-disable-line
CMILongIdentifier: '^(?:(?!urn:)\\S{1,4000}|urn:[A-Za-z0-9-]{1,31}:\\S{1,4000})$',
CMIFeedback: '^.*$', // This must be redefined
CMIIndex: '[._](\\d+).',
CMIIndexStore: '.N(\\d+).',
// Vocabulary Data Type Definition
CMICStatus: '^(' + scorm2004_values.validCStatus.join('|') + ')$',
CMISStatus: '^(' + scorm2004_values.validSStatus.join('|') + ')$',
CMIExit: '^(' + scorm2004_values.validExit.join('|') + ')$',
CMIType: '^(' + scorm2004_values.validType.join('|') + ')$',
CMIResult: '^(' + scorm2004_values.validResult.join('|') + '|-?([0-9]{1,4})(\\.[0-9]{1,18})?)$',
NAVEvent: '^(' + scorm2004_values.validNavRequest.join('|') + '|\{target=\\S{0,200}[a-zA-Z0-9]\}choice|jump)$', // eslint-disable-line
NAVBoolean: '^(unknown|true|false$)',
NAVTarget: '^(previous|continue|choice.{target=\\S{0,200}[a-zA-Z0-9]})$',
// Data ranges
scaled_range: '-1#1',
audio_range: '0#*',
speed_range: '0#*',
text_range: '-1#1',
progress_range: '0#1',
};

View File

@@ -1,5 +1,5 @@
// @flow
import {scorm2004_regex} from '../regex';
import {scorm2004_regex} from './regex';
export const learner_responses = {
'true-false': {