-
Notifications
You must be signed in to change notification settings - Fork 90
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:dixieio/zipcelx
* 'master' of github.com:dixieio/zipcelx: (25 commits) Runned new build Removed unused constant Fixed linting errors Added Contributing file Updated tests to use a baseConfig object, to run tests from Changed test copy Changed the validation check to just throw one validation error, added test to ensure error gets called in validation fails for the tool Updated validator just to throw console.errors and added tests Renamed file, and Updated tests to not run assert Added test for formatRow Removed reuse of xml string, added expected xml strings to formatCell test and added Cell type of number test Updated test date, made test to ensure it generates string cell type Added test for formatCell type catch and fallback, and moved warning to constants Added test for cell of type String formatter Added test for cell of type Number formatter added test for the generator cell number Moved error messages to constants Added test & validator to ensure sheet data is an array Added test to ensure data contians array, updated tests to use baseConfig Updated child validator ...
- Loading branch information
Showing
17 changed files
with
283 additions
and
53 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
We 💜 contributions | ||
------------------- | ||
|
||
While we love contributions, we also need to ensure that our library is of great quality. Thus we require you to follow some simple guidelines when you're submitting your contributions. | ||
|
||
## Reporting Issues and Asking Questions | ||
|
||
Before opening an issue, please search the [issue tracker](https://github.com/dixieio/redux-json-api/issues) to make sure your issue hasn’t already been reported. | ||
|
||
## Development | ||
|
||
Visit the [issue tracker](https://github.com/dixieio/redux-json-api/issues) to find a list of open issues that need attention. | ||
|
||
Fork, then clone the repo: | ||
|
||
``` | ||
git clone https://github.com/your-username/redux-json-api.git | ||
``` | ||
|
||
### Testing | ||
|
||
To run tests: | ||
|
||
``` | ||
npm run test // Will run tests once | ||
``` | ||
|
||
To continuously watch and run tests, run the following: | ||
|
||
``` | ||
npm run test:watch | ||
``` | ||
|
||
### Linting | ||
|
||
To Lint | ||
``` | ||
npm run lint | ||
``` | ||
|
||
### Building | ||
|
||
To build run: | ||
|
||
``` | ||
npm run build | ||
``` | ||
|
||
### Quality insurance | ||
The `build` command should handle it but always run the `lint` command to ensure we are all developing with the same code standards. | ||
|
||
### Submitting a Pull Request | ||
|
||
For non-trivial changes, please open an issue with a proposal for a new feature or refactoring before starting on the work. We don’t want you to waste your efforts on a pull request that we won’t want to accept. | ||
|
||
On the other hand, sometimes the best way to start a conversation *is* to send a pull request. Use your best judgement! | ||
|
||
1. Open a new issue in the [Issue tracker](https://github.com/dixieio/redux-json-api/issues) | ||
1. Fork the repo | ||
1. Create a new feature branch based off the `master` branch | ||
1. Create breaking test(s) before implementing any fixes or functionality | ||
1. Make your changes | ||
1. Submit a pull request, referencing any issue that it resolves | ||
|
||
Thank you, we 💜 your contributions! |
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,18 @@ | ||
/** | ||
Basic working config | ||
*/ | ||
|
||
export default { | ||
filename: 'report', | ||
sheet: { | ||
data: [ | ||
[{ | ||
value: 'Test', | ||
type: 'string' | ||
}, { | ||
value: 1000, | ||
type: 'number' | ||
}] | ||
] | ||
} | ||
}; |
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,7 @@ | ||
import generatorCellNumber from '../../src/commons/generatorCellNumber'; | ||
|
||
describe('Cell number generator', () => { | ||
it('should create cell number A1', () => { | ||
expect(generatorCellNumber(0, 1)).toBe('A1'); | ||
}); | ||
}); |
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,31 @@ | ||
import { WARNING_INVALID_TYPE } from '../../../src/commons/constants'; | ||
import formatCell from '../../../src/formatters/cells/formatCell'; | ||
import baseConfig from '../../baseConfig'; | ||
|
||
const cells = baseConfig.sheet.data[0]; | ||
|
||
console.warn = jest.genMockFn(); | ||
|
||
describe('Format Cell', () => { | ||
describe('Create a cell of type sting', () => { | ||
const expectedXML = '<c r="A1" t="inlineStr"><is><t>Test</t></is></c>'; | ||
|
||
it('Should fallback to string if invalid type was supplied', () => { | ||
const cell = Object.assign({}, cells[0], { type: 'date' }); | ||
formatCell(cell); | ||
expect(console.warn).toBeCalledWith(WARNING_INVALID_TYPE); | ||
expect(formatCell(cell, 0, 1)).toBe(expectedXML); | ||
}); | ||
|
||
it('Create cell', () => { | ||
expect(formatCell(cells[0], 0, 1)).toBe(expectedXML); | ||
}); | ||
}); | ||
|
||
describe('Create a cell of type number', () => { | ||
const expectedXML = '<c r="B1"><v>1000</v></c>'; | ||
it('Create cell', () => { | ||
expect(formatCell(cells[1], 1, 1)).toBe(expectedXML); | ||
}); | ||
}); | ||
}); |
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,9 @@ | ||
import generatorNumberCell from '../../../src/formatters/cells/generatorNumberCell'; | ||
|
||
export const expectedXML = '<c r="A1"><v>1000</v></c>'; | ||
|
||
describe('Cell of type Number', () => { | ||
it('Should create a new xml markup cell', () => { | ||
expect(generatorNumberCell(0, 1000, 1)).toBe(expectedXML); | ||
}); | ||
}); |
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,9 @@ | ||
import generatorStringCell from '../../../src/formatters/cells/generatorStringCell'; | ||
|
||
const expectedXML = '<c r="A1" t="inlineStr"><is><t>Test</t></is></c>'; | ||
|
||
describe('Cell of type String', () => { | ||
it('Should create a new xml markup cell', () => { | ||
expect(generatorStringCell(0, 'Test', 1)).toBe(expectedXML); | ||
}); | ||
}); |
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,10 @@ | ||
import formatRow from '../../../src/formatters/rows/formatRow'; | ||
import baseConfig from '../../baseConfig'; | ||
|
||
const expectedXML = '<row r="1"><c r="A1" t="inlineStr"><is><t>Test</t></is></c><c r="B1"><v>1000</v></c></row>'; | ||
|
||
describe('Format Row', () => { | ||
it('Should create one row from given data', () => { | ||
expect(formatRow(baseConfig.sheet.data[0], 0)).toBe(expectedXML); | ||
}); | ||
}); |
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 |
---|---|---|
@@ -1,20 +1,59 @@ | ||
import validator from '../src/validator'; | ||
import { | ||
MISSING_KEY_FILENAME, | ||
INVALID_TYPE_FILENAME, | ||
INVALID_TYPE_SHEET, | ||
INVALID_TYPE_SHEET_DATA | ||
} from '../src/commons/constants'; | ||
import baseConfig from './baseConfig'; | ||
|
||
const data = [ | ||
[{ | ||
value: 'Monkey', | ||
type: 'string' | ||
}, { | ||
value: 1000, | ||
type: 'number' | ||
}] | ||
]; | ||
|
||
describe('Data validator', () => { | ||
it('Should ensure that Data passed is an Array', () => { | ||
expect(validator(data)).toBe(true); | ||
const configDescription = expect.objectContaining({ | ||
filename: expect.any(String), | ||
sheet: expect.objectContaining({ | ||
data: expect.arrayContaining(baseConfig.sheet.data) | ||
}) | ||
}); | ||
const errorObjectDescription = expect.objectContaining({ | ||
error: expect.any(String), | ||
}); | ||
|
||
console.error = jest.genMockFn(); | ||
|
||
describe('Validator', () => { | ||
it('Should ensure that being called with correct config', () => { | ||
expect(baseConfig).toEqual(configDescription); | ||
}); | ||
it('Should ensure that argument Data\'s childs is arrays', () => { | ||
expect(validator(data)).toBe(true); | ||
|
||
it('If validation is successfull return true', () => { | ||
expect(validator(baseConfig)).toBe(true); | ||
}); | ||
|
||
it('If validation fails it should call console.error', () => { | ||
let config = Object.assign({}, baseConfig, {filename: 1234}); | ||
validator(config) | ||
expect(console.error).toBeCalled(); | ||
}); | ||
|
||
describe('Filename Validator', () => { | ||
it('Should be a property of the config', () => { | ||
let config = Object.assign({}, config); | ||
delete config.filename; | ||
expect(validator(config)).toBe(false); | ||
expect(console.error).toBeCalledWith(MISSING_KEY_FILENAME); | ||
}); | ||
}); | ||
|
||
describe('Sheet data', () => { | ||
it('Should ensure that sheet data key is an array', () => { | ||
let config = Object.assign({}, baseConfig, { sheet: { data: { test: 'test'} } }); | ||
expect(validator(config)).toBe(false); | ||
expect(console.error).toBeCalledWith(INVALID_TYPE_SHEET); | ||
}); | ||
|
||
it('Should ensure each of the childs is an array', () => { | ||
let config = Object.assign({}, baseConfig, { sheet: { data: [{test: 'demo'}] } }); | ||
expect(validator(config)).toBe(false); | ||
expect(console.error).toBeCalledWith(INVALID_TYPE_SHEET_DATA); | ||
}); | ||
}) | ||
}); |
32 changes: 15 additions & 17 deletions
32
__test__/xmlFormatters.spec.js → __test__/zipcelx.spec.js
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 |
---|---|---|
@@ -1,29 +1,27 @@ | ||
import assert from 'assert'; | ||
import generatorRows from '../src/formatters/rows/generatorRows'; | ||
import { generateXMLWorksheet } from '../src/zipcelx'; | ||
import zipcelx, { generateXMLWorksheet } from '../src/zipcelx'; | ||
import baseConfig from './baseConfig'; | ||
|
||
const data = [ | ||
[{ | ||
value: 'Monkey', | ||
type: 'string' | ||
}, { | ||
value: 1000, | ||
type: 'number' | ||
}] | ||
]; | ||
console.error = jest.genMockFn(); | ||
|
||
describe('XML Formatter', () => { | ||
const rowsXML = `<row r="1"><c r="A1" t="inlineStr"><is><t>Monkey</t></is></c><c r="B1"><v>1000</v></c></row>`; | ||
describe('Zipcelx', () => { | ||
const rowsXML = `<row r="1"><c r="A1" t="inlineStr"><is><t>Test</t></is></c><c r="B1"><v>1000</v></c></row>`; | ||
|
||
it('Should console log error if validator fails', () => { | ||
let config = Object.assign({}, baseConfig, { sheet: { data: [{test: 'demo'}] } }); | ||
zipcelx(config); | ||
expect(console.error).toBeCalled(); | ||
}); | ||
|
||
it('Should map row arrays to XML markup', () => { | ||
assert.strictEqual(generatorRows(data), rowsXML); | ||
}) | ||
expect(generatorRows(baseConfig.sheet.data)).toBe(rowsXML); | ||
}); | ||
|
||
it('Should generate and XML Worksheet from template', () => { | ||
const expectedXML = [ | ||
'<?xml version="1.0" ?>', | ||
`<worksheet xmlns="http://schemas.openxmlformats.org/spreadsheetml/2006/main" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:mv="urn:schemas-microsoft-com:mac:vml" xmlns:mx="http://schemas.microsoft.com/office/mac/excel/2008/main" xmlns:r="http://schemas.openxmlformats.org/officeDocument/2006/relationships" xmlns:x14="http://schemas.microsoft.com/office/spreadsheetml/2009/9/main" xmlns:x14ac="http://schemas.microsoft.com/office/spreadsheetml/2009/9/ac" xmlns:xm="http://schemas.microsoft.com/office/excel/2006/main"><sheetData>${rowsXML}</sheetData></worksheet>` | ||
].join('\n'); | ||
assert.strictEqual(generateXMLWorksheet(data), expectedXML); | ||
}) | ||
expect(generateXMLWorksheet(baseConfig.sheet.data)).toBe(expectedXML); | ||
}); | ||
}); |
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
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 |
---|---|---|
@@ -1,3 +1,10 @@ | ||
export const CELL_TYPE_STRING = 'string'; | ||
export const CELL_TYPE_NUMBER = 'number'; | ||
export const validTypes = [CELL_TYPE_STRING, CELL_TYPE_NUMBER]; | ||
|
||
export const MISSING_KEY_FILENAME = 'Zipclex config missing property filename'; | ||
export const INVALID_TYPE_FILENAME = 'Zipclex filename can only be of type string'; | ||
export const INVALID_TYPE_SHEET = 'Zipcelx sheet data is not of type array'; | ||
export const INVALID_TYPE_SHEET_DATA = 'Zipclex sheet data childs is not of type array'; | ||
|
||
export const WARNING_INVALID_TYPE = 'Invalid type supplied in cell config, falling back to "string"'; |
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
Oops, something went wrong.