forked from openedx/frontend-app-authoring
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: reworked grading deadline (openedx#584)
- Loading branch information
1 parent
0880775
commit fbc3406
Showing
32 changed files
with
550 additions
and
559 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 |
---|---|---|
|
@@ -8,3 +8,5 @@ coverage: | |
default: | ||
target: auto | ||
threshold: 0% | ||
ignore: | ||
- "src/grading-settings/grading-scale/react-ranger.js" |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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
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
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
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
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
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
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
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,27 @@ | ||
/** | ||
* Time format conversions for values (hours or minutes) that are less than 10. | ||
* | ||
* @param {number} time - incoming time data. | ||
* @returns {string} - formatted time string. | ||
*/ | ||
export function formatTime(time) { | ||
return (time >= 10 ? time.toString() : `0${time}`); | ||
} | ||
|
||
/** | ||
* Validates inputStr as a time in HH:MM format. | ||
* | ||
* @param {string} inputStr - the input string to validate. | ||
* @param {function} setShowSavePrompt - a function to control save prompt display. | ||
* @param {function} setIsError - a function to set error state. | ||
* @returns {boolean} - returns `true` if `inputStr` is a valid time, else `false`. | ||
*/ | ||
export function timerValidation(inputStr, setShowSavePrompt, setIsError) { | ||
const timePattern = /^(?:[01]\d|2[0-3]):[0-5]\d$/; | ||
|
||
const isValid = timePattern.test(inputStr); | ||
setShowSavePrompt(isValid); | ||
setIsError(!isValid); | ||
|
||
return isValid; | ||
} |
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,42 @@ | ||
import { formatTime, timerValidation } from './utils'; | ||
|
||
const setShowSavePrompt = jest.fn(); | ||
const setIsError = jest.fn(); | ||
|
||
describe('formatTime', () => { | ||
it('formats single-digit time values correctly', () => { | ||
expect(formatTime(5)).toBe('05'); | ||
expect(formatTime(9)).toBe('09'); | ||
}); | ||
|
||
it('does not modify double-digit time values', () => { | ||
expect(formatTime(10)).toBe('10'); | ||
expect(formatTime(45)).toBe('45'); | ||
}); | ||
}); | ||
|
||
describe('timerValidation', () => { | ||
it('handles empty input', () => { | ||
const result = timerValidation('', setShowSavePrompt, setIsError); | ||
|
||
expect(result).toBe(false); | ||
expect(setShowSavePrompt).toHaveBeenCalledWith(false); | ||
expect(setIsError).toHaveBeenCalledWith(true); | ||
}); | ||
|
||
it('validates correct HH:MM input', () => { | ||
const result = timerValidation('12:34', setShowSavePrompt, setIsError); | ||
|
||
expect(result).toBe(true); | ||
expect(setShowSavePrompt).toHaveBeenCalledWith(true); | ||
expect(setIsError).toHaveBeenCalledWith(false); | ||
}); | ||
|
||
it('handles invalid input', () => { | ||
const result = timerValidation('abc', setShowSavePrompt, setIsError); | ||
|
||
expect(result).toBe(false); | ||
expect(setShowSavePrompt).toHaveBeenCalledWith(false); | ||
expect(setIsError).toHaveBeenCalledWith(true); | ||
}); | ||
}); |
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
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
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
Oops, something went wrong.