Exporting jasmine test results in json format from grunt - json

I am using Jasmine to execute the tests from the Grunt task. I want to output the results from the test cases in JSON. Below is the configuration for the jasmine. This configuration generates XML files under junit folder.
var conf = {
src: [
// '../../../Test.UnitTest.JS/UnitTests/' + name + '/**/*.js'
],
options: {
template: require('grunt-template-jasmine-requirejs'),
templateOptions: {
requireConfig: {
baseUrl: 'SinglePageApplications/' + name,
//waitSeconds: 30,
paths: mixIn({
'knockout-editables': '../../Assets/scripts/vendor/ko.editables-0.9.0',
'knockout-validation': '../../Assets/scripts/vendor/knockout.validation-1.0.2',
'bignumber': '../../Assets/scripts/vendor/bignumber-1.4.1',
'testutils': '../../../Test.UnitTest.JS/Utils',
'shared': '../../Legacy/Shared',
'testdata': '../../../Test.UnitTest.JS/UnitTests/' + name + '/testdata'
}, addConfigurationPaths(app))
}
},
helpers: [
'Assets/scripts/ato/helperscript.js'
],
specs: [
'../Test.UnitTest.JS/UnitTests/' + name + '/**/*.js'
],
junit: {
path: 'build/junit/' + name + '/'
},
timeout: 100000,
vendor: arr
}
,
//specs : 'src/test/js/unit-headless.html',
phantomjs: {
'ignore-ssl-errors': true
}
}
I want the results to be displayed in JSON format so I installed jasmine-json-test-reporter using npm and tried implemented it in my current config like this:
var conf = {
src: [
// '../../../Test.UnitTest.JS/UnitTests/' + name + '/**/*.js'
],
options: {
template: require('grunt-template-jasmine-requirejs'),
templateOptions: {
requireConfig: {
baseUrl: 'SinglePageApplications/' + name,
//waitSeconds: 30,
paths: mixIn({
'knockout-editables': '../../Assets/scripts/vendor/ko.editables-0.9.0',
'knockout-validation': '../../Assets/scripts/vendor/knockout.validation-1.0.2',
'bignumber': '../../Assets/scripts/vendor/bignumber-1.4.1',
'testutils': '../../../Test.UnitTest.JS/Utils',
'shared': '../../Legacy/Shared',
'testdata': '../../../Test.UnitTest.JS/UnitTests/' + name + '/testdata'
}, addConfigurationPaths(app))
}
},
helpers: [
'Assets/scripts/ato/helperscript.js'
//'Legacy/Shared/common/constants.js'
],
specs: [
//'../Test.UnitTest.JS/UnitTests/' + name + '/common/*.js',
//'../Test.UnitTest.JS/UnitTests/' + name + '/testdata',
'../Test.UnitTest.JS/UnitTests/' + name + '/**/*.js'
],
junit: {
path: 'build/junit/' + name + '/'
},
timeout: 100000,
vendor: arr
}
,
//specs : 'src/test/js/unit-headless.html',
phantomjs: {
'ignore-ssl-errors': true
},
onPrepare: function () {
var JSONReporter = require('jasmine-json-test-reporter');
var jasmine = require('jasmine');
return browser.getProcessedConfig().then(function (config) {
browser.params['browsername'] = config.capabilities.browserName.toUpperCase();
browser.params['version'] = config.capabilities.version || 'latest stable';
browser.params['platform'] = config.capabilities.os + '-' + config.capabilities.os_version;
jasmine.getEnv().addReporter(new JSONReporter({
file: 'results/' + browser.params.platform + '-' + browser.params.version + '.' + browser.params.browsername + '.json',
beautify: true,
indentationLevel: 2 // used if beautify === true
}));
});
}
}
This code is not generating any json file. I am not too sure use jasmine-json-test-reporter with current jasmine config.

I manage to get it working. The source files were not point to the right locations. Changing the following lines fixed it:
src: [
'SinglePageApplications/' + name + '/common/**/*.js',
'SinglePageApplications/' + name + '/viewmodels/**/*.js',
'SinglePageApplications/' + name + '/views/**/*.js',
'SinglePageApplications/' + name + '/main.js'
],

