Skip to content

Commit

Permalink
Merge pull request #48 from ucfopen/dev/1.2.0
Browse files Browse the repository at this point in the history
Dev/1.2.0
  • Loading branch information
clpetersonucf authored Apr 17, 2024
2 parents a8badba + 42a00e4 commit 0938809
Show file tree
Hide file tree
Showing 21 changed files with 5,793 additions and 4,211 deletions.
8 changes: 4 additions & 4 deletions .github/workflows/release-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -11,14 +11,14 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.x]
node-version: [18.13.0]

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v5

- name: Test and build with node ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}

Expand All @@ -32,4 +32,4 @@ jobs:
file: build/_output/*
tag: ${{ github.ref }}
overwrite: true
file_glob: true
file_glob: true
8 changes: 4 additions & 4 deletions .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,17 @@ jobs:
runs-on: ubuntu-latest
strategy:
matrix:
node-version: [12.3.1]
node-version: [18.13.0]

steps:
- name: Checkout code
uses: actions/checkout@v2
uses: actions/checkout@v4

- name: Run tests with Node.js ${{ matrix.node-version }}
uses: actions/setup-node@v1
uses: actions/setup-node@v3
with:
node-version: ${{ matrix.node-version }}
- run: npm install -g yarn
- run: yarn install
- run: yarn test-ci
- run: yarn build
- run: yarn build
13 changes: 7 additions & 6 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,18 @@
},
"version": "1.1.7",
"dependencies": {
"materia-widget-development-kit": "2.5.2"
"materia-widget-development-kit": "~3.0.0"
},
"devDependencies": {
"angular": "1.6.9",
"angular-mocks": "~1.5.0",
"jest": "^23.6.0",
"jest-coffee-preprocessor": "^1.0.0"
},
"scripts": {
"start": "webpack-dev-server",
"build": "webpack -p",
"build-dev": "webpack",
"start": "mwdk-start",
"build": "mwdk-build-prod",
"build-dev": "mwdk-build-dev",
"test": "TZ='America/New_York' jest --verbose",
"test-ci": "TZ='America/New_York' CI=true jest --ci --useStderr --coverage --coverageReporters text-summary cobertura"
},
Expand All @@ -37,10 +38,10 @@
],
"coverageThreshold": {
"global": {
"statements": 92,
"statements": 91,
"branches": 76,
"functions": 93,
"lines": 93
"lines": 92
}
}
},
Expand Down
1 change: 1 addition & 0 deletions src/assets/materia-logo.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file removed src/assets/materialogo.png
Binary file not shown.
8 changes: 8 additions & 0 deletions src/controllers/__snapshots__/creator.test.js.snap
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ Object {
"name": "null",
},
],
"options": Object {
"enableQuestionBank": false,
"questionBankVal": 1,
},
}
`;

Expand Down Expand Up @@ -119,6 +123,10 @@ Object {
"name": "null",
},
],
"options": Object {
"enableQuestionBank": false,
"questionBankVal": 1,
},
}
`;

Expand Down
46 changes: 30 additions & 16 deletions src/controllers/creator.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
Matching = angular.module 'matching', ['ngAnimate']

Matching.controller 'matchingCreatorCtrl', ['$scope', '$sce', ($scope, $sce) ->
angular.module 'matching', ['ngAnimate']
.controller 'matchingCreatorCtrl', ['$scope', '$sce', ($scope, $sce) ->
_qset = {}
materiaCallbacks = {}
# Stores data to be gathered on save.
Expand All @@ -9,8 +8,22 @@ Matching.controller 'matchingCreatorCtrl', ['$scope', '$sce', ($scope, $sce) ->
wordPairs : []
uniqueIds : []

$scope.acceptedMediaTypes = ['mp3']
$scope.acceptedMediaTypes = ['audio']
audioRef = []
$scope.questionBankDialog = false
$scope.enableQuestionBank = false
$scope.questionBankValTemp = 1
$scope.questionBankVal = 1

$scope.autoSize = (pair, audio) ->
question = pair.question or ''
answer = pair.answer or ''
len = if question.length > answer.length then question.length else answer.length
if audio == true
size = if len > 15 then 85 + len * 1.1 else 85
else
size = if len > 15 then 25 + len * 1.1 else 25
height: size + 'px'

# Adds and removes a pair of textareas for users to input a word pair.
$scope.addWordPair = (q=null, a=null, media=[0,0], id='') ->
Expand All @@ -28,6 +41,11 @@ Matching.controller 'matchingCreatorCtrl', ['$scope', '$sce', ($scope, $sce) ->
materiaCallbacks.initExistingWidget = (title, widget, qset, version, baseUrl) ->
_items = qset.items[0].items

if qset.options
$scope.enableQuestionBank = if qset.options.enableQuestionBank then qset.options.enableQuestionBank else false
$scope.questionBankVal = if qset.options.questionBankVal then qset.options.questionBankVal else 1
$scope.questionBankValTemp = if qset.options.questionBankVal then qset.options.questionBankVal else 1

$scope.$apply ->
$scope.widget.title = title
$scope.widget.wordPairs = []
Expand Down Expand Up @@ -77,21 +95,16 @@ Matching.controller 'matchingCreatorCtrl', ['$scope', '$sce', ($scope, $sce) ->
$scope.hideCover()

$scope.hideCover = ->
$scope.showTitleDialog = $scope.showIntroDialog = $scope.showErrorDialog = false

$scope.autoSize = (pair, audio) ->
question = pair.question or ''
answer = pair.answer or ''
len = if question.length > answer.length then question.length else answer.length
if audio == true
size = if len > 15 then 85 + len * 1.1 else 85
else
size = if len > 15 then 25 + len * 1.1 else 25
height: size + 'px'
$scope.showTitleDialog = $scope.showIntroDialog = $scope.showErrorDialog = $scope.questionBankDialog = false
$scope.questionBankValTemp = $scope.questionBankVal

$scope.audioUrl = (assetId) ->
# use $sce.trustAsResourceUrl to avoid interpolation error
$sce.trustAsResourceUrl Materia.CreatorCore.getMediaUrl(assetId + ".mp3")
$sce.trustAsResourceUrl Materia.CreatorCore.getMediaUrl(assetId)

$scope.validateQuestionBankVal = ->
if ($scope.questionBankValTemp >= 1 && $scope.questionBankValTemp <= $scope.widget.wordPairs.length)
$scope.questionBankVal = $scope.questionBankValTemp

# prevents duplicate ids
createUniqueAudioAnswerId = () ->
Expand All @@ -116,6 +129,7 @@ Matching.controller 'matchingCreatorCtrl', ['$scope', '$sce', ($scope, $sce) ->

_buildSaveData = ->
_qset.items = []
_qset.options = {enableQuestionBank: $scope.enableQuestionBank, questionBankVal: $scope.questionBankVal}
_qset.items[0] =
name: "null"
items: []
Expand Down
34 changes: 32 additions & 2 deletions src/controllers/creator.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -234,8 +234,8 @@ describe('Matching Creator Controller', function(){
//angular's $sce does some weird un/wrapping, usually it would handle this
var url = $scope.audioUrl('audioId').$$unwrapTrustedValue();

expect(Materia.CreatorCore.getMediaUrl).toHaveBeenCalledWith('audioId.mp3');
expect(url).toBe('http://mock-url/audioId.mp3');
expect(Materia.CreatorCore.getMediaUrl).toHaveBeenCalledWith('audioId');
expect(url).toBe('http://mock-url/audioId');
});

it('should import questions without assets', function(){
Expand Down Expand Up @@ -345,6 +345,36 @@ describe('Matching Creator Controller', function(){
// expect($scope.widget.wordPairs[2].media[1]).toBe('testId2');
});

it('should give default qset options if question bank options are undefined', function () {

qset.data.options = {};
materiaCallbacks.initExistingWidget('matcher', widgetInfo, qset.data);

expect($scope.enableQuestionBank).toBe(false);
expect($scope.questionBankVal).toBe(1);
expect($scope.questionBankValTemp).toBe(1);
});

it('should update questionBankVal if questionBankValTemp is valid within the range', function () {

qset.data.options = {enableQuestionBank: true, questionBankVal: 6};
materiaCallbacks.initExistingWidget('matcher', widgetInfo, qset.data);

// set initial values where questionBankValTemp is invalid
$scope.questionBankValTemp = 11;
$scope.validateQuestionBankVal();

// expect questionBankVal to change to wordPairs value
expect($scope.questionBankVal).toBe(6);

// this time questionBankValTemp is valid
$scope.questionBankValTemp = 8;
$scope.validateQuestionBankVal();

// expect questionBankVal to be updated to questionBankValTemp
expect($scope.questionBankVal).toBe(8);

});

it('should autosize correctly', function () {
var lessThan15chars = 'small';
Expand Down
18 changes: 13 additions & 5 deletions src/controllers/player.coffee
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
Matching = angular.module 'matching'

Matching.controller 'matchingPlayerCtrl', ['$scope', '$timeout', '$sce', ($scope, $timeout, $sce) ->
angular.module('matching', [])
.controller 'matchingPlayerCtrl', ['$scope', '$timeout', '$sce', ($scope, $timeout, $sce) ->
materiaCallbacks = {}
$scope.title = ''

Expand Down Expand Up @@ -46,6 +45,14 @@ Matching.controller 'matchingPlayerCtrl', ['$scope', '$timeout', '$sce', ($scope
materiaCallbacks.start = (instance, qset) ->
$scope.qset = qset
$scope.title = instance.name

# Update qset items to only include the number of questions specified in the question bank. Done here since $scope.totalItems depends on it.
if qset.options && qset.options.enableQuestionBank
_shuffle qset.items[0].items
qbItemsLength = qset.options.questionBankVal
rndStart = Math.floor(Math.random() * (qset.items[0].items.length - qbItemsLength + 1))
qset.items[0].items = qset.items[0].items.slice(rndStart, rndStart + qbItemsLength)

$scope.totalItems = qset.items[0].items.length
$scope.totalPages = Math.ceil $scope.totalItems/ITEMS_PER_PAGE

Expand All @@ -62,6 +69,7 @@ Matching.controller 'matchingPlayerCtrl', ['$scope', '$timeout', '$sce', ($scope
_itemIndex = 0
_pageIndex = 0
_indexShift = 0

# Splits the the last items over the last two pages
_leftover = $scope.totalItems % ITEMS_PER_PAGE
_splitPoint = ~~(4 + (_leftover - 1)/2)
Expand Down Expand Up @@ -245,7 +253,7 @@ Matching.controller 'matchingPlayerCtrl', ['$scope', '$timeout', '$sce', ($scope
$scope.answerCircles[$scope.currentPage][match2_AIndex].color = 'c0'
$scope.matches.splice indexOfAnswer, 1

_assistiveAlert $scope.pages[$scope.currentPage].questions[$scope.selectedQA[$scope.currentPage].question].text + ' matched with ' +
_assistiveAlert $scope.pages[$scope.currentPage].questions[$scope.selectedQA[$scope.currentPage].question].text + ' matched with ' +
$scope.pages[$scope.currentPage].answers[$scope.selectedQA[$scope.currentPage].answer].text

_pushMatch()
Expand Down Expand Up @@ -487,4 +495,4 @@ Matching.controller 'matchingPlayerCtrl', ['$scope', '$timeout', '$sce', ($scope
if alertEl then alertEl.innerHTML = msg

Materia.Engine.start materiaCallbacks
]
]
18 changes: 18 additions & 0 deletions src/controllers/player.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,17 @@ describe('Matching Player Controller', function(){
expect($scope.showInstructions).toBe(true);
});

it('should slice the qset if qb is enabled', function () {

// Enable question bank and set the number of questions to 3
qset.data.options = {enableQuestionBank: true, questionBankVal: 3}

materiaCallbacks.start(widgetInfo, qset.data);

// qset should be sliced to the length given by questionBankVal
expect(qset.data.items[0].items.length).toEqual(3);
});

it('should change to the previous page', inject(function ($timeout) {
materiaCallbacks.start(widgetInfo, qset.data);
Materia.Engine.getImageAssetUrl
Expand Down Expand Up @@ -476,6 +487,13 @@ describe('Matching Player Controller', function(){
expect($scope.pages[0].answers[0].text).toEqual('to change');
});

it('should return 0 progress when no items have been matched', function () {

materiaCallbacks.start(widgetInfo, qset.data);
$scope.totalItems = 0;
expect($scope.getProgressAmount()).toBe(0);
});

it('should correctly report the text of a match', function() {
materiaCallbacks.start(widgetInfo, qset.data);
setupQA();
Expand Down
Loading

0 comments on commit 0938809

Please sign in to comment.