@itexpert-dev/base-universal-table
Version:
base universal table for build tables
88 lines • 3.94 kB
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
var universalTableDataPreprocessors_1 = require("./universalTableDataPreprocessors");
describe('test case for data preprocessors for parse server request to UI data format', function () {
var viewFields = ['a', 'b', 'c'];
var reorderViewFields = ['c', 'a', 'b'];
describe('tests for baseHeaders preprocessor', function () {
var aVerboseName = 'aVerbName';
var bVerboseName = 'bVerbName';
var cVerboseName = 'cVerbName';
var metadataMock = {
'a': {
type: 'any',
verboseName: aVerboseName
},
'b': {
type: 'any2',
verboseName: bVerboseName
},
'c': {
type: 'any3',
verboseName: cVerboseName
}
};
it('easy test for baseHeaders preprocessor', function () {
var headerPreprocessorResult = universalTableDataPreprocessors_1.UniversalTableDataPreprocessors.parseHeaders(viewFields, metadataMock);
expect(headerPreprocessorResult).toEqual([{ label: aVerboseName }, { label: bVerboseName }, { label: cVerboseName }]);
});
it('test for reorder fields', function () {
var result = universalTableDataPreprocessors_1.UniversalTableDataPreprocessors.parseHeaders(reorderViewFields, metadataMock);
expect(result).toEqual([{ label: cVerboseName }, { label: aVerboseName }, { label: bVerboseName }]);
});
it('test for throw error if no field in metadata', function () {
var metadata = {
'c': {
type: 'any4',
verboseName: 'lol'
}
};
expect(function () {
universalTableDataPreprocessors_1.UniversalTableDataPreprocessors.parseHeaders(['a', 'b'], {});
}).toThrowError("fields: [a, b] not found in metadata\ncurrent metadata: " + metadata);
});
});
describe('tests for data preprocessor', function () {
var firstCellAVal = 'first baseCell A value';
var cellAType = 'any baseCell type #1';
var testResponse = {
data: [{
'a': {
value: firstCellAVal
}
}],
metadata: {
'a': {
type: cellAType,
verboseName: 'baseCell a verbose name'
}
},
totalResult: 1
};
var expectedResult = [{
cells: [{
value: firstCellAVal,
type: cellAType
}]
}];
it('easy test', function () {
var result = universalTableDataPreprocessors_1.UniversalTableDataPreprocessors.parseData(['a'], testResponse);
expect(result).toEqual(expectedResult);
});
it('test if field missing in any row', function () {
//TODO: add test
});
it('test if field missing in metadata', function () {
//TODO: add test
});
it('test if field missing', function () {
//TODO: add test, uncomment text under
// let extendTestResponse = Object.assign({}, testResponse);
// extendTestResponse.data.push(extendTestResponse.data[1]);
// expect(()=>{
// UniversalTableDataPreprocessors.parseData(['a', 'b'], testResponse)
// }).toThrowError(`fields: [b] not found in metadata\ncurrent metadata: ${testResponse.metadata}\nfields: [b] not found in data row: 1\nfields: [b] not found in data row: 2`)
});
});
});
//# sourceMappingURL=universalTableDataPreprocessors.spec.js.map