-
Notifications
You must be signed in to change notification settings - Fork 584
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Teacher tool: field value validator added (#9867)
* field value validator added * change template string for num equality validator Co-authored-by: Eric Anderson <[email protected]> --------- Co-authored-by: Eric Anderson <[email protected]>
- Loading branch information
1 parent
d2e0ba5
commit 461a8db
Showing
5 changed files
with
75 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
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
21 changes: 21 additions & 0 deletions
21
pxteditor/code-validation/validateBlockFieldValueExists.ts
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,21 @@ | ||
// validates that one or more blocks comments are in the project | ||
// returns the blocks that have comments for teacher tool scenario | ||
export function validateBlockFieldValueExists({ usedBlocks, fieldType, fieldValue, specifiedBlock }: { | ||
usedBlocks: Blockly.Block[], | ||
fieldType: string, | ||
fieldValue: string, | ||
specifiedBlock: string, | ||
}): { | ||
successfulBlocks: Blockly.Block[], | ||
passed: boolean | ||
} { | ||
const enabledSpecifiedBlocks = usedBlocks.filter((block) => | ||
block.isEnabled() && block.type === specifiedBlock | ||
); | ||
|
||
const successfulBlocks = enabledSpecifiedBlocks.filter((block) => | ||
block.getFieldValue(fieldType) === fieldValue | ||
); | ||
|
||
return { successfulBlocks, passed: successfulBlocks.length > 0 }; | ||
} |