Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for Materia widgets in assessments. #1912

Open
wants to merge 6 commits into
base: dev/33-serpierite
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@
"packages/obonode/obojobo-chunks-iframe",
"packages/obonode/obojobo-chunks-list",
"packages/obonode/obojobo-chunks-materia",
"packages/obonode/obojobo-chunks-materia-assessment",
"packages/obonode/obojobo-chunks-math-equation",
"packages/obonode/obojobo-chunks-multiple-choice-assessment",
"packages/obonode/obojobo-chunks-numeric-assessment",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ $color-bg2: #f4f4f4;
$color-bg3: #131313;
$color-action-bg: #f9f4ff;
$color-correct: #38ae24;
$color-partially-correct: #ffc802;
$color-incorrect: #c21f00;
$color-survey: #48b8b9;
$color-alt-correct: #ffc802;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ const parserMap = new Map()
.set('ObojoboDraft.Chunks.IFrame', require('./parsers/iframe-node-parser'))
.set('ObojoboDraft.Chunks.List', require('./parsers/list-node-parser'))
.set('ObojoboDraft.Chunks.Materia', require('./parsers/materia-node-parser'))
.set('ObojoboDraft.Chunks.MateriaAssessment', require('./parsers/materia-assessment-node-parser'))
.set('ObojoboDraft.Chunks.MathEquation', require('./parsers/math-equation-node-parser'))
.set('ObojoboDraft.Chunks.MCAssessment.MCAnswer', require('./parsers/mc-answer-node-parser'))
.set('ObojoboDraft.Chunks.MCAssessment.MCChoice', require('./parsers/mc-choice-node-parser'))
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
const processAttrs = require('../process-attrs')
const processTriggers = require('../process-triggers')

const materiaAssessmentNodeParser = (node, childrenParser) => {
const id = node.id ? ` id="${node.id}"` : ''
const attrs = processAttrs(node.content, ['triggers', 'actions'])
const triggersXML = processTriggers(node.content.triggers)

return (
`<MateriaAssessment${attrs}${id}>` +
childrenParser(node.children) +
triggersXML +
`</MateriaAssessment>`
)
}

module.exports = materiaAssessmentNodeParser
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const nameMap = new Map()
.set('IFrame', 'ObojoboDraft.Chunks.IFrame')
.set('List', 'ObojoboDraft.Chunks.List')
.set('Materia', 'ObojoboDraft.Chunks.Materia')
.set('MateriaAssessment', 'ObojoboDraft.Chunks.MateriaAssessment')
.set('MathEquation', 'ObojoboDraft.Chunks.MathEquation')
.set('MCAnswer', 'ObojoboDraft.Chunks.MCAssessment.MCAnswer')
.set('MCAssessment', 'ObojoboDraft.Chunks.MCAssessment')
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
'use strict'

let dbm
let type
let seed

/**
* We receive the dbmigrate dependency from dbmigrate initially.
* This enables us to not have to rely on NODE_PATH.
*/
exports.setup = function(options, seedLink) {
dbm = options.dbmigrate
type = dbm.dataType
seed = seedLink
}

exports.up = function(db) {
return db
.createTable('external_tool_data', {
id: { type: 'bigserial', primaryKey: true },
created_at: {
type: 'timestamp WITH TIME ZONE',
notNull: true,
defaultValue: new String('now()')
},
payload: { type: 'jsonb' },
user_id: { type: 'bigint', notNull: true },
visit_id: { type: 'UUID', notNull: true },
draft_content_id: { type: 'UUID', notNull: true },
node_id: { type: 'UUID', notNull: true }
})
.then(result => {
return db.addIndex('external_tool_data', 'external_tool_data_user_id_index', ['user_id'])
})
.then(result => {
return db.addIndex('external_tool_data', 'external_tool_data_visit_id_index', ['visit_id'])
})
.then(result => {
return db.addIndex('external_tool_data', 'external_tool_data_draft_content_id_index', [
'draft_content_id'
])
})
.then(result => {
return db.addIndex('external_tool_data', 'external_tool_data_node_id_index', ['node_id'])
})
}

