Skip to content

Commit

Permalink
Merge branch 'master' into feature/6-vue
Browse files Browse the repository at this point in the history
  • Loading branch information
Siemienik authored Nov 1, 2020
2 parents 5ce8af8 + dcf0ee4 commit 997508e
Show file tree
Hide file tree
Showing 34 changed files with 16,720 additions and 5 deletions.
22 changes: 17 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -108,10 +108,19 @@ interface Person {

Sample integration with `xlsx-import` are placed in [./samples](./samples) directory. Currently available:

### Frontend frameworks

* [Vue sample](samples/vue/) - it is a web app created with Vue that displays parsed xlsx file
* [React sample](samples/react/) - it is a web app created with React that displays parsed xlsx file

### Console / CLI

* [NodeJS sample](./samples/nodejs/) of **importing an invoice** - it is pure JS example which runs on nodejs.
* [NodeJS + TS sample](./samples/nodejs-ts/) of **importing an invoice** - it is Typescript example that can be transpiled down to pure JS or run directly with ts-node.

### Backend

* [ExpressJS sample](./samples/express/) - it is a small service created with ExpressJS can parse xlsx files with concrete structure
* [Vue sample](samples/vue/) - it is a web app created with Vue that displays parsed xlsx file

## The configuration

Expand Down Expand Up @@ -180,17 +189,20 @@ const result = wordsInSentencesMapper(input);

```

## Supported Node version
## Supports

### Supported browsers

Browser supporting has been proved for ✅ _Chrome_ and ✅ _Firefox_ in [Vue & React Samples](#frontend-frameworks) and theirs tests.

### Supported Node version

8 | 9 | 10 | 11 | 12 | 13 | 14
--|---|----|----|----|----|---
❌ | ❌ | ✅ | ✅ | ✅ | ✅ | ✅

Node v8 and v9 compatibly was drop after upgrade `ExcelJS` to version 4+ and it is able to turn on by downgrading `xlsx-import` to version 2.2.1 or if needed really important by requesting me directly.

## Supported browsers

Chrome, Firefox. [_proved here_](https://github.com/Siemienik/xlsx-import/pull/57)

## See also

Expand Down
23 changes: 23 additions & 0 deletions samples/react/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# See https://help.github.com/articles/ignoring-files/ for more about ignoring files.

# dependencies
/node_modules
/.pnp
.pnp.js

# testing
/coverage

# production
/build

# misc
.DS_Store
.env.local
.env.development.local
.env.test.local
.env.production.local

npm-debug.log*
yarn-debug.log*
yarn-error.log*
56 changes: 56 additions & 0 deletions samples/react/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
# React

This is an example how to use `xlsx-import` in React.
It is made with [CRA](https://github.com/facebook/create-react-app)

**LIB Version:** `2.3.3`

## Scripts

`npm start` - start dev server

`npm run build` - build static artifacts

`npm run test` - run all tests

`npm run test:cra` - run jest only tests

`npm run test:cy` - run cypress only tests

`npm run cy:open` - open cypress dashboard (server must be started before this command)

`npm run eject` - eject CRA

## Usage

```bash
# install dependencies
npm install

# start dev server
npm start
```

Browser will be opened automatically. Then click on "Download and parse invoice" button.
You will see invoice file imported with xlsx-import library.

## What happened

1. [Invoice.xlsx](public/invoice.xlsx) fetched as Blob file
2. Blob file transformed into ArrayBuffer and passed to [exceljs](https://www.npmjs.com/package/exceljs) in order to obtain Workbook class
3. Workbook class then passed to Importer class of xlsx-import for mapping.
This is [workaround](https://github.com/Siemienik/xlsx-import/issues/4)
and will be fixed in [#52](https://github.com/Siemienik/xlsx-import/issues/52)
4. After mapping invoice data rendered with [Invoice](src/components/Invoice/Invoice.jsx) component

## What is worth to see here

1. Study config: [`invoiceConfig.js`](src/components/Invoice/invoiceConfig.js)
2. Usage package in [`App.js (importInvoice function)`](src/App.js)

## What later

1. Study documentation: [docs](./../../README.md)
2. Start using `xlsx-import` in your project
3. Ask a lot, report bugs and request for help: <https://github.com/Siemienik/xlsx-import/issues>
4. [Sponsor `xlsx-import` project](https://github.com/sponsors/Siemienik)
5 changes: 5 additions & 0 deletions samples/react/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"baseUrl": "http://localhost:3000",
"screenshotOnRunFailure": false,
"video": false
}
5 changes: 5 additions & 0 deletions samples/react/cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
70 changes: 70 additions & 0 deletions samples/react/cypress/integration/app_page_spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
const invoice = {
buyer: {
name: 'Bigos INC.',
taxIdNumber: '987654321',
address: 'ul. Agiede 2020, MiastoNaK',
},
date: '2020-10-08T00:00:00.000Z',
dueDate: '2020-10-29T00:00:00.000Z',
items: [
{
item: 'Mleczko do prania',
unitPrice: 16.45,
quantity: 2,
price: 32.9,
},
{
item: 'Płyn do płukania',
unitPrice: 14.55,
quantity: 1,
price: 14.55,
},
{
item: 'Pokarm dla smoka',
unitPrice: 79.99,
quantity: 10,
price: 799.9,
},
{
item: 'Instrukcja jak latać na smoku',
unitPrice: 19.89,
quantity: 1,
price: 19.89,
},
],
seller: {
name: 'Krupnik LTD.',
taxIdNumber: '123456789',
address: 'ul. Usbewifi 5/G, MiastoNaK',
accountNo: 'PL 12 1234 1234 1234 1234 1234 1234',
},
total: 867.24,
};

describe('The App', () => {
it('successfully loads', () => {
cy.visit('/');
});

it('renders parsed invoice file', () => {
cy.visit('/');
cy.get('button').click().should('be.disabled');
cy.get('[data-qa-name="buyer-name"]').contains(invoice.buyer.name);
cy.get('[data-qa-name="buyer-tax-id"]').contains(invoice.buyer.taxIdNumber);
cy.get('[data-qa-name="buyer-address"]').contains(invoice.buyer.address);
invoice.items.forEach((inv, idx) => {
const parent = cy.get(`[data-qa-name="invoice-${idx}"]`);
parent.get('[data-qa-name="invoice-item"]').contains(inv.item);
parent.get('[data-qa-name="invoice-price"]').contains(inv.price);
parent.get('[data-qa-name="invoice-quantity"]').contains(inv.quantity);
parent.get('[data-qa-name="invoice-unit-price"]').contains(inv.unitPrice);
});
cy.get('[data-qa-name="seller-name"]').contains(invoice.seller.name);
cy.get('[data-qa-name="seller-tax-id"]').contains(invoice.seller.taxIdNumber);
cy.get('[data-qa-name="seller-address"]').contains(invoice.seller.address);
cy.get('[data-qa-name="seller-account"]').contains(invoice.seller.accountNo);
cy.get('[data-qa-name="date"]').contains(invoice.date);
cy.get('[data-qa-name="due-date"]').contains(invoice.dueDate);
cy.get('[data-qa-name="total"]').contains(invoice.total);
});
});
21 changes: 21 additions & 0 deletions samples/react/cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/// <reference types="cypress" />
// ***********************************************************
// This example plugins/index.js can be used to load plugins
//
// You can change the location of this file or turn off loading
// the plugins file with the 'pluginsFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/plugins-guide
// ***********************************************************

// This function is called when a project is opened or re-opened (e.g. due to
// the project's config changing)

/**
* @type {Cypress.PluginConfig}
*/
module.exports = (on, config) => {
// `on` is used to hook into various events Cypress emits
// `config` is the resolved Cypress config
}
25 changes: 25 additions & 0 deletions samples/react/cypress/support/commands.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// ***********************************************
// This example commands.js shows you how to
// create various custom commands and overwrite
// existing commands.
//
// For more comprehensive examples of custom
// commands please read more here:
// https://on.cypress.io/custom-commands
// ***********************************************
//
//
// -- This is a parent command --
// Cypress.Commands.add("login", (email, password) => { ... })
//
//
// -- This is a child command --
// Cypress.Commands.add("drag", { prevSubject: 'element'}, (subject, options) => { ... })
//
//
// -- This is a dual command --
// Cypress.Commands.add("dismiss", { prevSubject: 'optional'}, (subject, options) => { ... })
//
//
// -- This will overwrite an existing command --
// Cypress.Commands.overwrite("visit", (originalFn, url, options) => { ... })
20 changes: 20 additions & 0 deletions samples/react/cypress/support/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// ***********************************************************
// This example support/index.js is processed and
// loaded automatically before your test files.
//
// This is a great place to put global configuration and
// behavior that modifies Cypress.
//
// You can change the location of this file or turn off
// automatically serving support files with the
// 'supportFile' configuration option.
//
// You can read more here:
// https://on.cypress.io/configuration
// ***********************************************************

// Import commands.js using ES2015 syntax:
import './commands'

// Alternatively you can use CommonJS syntax:
// require('./commands')
Loading

0 comments on commit 997508e

Please sign in to comment.