Related

Any search result returned due to a free-text search should show preview text under each row in the results tables

I am applying filter on columns in the datatable as well as on the attributes that are not in the datatable but are in present in the database of the object. The filters are working fine and I am getting the output wanted. However on the text search I want to preview the text found that is not part of the attributes in the datatable under the row (refer to the image below for better understanding of the scenario).
I have tried dynamically adding a row but it just reloads the page and shows me the same data i got from the ajax request.
var counter = 1;
$('#addRow').on('click', function () {
datatable.row.add([
counter + '.1',
counter + '.2',
counter + '.3',
counter + '.4',
counter + '.5'
]).draw();
counter++;
});
here's the code of Datatable that handles the ajax request and renders the data
let datatable = companytable.DataTable({
lengthMenu: [[10, 20, 30, -1], [10, 20, 30, "All"]],
ajax: {
url: '/api/company/get?' + "&statusFilter=" + statusFilter + "&nameFilter=" + nameFilter
+ "&isrOfficeSelected=" + isrOfficeSelected + "&industrySelected=" + industrySelected
+ "&companyTypeSelected=" + companyTypeSelected
+ "&usOfficeSelected=" + usOfficeSelected
+ "&usOfficeStateSelected=" + usOfficeStateSelected
+ "&targetMarketSelected=" + targetMarketSelected
+ "&financingStageSelected=" + financingStageSelected
+ "&officeSizeSelected=" + officeSizeSelected
+ "&tamidReferralSelected=" + tamidReferralSelected
+ "&ratingLow=" + ratingLow + "&ratingHigh=" + ratingHigh
+ "&paidInternFrom=" + paidInternFrom + "&paidInternTo=" + paidInternTo
+ "&unpaidInternFrom=" + unpaidInternFrom + "&unpaidInternTo=" + unpaidInternTo
+ "&activeInternFrom=" + activeInternFrom + "&activeInternTo=" + activeInternTo
,
type: "GET",
},
processing: true,
serverSide: true,
language: {
processing: "Loading...",
paginate: {
previous: "<",
next: ">",
first: "<<",
last: ">>"
},
lengthMenu: "_MENU_"
},
columns: [
{
data: "CompanyName",
name: "CompanyName",
render: function (data, type, row) {
if (row.CompanyName !== '') {
return $('<span />')
.append($('<a />')
.prop('href', '/Consulting/Admin/Company?id=' + row.ID).text(row.CompanyName)).html();
}
return "";
}
},
{
data: 'Department',
name: "Department",
render: function (data, type, row) {
return $("<span/>").text(row.Department).html();
}
},
{
data: 'ContactName',
name: "ContactName",
render: function (data, type, row) {
return $("<span/>").text(row.FirstName + " " + row.LastName).html();
}
},
{
data: 'Email',
name: "Email",
render: function (data, type, row) {
return $("<span/>").text(row.Email).html();
}
},
{
data: "CurrentRating",
name: "CurrentRating",
render: function (data, type, row) {
let rating = $('<span />');
rating.append($('<span class="hidden" />').text(row.CurrentRating));
for (var i = 0; i < 5; i++) {
rating.append($('<i ></i>').addClass(i < parseInt(row.CurrentRating) ? 'fa fa-star text-primary' : 'fa fa-star-o text-muted'))
}
return rating.html();
}
},
],
dom: '<"top">rt<"bottom"pl><"clear">',
pagingType: "full_numbers",
});
Image Reference of the desired output

How to bind a model json to a comboBox in controller?