exports.down = function(db) {
return db.dropTable('external_tool_data')
}

exports._meta = {
version: 1
}
14 changes: 10 additions & 4 deletions packages/obonode/obojobo-chunks-abstract-assessment/constants.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
const CHOICE_NODE = 'ObojoboDraft.Chunks.AbstractAssessment.Choice'
const FEEDBACK_NODE = 'ObojoboDraft.Chunks.AbstractAssessment.Feedback'
const MATERIA_ASSESSMENT_NODE = 'ObojoboDraft.Chunks.MateriaAssessment'

// Whenever an inheriting component is created
// Add its Assessment type to the valid assessments, its answer type to valid answers
Expand All @@ -16,22 +17,27 @@ import {
} from 'obojobo-chunks-multiple-choice-assessment/constants'
import mcAssessment from 'obojobo-chunks-multiple-choice-assessment/empty-node.json'

import materiaAssessment from 'obojobo-chunks-materia-assessment/empty-node.json'

const assessmentToAnswer = {
[NUMERIC_ASSESSMENT_NODE]: numericAssessment.children[0].children[0],
[MC_ASSESSMENT_NODE]: mcAssessment.children[0].children[0]
[MC_ASSESSMENT_NODE]: mcAssessment.children[0].children[0],
[MATERIA_ASSESSMENT_NODE]: materiaAssessment.children[0]
}

const answerTypeToJson = {
[NUMERIC_ANSWER_NODE]: numericAssessment.children[0].children[0],
[MC_ANSWER_NODE]: mcAssessment.children[0].children[0]
[MC_ANSWER_NODE]: mcAssessment.children[0].children[0],
[MATERIA_ASSESSMENT_NODE]: materiaAssessment.children[0]
}

const answerToAssessment = {
[NUMERIC_ANSWER_NODE]: numericAssessment,
[MC_ANSWER_NODE]: mcAssessment
[MC_ANSWER_NODE]: mcAssessment,
[MATERIA_ASSESSMENT_NODE]: materiaAssessment
}

const validAssessments = [NUMERIC_ASSESSMENT_NODE, MC_ASSESSMENT_NODE]
const validAssessments = [NUMERIC_ASSESSMENT_NODE, MC_ASSESSMENT_NODE, MATERIA_ASSESSMENT_NODE]
const validAnswers = [NUMERIC_ANSWER_NODE, MC_ANSWER_NODE]

export {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
node_modules
coverage
3 changes: 3 additions & 0 deletions packages/obonode/obojobo-chunks-materia-assessment/.eslintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "eslint-config-obojobo"
}
2 changes: 2 additions & 0 deletions packages/obonode/obojobo-chunks-materia-assessment/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
coverage
node_modules
18 changes: 18 additions & 0 deletions packages/obonode/obojobo-chunks-materia-assessment/.npmignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
coverage
node_modules
npm-debug.log
yarn-error.log
*.DS_Store
__mocks__
__tests__
.vscode
.eslintignore
.eslintrc
.prettierignore
.stylelintignore
.stylelintrc
.scss-lint.yml
prettier.config.js
Dockerfile
__snapshots__
*.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
package.json
coverage
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
node_modules
coverage/
__snapshots__
*.js
*.jsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"extends": "stylelint-config-obojobo"
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Jest Snapshot v1, https://goo.gl/fbAQLP

