-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #33 from marco-genova-ntt/environment-pages-config…
…uration Added environment pages.json configuration #32
- Loading branch information
Showing
12 changed files
with
245 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
import R from 'ramda'; | ||
import PagesProvider from './../app/PagesProvider'; | ||
|
||
test('check default constructor', () => { | ||
let pp = new PagesProvider(); | ||
expect(pp).not.toBeUndefined(); | ||
expect(pp.pages).toEqual({}); | ||
expect(pp._baseFile).toEqual('pages.json'); | ||
}); | ||
|
||
test('check a complete load process', () => { | ||
let pp = new PagesProvider({baseFile : "./tmp/test_pages.json"}); | ||
expect(pp).not.toBeUndefined(); | ||
expect(pp._baseFile).toEqual('./tmp/test_pages.json'); | ||
expect(pp.pages).toEqual({}); | ||
|
||
pp.loadPages(); | ||
expect(pp.pages).not.toBeUndefined(); | ||
|
||
pp.worksOnPages('test2', (pages) => { | ||
expect(R.length(pages)).toBe(2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import R from 'ramda'; | ||
import * as utility from './utility'; | ||
import path from 'path'; | ||
|
||
/** | ||
* This class is used to provide a set of pages extracted from filesystem. | ||
* The set of pages is cut by environment | ||
*/ | ||
class PagesProvider { | ||
|
||
constructor(configuration = {}) { | ||
this._baseFile = configuration.baseFile ? configuration.baseFile : 'pages.json'; | ||
this._absoluteFile = path.join(process.cwd(), this._baseFile); | ||
} | ||
|
||
/** | ||
* Loads page as state of object from filesystem | ||
*/ | ||
loadPages () { | ||
this._pages = utility.getJSONFromFile(this._absoluteFile); | ||
} | ||
|
||
/** | ||
* Works a set of page for the context | ||
* | ||
* @param {String} context identifier of the ernviroment ot use | ||
* @param {Function} worker function to work pages | ||
*/ | ||
worksOnPages(context = 'default', worker) { | ||
if (!R.isEmpty(this._pages) && worker) { | ||
const pagesSet = utility.getClonedProp(context, this._pages); | ||
if (R.length(pagesSet) > 0) { | ||
R.call(worker, R.clone(pagesSet)); | ||
} | ||
} | ||
} | ||
|
||
/** | ||
* Gets the whole set of pages | ||
*/ | ||
get pages() { | ||
return {...this._pages}; | ||
} | ||
} | ||
|
||
export default PagesProvider; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
"use strict"; | ||
|
||
var _ramda = _interopRequireDefault(require("ramda")); | ||
|
||
var _PagesProvider = _interopRequireDefault(require("./../app/PagesProvider")); | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
test('check default constructor', () => { | ||
let pp = new _PagesProvider.default(); | ||
expect(pp).not.toBeUndefined(); | ||
expect(pp.pages).toEqual({}); | ||
expect(pp._baseFile).toEqual('pages.json'); | ||
}); | ||
test('check a complete load process', () => { | ||
let pp = new _PagesProvider.default({ | ||
baseFile: "./tmp/test_pages.json" | ||
}); | ||
expect(pp).not.toBeUndefined(); | ||
expect(pp._baseFile).toEqual('./tmp/test_pages.json'); | ||
expect(pp.pages).toEqual({}); | ||
pp.loadPages(); | ||
expect(pp.pages).not.toBeUndefined(); | ||
pp.worksOnPages('test2', pages => { | ||
expect(_ramda.default.length(pages)).toBe(2); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
"use strict"; | ||
|
||
Object.defineProperty(exports, "__esModule", { | ||
value: true | ||
}); | ||
exports.default = void 0; | ||
|
||
var _ramda = _interopRequireDefault(require("ramda")); | ||
|
||
var utility = _interopRequireWildcard(require("./utility")); | ||
|
||
var _path = _interopRequireDefault(require("path")); | ||
|
||
function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } } | ||
|
||
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } | ||
|
||
/** | ||
* This class is used to provide a set of pages extracted from filesystem. | ||
* The set of pages is cut by environment | ||
*/ | ||
class PagesProvider { | ||
constructor(configuration = {}) { | ||
this._baseFile = configuration.baseFile ? configuration.baseFile : 'pages.json'; | ||
this._absoluteFile = _path.default.join(process.cwd(), this._baseFile); | ||
} | ||
/** | ||
* Loads page as state of object from filesystem | ||
*/ | ||
|
||
|
||
loadPages() { | ||
this._pages = utility.getJSONFromFile(this._absoluteFile); | ||
} | ||
/** | ||
* Works a set of page for the context | ||
* | ||
* @param {String} context identifier of the ernviroment ot use | ||
* @param {Function} worker function to work pages | ||
*/ | ||
|
||
|
||
worksOnPages(context = 'default', worker) { | ||
if (!_ramda.default.isEmpty(this._pages) && worker) { | ||
const pagesSet = utility.getClonedProp(context, this._pages); | ||
|
||
if (_ramda.default.length(pagesSet) > 0) { | ||
_ramda.default.call(worker, _ramda.default.clone(pagesSet)); | ||
} | ||
} | ||
} | ||
/** | ||
* Gets the whole set of pages | ||
*/ | ||
|
||
|
||
get pages() { | ||
return { ...this._pages | ||
}; | ||
} | ||
|
||
} | ||
|
||
var _default = PagesProvider; | ||
exports.default = _default; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters