Skip to content

Commit

Permalink
Initial unit tests for front-end framework (#4576)
Browse files Browse the repository at this point in the history
Credit to @bennothommo
  • Loading branch information
bennothommo authored and LukeTowers committed Sep 25, 2019
1 parent 815ec1a commit 5f15ed5
Show file tree
Hide file tree
Showing 10 changed files with 808 additions and 3 deletions.
13 changes: 13 additions & 0 deletions .babelrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"presets": ["@babel/preset-env"],
"plugins": [
[
"module-resolver", {
"root": ["."],
"alias": {
"helpers": "./tests/js/helpers"
}
}
]
]
}
24 changes: 24 additions & 0 deletions .github/workflows/frontend-tests.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
name: Tests

on:
push:
branches:
- master
- develop
pull_request:

jobs:
frontendTests:
runs-on: ubuntu-latest
name: JavaScript
steps:
- name: Checkout changes
uses: actions/checkout@v1
- name: Install Node
uses: actions/setup-node@v1
with:
node-version: 8
- name: Install Node dependencies
run: npm install
- name: Run tests
run: npm run test
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ sftp-config.json
.ftpconfig
selenium.php
composer.lock
package-lock.json
/node_modules
_ide_helper.php

# for netbeans
Expand Down
5 changes: 5 additions & 0 deletions .jshintrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"esversion": 6,
"curly": true,
"asi": true
}
2 changes: 1 addition & 1 deletion modules/system/assets/js/framework-min.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ var fieldElement=$form.find('[name="'+fieldName+'"], [name="'+fieldName+'[]"], [
if(fieldElement.length>0){var _event=jQuery.Event('ajaxInvalidField')
$(window).trigger(_event,[fieldElement.get(0),fieldName,fieldMessages,isFirstInvalidField])
if(isFirstInvalidField){if(!_event.isDefaultPrevented())fieldElement.focus()
isFirstInvalidField=false}}})},handleFlashMessage:function(message,type){},handleRedirectResponse:function(url){window.location.href=url},handleUpdateResponse:function(data,textStatus,jqXHR){var updatePromise=$.Deferred().done(function(){for(var partial in data){var selector=(options.update[partial])?options.update[partial]:partial
isFirstInvalidField=false}}})},handleFlashMessage:function(message,type){},handleRedirectResponse:function(url){window.location.assign(url)},handleUpdateResponse:function(data,textStatus,jqXHR){var updatePromise=$.Deferred().done(function(){for(var partial in data){var selector=(options.update[partial])?options.update[partial]:partial
if($.type(selector)=='string'&&selector.charAt(0)=='@'){$(selector.substring(1)).append(data[partial]).trigger('ajaxUpdate',[context,data,textStatus,jqXHR])}
else if($.type(selector)=='string'&&selector.charAt(0)=='^'){$(selector.substring(1)).prepend(data[partial]).trigger('ajaxUpdate',[context,data,textStatus,jqXHR])}
else{$(selector).trigger('ajaxBeforeReplace')
Expand Down
2 changes: 1 addition & 1 deletion modules/system/assets/js/framework.combined-min.js
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ var fieldElement=$form.find('[name="'+fieldName+'"], [name="'+fieldName+'[]"], [
if(fieldElement.length>0){var _event=jQuery.Event('ajaxInvalidField')
$(window).trigger(_event,[fieldElement.get(0),fieldName,fieldMessages,isFirstInvalidField])
if(isFirstInvalidField){if(!_event.isDefaultPrevented())fieldElement.focus()
isFirstInvalidField=false}}})},handleFlashMessage:function(message,type){},handleRedirectResponse:function(url){window.location.href=url},handleUpdateResponse:function(data,textStatus,jqXHR){var updatePromise=$.Deferred().done(function(){for(var partial in data){var selector=(options.update[partial])?options.update[partial]:partial
isFirstInvalidField=false}}})},handleFlashMessage:function(message,type){},handleRedirectResponse:function(url){window.location.assign(url)},handleUpdateResponse:function(data,textStatus,jqXHR){var updatePromise=$.Deferred().done(function(){for(var partial in data){var selector=(options.update[partial])?options.update[partial]:partial
if($.type(selector)=='string'&&selector.charAt(0)=='@'){$(selector.substring(1)).append(data[partial]).trigger('ajaxUpdate',[context,data,textStatus,jqXHR])}
else if($.type(selector)=='string'&&selector.charAt(0)=='^'){$(selector.substring(1)).prepend(data[partial]).trigger('ajaxUpdate',[context,data,textStatus,jqXHR])}
else{$(selector).trigger('ajaxBeforeReplace')
Expand Down
2 changes: 1 addition & 1 deletion modules/system/assets/js/framework.js
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ if (window.jQuery.request !== undefined) {
* Custom function, redirect the browser to another location
*/
handleRedirectResponse: function(url) {
window.location.href = url
window.location.assign(url)
},

/*
Expand Down
48 changes: 48 additions & 0 deletions package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
{
"name": "octobercms",
"description": "Free, open-source, self-hosted CMS platform based on the Laravel PHP Framework.",
"directories": {
"test": "tests/js/cases",
"helpers": "tests/js/helpers"
},
"scripts": {
"test": "mocha --require @babel/register tests/js/cases/**/*.js"
},
"repository": {
"type": "git",
"url": "git+https://github.com/octobercms/october.git"
},
"contributors": [
{
"name": "Alexey Bobkov",
"email": "aleksey.bobkov@gmail.com"
},
{
"name": "Samuel Georges",
"email": "daftspunky@gmail.com"
},
{
"name": "Luke Towers",
"email": "octobercms@luketowers.ca",
"url": "https://luketowers.ca"
}
],
"license": "MIT",
"bugs": {
"url": "https://github.com/octobercms/october/issues"
},
"homepage": "https://octobercms.com/",
"devDependencies": {
"@babel/cli": "^7.5.5",
"@babel/core": "^7.5.5",
"@babel/node": "^7.5.5",
"@babel/preset-env": "^7.5.5",
"@babel/register": "^7.5.5",
"babel-plugin-module-resolver": "^3.2.0",
"chai": "^4.2.0",
"jquery": "^3.4.1",
"jsdom": "^15.1.1",
"mocha": "^6.2.0",
"sinon": "^7.4.1"
}
}
Loading

0 comments on commit 5f15ed5

Please sign in to comment.