I want to bind a model json with a comboBox inside the controller (not in a xml view).
I made a model Json called types.json and I passed to the controller, but, when I bind the values inside the created model to the combobox, didn't show nothing.
Can you please help me. I can't find the problem here.
That is parts of my code, below, who I think is important to this question.
my MODEL JSON - name: types.json
"types": [
{
"text": "Férias",
"key": "01"
},
{
"text": "something",
"key": "02"
},
]
my CONTROLLER - name: Page.controller.js
handleAppointmentCreate: function (oEvent) {
var oStartDate = oEvent.getParameter("startDate"),
oEndDate = oEvent.getParameter("endDate"),
oCalendarRow = oEvent.getParameter("calendarRow"),
oEmpId = oCalendarRow.getKey(),
_oYearStartDate = oStartDate.getFullYear(),
_oMonthStartDate = oStartDate.getMonth() + 1,
_oDateStartDate = oStartDate.getDate(),
_oYearEndDate = oEndDate.getFullYear(),
_oMonthEndDate = oEndDate.getMonth() + 1,
_oDateEndDate = oEndDate.getDate(),
_HourStart = oStartDate.getHours(),
_oMinStart = oStartDate.getMinutes(),
_oSecStart = oStartDate.getSeconds(),
_oHourEnd = oEndDate.getHours(),
_oMinEnd = oEndDate.getMinutes(),
_oSecEnd = oEndDate.getSeconds(),
sStartDate = _oYearStartDate + "-" + _oMonthStartDate + "-" + _oDateStartDate,
sEndDate = _oYearEndDate + "-" + _oMonthEndDate + "-" + _oDateEndDate,
sStartHour = _HourStart + ":" + _oMinStart + ":" + _oSecStart,
sEndHour = _oHourEnd + ":" + _oMinEnd + ":" + _oSecEnd,
sIdEmp = oEmpId;
var dataModel = this.getOwnerComponent().getModel("Model");
this.getView().setModel(dataModel, "DataModel");
if (!this.oConfirmDialog) {
this.oConfirmDialog = new Dialog({
type: DialogType.Message,
title: "Novo agendamento",
content: [
new HorizontalLayout({
content: [
new VerticalLayout({
width: "120px",
content: [
new Text({ text: "Id de funcionário: " }),
new Text({ text: "Data de inicio: " }),
new Text({ text: "Data de término: " }),
new Text({ text: "Hora de inicio: " }),
new Text({ text: "Hora de término: " })
]
}),
new VerticalLayout({
content: [
new Text({text: sIdEmp }),
new Text({ text: sStartDate }),
new Text({ text: sEndDate }),
new Text({ text: sStartHour }),
new Text({ text: sEndHour })
]
})
]
}),
new TextArea("confirmationTitle", {
width: "100%",
placeholder: "Adicione o titulo do agendamento"
//required:"true" - não pode ter
}),
new TextArea("confirmationDetails", {
width: "100%",
placeholder: "Adicione detalhes do agendamento"
//required:"true" - não pode ter
}),
new sap.m.ComboBox({
items: {
path: "DataModel>/types",
template: {
Type: "sap.ui.core.ListItem",
text: "{DataModel>Key}",
enabled: true
}
}
})
],
beginButton: new Button({
type: ButtonType.Emphasized,
text: "Submeter",
press: function () {
var sIdEmp1 = sIdEmp,
sStartDate1 = sStartDate,
sEndDate1 = sEndDate,
sStartHour1 = sStartHour,
sEndHour1 = sEndHour,
sTitle = Core.byId("confirmationTitle").getValue(),
sDetails = Core.byId("confirmationDetails").getValue();
this.addAppointment(sIdEmp1, sStartDate1, sEndDate1, sStartHour1, sEndHour1, sTitle, sDetails);
this.oConfirmDialog.close();
}.bind(this)
}),
endButton: new Button({
text: "Cancelar",
press: function () {
this.oConfirmDialog.close();
}.bind(this)
})
});
}
this.oConfirmDialog.open();
},
First of all, there's a typo. In your model you have the string "key", but when creating the ComboBox you used "Key", with an uppercase K. Be sure that you put the same on both places.
If this don't solves your problem, try using sap.ui.core.Item instead of sap.ui.core.ListItem, as it is the control that the aggregation items accepts:
new sap.m.ComboBox({
items: {
path: "DataModel>/types",
template: new sap.ui.core.Item({
key: "{DataModel>key}",
text: "{DataModel>text}"
})
},
enabled: true
})
Also, remember that ComboBox is ony recomended when you will have between 13 and 200 results. For less than 13 options to show use sap.m.Select instead.

My code is executed after the end of the gulp task

I built an asyncronous gulp task to convert some sass files into css files and i got some troubles with timeline code execution.
I need to execute this task inside a loop and the code is executed after the end of the gulp task
async build() {
var self = this;
var tasks = await this.themes.map(async(theme) => {
return gulp.src(this.templatesPath + '/' + this.pattern)
.pipe(header('#import \'' + this.themesPath + '/' + theme + '/' + this.themeFile + '\';'))
.pipe(sass.sync().on('error', gutil.log))
.pipe(rename(function (path: any) {
var file = path.basename + path.extname;
path.dirname += '/' + file;
gutil.log(self.folders[theme][file]);
}))
.pipe(gulp.dest(this.themesPath + '/' + theme))
gutil.log('loop');
});
gutil.log('end');
}
gutil.log output inside rename function is always outprinted after end of task
[18:08:34] Starting 'build'...
[18:08:34] end
[18:08:34] Finished 'build' after 33 ms
[18:08:34] [ { '$': { 'jcr:primaryType': 'jnt:file' },
'jcr:content': [ [Object] ] } ]
[18:08:34] [ { '$': { 'jcr:primaryType': 'jnt:file' },
'jcr:content': [ [Object] ] } ]
How can I handle the end of loop to be sure my objects are filled when i execute others tasks ?

Create a dynamic array for use in grunt concat

I need to concatenate a set files based on variables I have defined my package.json.
// package.json
...
"layouts": [
{
"page": "home",
"version": "a"
},
{
"page": "about",
"version": "a"
},
{
"page": "contact",
"version": "b"
}
]
...
In grunt I am then building these into a JSON array and pumping it into the src parameter in my grunt-concat-contrib task.
// gruntfile.js
...
var package = grunt.file.readJSON('package.json'),
targets = package.layouts,
paths = [];
for (var target = 0; target < targets.length; target++) {
paths.push("layouts/" + targets[target]['page'] + "/" + targets[target]['version'] + "/*.php");
};
var paths = JSON.stringify(paths);
grunt.log.write(paths); // Writing this to console for debugging
grunt.initConfig({
concat: {
build: {
src: paths,
dest: 'mysite/Code.php',
options: {
separator: '?>\n\n'
}
}
}
});
...
My issue is that the paths variable is not working inside of the initConfig when it is assigned to JSON.stringify(paths).
If I manually input the array like the following that I copied from where I logged the paths variable to the console, it works!
var paths = ["layouts/home/a/*.php","layouts/about/a/*.php","layouts/contact/b/*.php"];
What am I missing?
Derp. I fixed it, I didn't need to JSON.stringify() the array.
Final working gruntfile is below:
// gruntfile.js
...
var package = grunt.file.readJSON('package.json'),
targets = package.layouts,
paths = [];
for (var target = 0; target < targets.length; target++) {
paths.push("layouts/" + targets[target]['page'] + "/" + targets[target]['version'] + "/*.php");
};
grunt.initConfig({
concat: {
build: {
src: paths,
dest: 'mysite/Code.php',
options: {
separator: '?>\n\n'
}
}
}
});
...

Adding links to jQgrid and open in new window