exports[`MateriaAssessment viewer component renders 1`] = `
<div
className="obojobo-draft--chunks--materia is-not-open"
>
<div>
MockClassComponent Props:
{
"model": {
"id": "mock-uuid",
"content": {
"src": "http://www.example.com"
},
"metadata": {},
"index": 0,
"type": "ObojoboDraft.Chunks.MateriaAssessment",
"children": null
},
"moduleData": {
"model": {
"title": "mocked-module-title"
},
"navState": {
"visitId": "mock-visit-id"
}
},
"title": "Materia Widget"
}
</div>
<div
className="label"
>
<div>
MockClassComponent Props:
{
"parentModel": {
"id": "mock-uuid",
"content": {
"src": "http://www.example.com"
},
"metadata": {},
"index": 0,
"type": "ObojoboDraft.Chunks.MateriaAssessment",
"children": null
},
"textItem": {
"text": {
"styleList": {
"styles": []
},
"value": ""
},
"data": {},
"parent": {
"maxItems": 1,
"items": [
null
],
"dataTemplate": {}
}
},
"groupIndex": "0"
}
</div>
</div>
</div>
`;
11 changes: 11 additions & 0 deletions packages/obonode/obojobo-chunks-materia-assessment/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = function(api) {
api.cache(true)
return {
presets: ['@babel/preset-env', '@babel/preset-react'],
env: {
test: {
presets: ['@babel/preset-env', '@babel/preset-react']
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
const materiaChunkConverter = require('obojobo-chunks-materia/converter')

export default materiaChunkConverter
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import MateriaRegistration from 'obojobo-chunks-materia/editor-registration'

import emptyNode from './empty-node.json'

const MATERIA_ASSESSMENT_NODE = 'ObojoboDraft.Chunks.MateriaAssessment'

const MateriaAssessment = {
...MateriaRegistration,
name: MATERIA_ASSESSMENT_NODE,
menuLabel: 'Materia Widget Assessment',
json: {
emptyNode
}
}

export default MateriaAssessment
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
jest.mock('obojobo-chunks-materia/editor-component', () =>
global.mockReactComponent(this, 'MockMateria')
)
jest.mock('slate')
jest.mock('obojobo-chunks-materia/converter')

import MateriaAssessment from './editor-registration'

describe('Materia editorRegistration', () => {
test('has expected properties', () => {
// The editor registration for the MateriaAssessment chunk basically extends the
// editor registration for the Materia chunk, so it should look the same
expect(MateriaAssessment).toMatchInlineSnapshot(`
Object {
"helpers": Object {
"oboToSlate": [MockFunction],
"slateToObo": [MockFunction],
},
"icon": Object {},
"isContent": true,
"isInsertable": true,
"json": Object {
"emptyNode": Object {
"children": Array [
Object {
"text": "",
},
],
"content": Object {},
"type": "ObojoboDraft.Chunks.MateriaAssessment",
},
},
"menuLabel": "Materia Widget Assessment",
"name": "ObojoboDraft.Chunks.MateriaAssessment",
"plugins": Object {
"decorate": [Function],
"onKeyDown": [Function],
"renderNode": [Function],
},
}
`)
})
})
6 changes: 6 additions & 0 deletions packages/obonode/obojobo-chunks-materia-assessment/editor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
// Main entrypoint for editor
import Common from 'obojobo-document-engine/src/scripts/common'
import EditorNode from './editor-registration'

// register
Common.Registry.registerEditorModel(EditorNode)
24 changes: 24 additions & 0 deletions packages/obonode/obojobo-chunks-materia-assessment/editor.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
jest.mock('obojobo-document-engine/src/scripts/common/index', () => ({
Registry: {
registerEditorModel: jest.fn()
}
}))

jest.mock('./editor-registration', () => ({ EditorNode: 1 }))

import Common from 'obojobo-document-engine/src/scripts/common/index'

describe('Question editor script', () => {
test('registers node', () => {
// shouldn't have been called yet
expect(Common.Registry.registerEditorModel).toHaveBeenCalledTimes(0)

require('./editor')
const EditorRegistration = require('./editor-registration')

// the editor script should have registered the model
expect(Common.Registry.registerEditorModel).toHaveBeenCalledTimes(1)

expect(Common.Registry.registerEditorModel).toHaveBeenCalledWith(EditorRegistration)
})
})
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"type":"ObojoboDraft.Chunks.MateriaAssessment",
"content": { },
"children": [{ "text": "" }]
}
11 changes: 11 additions & 0 deletions packages/obonode/obojobo-chunks-materia-assessment/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
module.exports = {
obojobo: {
isOptional: true,
expressMiddleware: 'server/index.js',
clientScripts: {
viewer: 'viewer.js',
editor: 'editor.js'
},
serverScripts: ['server/materiaassessment']
}
}
Loading
Loading