I have this jqgrid definition and I'm trying to open the selected document in a new Window.
My final urls should like these:
http://localhost/XPagesSortableSearchResults.nsf/xPerson.xsp?documentId=9D93E80306A7AA88802572580072717A&action=openDocument
and also I need to generate this type of url:
http://localhost/XPagesSortableSearchResults.nsf/$$OpenDominoDocument.xsp?documentId=9D93E80306A7AA88802572580072717&action=openDocument
$().ready(function(){
jQuery("#list2").jqGrid({
url:'./xGrid7.xsp/peoplejson',
datatype: "json",
colNames:['InternetAddress','#','Name','OfficeCountry'],
colModel:[
{name:'InternetAddress',index:'InternetAddress', width:200},
{name:'#position',index:'#position', width:50,sorttype:'int'},
{name:'$17',index:'$17', width:200},
{name:'OfficeCountry',
width:200,
formatter:editLinkFmatter
// formatter:'showlink',
// formatoptions:{ baseLinkUrl:'xPerson.xsp',addParam: '&action=openDocument', idName:'documentId'}
}
],
jsonReader: {
repeatitems: false,
id: '#unid',
root: function (obj) {
if ($.isArray(obj)) {
return obj;
}
if ($.isArray(obj.items)) {
return obj.items;
}
return [];
},
page: function () { return 1; },
total: function () { return 1; },
records: function (obj) {
if ($.isArray(obj)) {
return obj.length;
}
if ($.isArray(obj.items)) {
return obj.items.length;
}
return 0;
}
},
caption: "JSON Example",
height: 500,
gridview: true,
loadonce: true,
ignoreCase: true,
rowNum: 50,
rowList: [50, 100, 500, 1000],
pager: '#pager2'
}).jqGrid('filterToolbar', {stringResult: true, defaultSearch: 'cn', searchOnEnter: false});
Note my Json object looks like this and I'm not using the documentId I need on my url as part of my ColModel; the value I need is #unid
[
{
"#entryid":"1-B933790B1DC265ED8025725800728CC5",
"#unid":"B933790B1DC265ED8025725800728CC5",
"#noteid":"1E76E",
"#position":"1",
"#read":true,
"#siblings":40000,
"#form":"Person",
"$17":"Aaron, Adam",
"InternetAddress":"consurgo#compleo.net",
"OfficeCountry":"Namibia"
},
{
"#entryid":"2-9D93E80306A7AA88802572580072717A",
"#unid":"9D93E80306A7AA88802572580072717A",
"#noteid":"19376",
"#position":"2",
"#read":true,
"#siblings":40000,
"#form":"Person",
"$17":"Aaron, Dave",
"InternetAddress":"gratia#incito.co.uk",
"OfficeCountry":"Brazil"
},
{
"#entryid":"3-FAFA753960DB587A80257258007287CF",
"#unid":"FAFA753960DB587A80257258007287CF",
"#noteid":"1D842",
"#position":"3",
"#read":true,
"#siblings":40000,
"#form":"Person",
"$17":"Aaron, Donnie",
"InternetAddress":"vociferor#nequities.net",
"OfficeCountry":"Algeria"
}
]
So far I make it work using:
{name:'OfficeCountry',
width:200,
formatter:'showlink',
formatoptions:{ baseLinkUrl:'xPerson.xsp',addParam: '&action=openDocument', idName:'documentId'}
}
but I need to open it in a new window
I also tried with formatter:editLinkFmatter
function editLinkFmatter(cellvalue, options, rowObject) {
return "<a href='./" + rowObject[2] + "' class='requestlink'>" + cellvalue + "</a>";
//return "<a href='./documentId=" + rowObject.#unid + "' >Click here</a>";
//return "<a href='./documentId=" + options.idName + "&action=OpenDocument'>" + cellvalue + "</a>";
}
and I can't use rowObject.#unid because the node name
It seems to me that you should just use target="_blank"attribute in the <a> (see here and here). The standard 'showlink' formatter supports target attribute.
As the alternative to the custom formatter you can use 'dynamicLink' formatter (see the answer). You can download the last version of jQuery.jqGrid.dynamicLink.js from here.
UPDATED: To assess the property with the name #unid you can use syntax rowObject["#unid"]. So the editLinkFmatter can be like
function editLinkFmatter(cellvalue, options, rowObject) {
return "<a href='?documentId=" + rowObject["#unid"] +
"&action=OpenDocument' class='requestlink'>" + cellvalue + "</a>";
}
or better like
function editLinkFmatter(cellvalue, options, rowObject) {
return "<a href='?" +
$.param({
documentId: rowObject["#unid"],
action: 'OpenDocument'
}) + "' class='requestlink'>" + cellvalue + "</a>";
}