Skip to content

Commit

Permalink
Added vue example
Browse files Browse the repository at this point in the history
  • Loading branch information
Metastasis committed Oct 31, 2020
1 parent 4e4dd11 commit 5ce8af8
Show file tree
Hide file tree
Showing 25 changed files with 14,688 additions and 0 deletions.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,7 @@ Sample integration with `xlsx-import` are placed in [./samples](./samples) direc
* [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.
* [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
23 changes: 23 additions & 0 deletions samples/vue/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
.DS_Store
node_modules
/dist


# local env files
.env.local
.env.*.local

# Log files
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*

# Editor directories and files
.idea
.vscode
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
52 changes: 52 additions & 0 deletions samples/vue/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
# Vue

This is an example how to use `xlsx-import` in Vue.
It is made with [Vue CLI](https://cli.vuejs.org/)

**LIB Version:** `2.3.3`

## Scripts

`npm run start` - compiles and hot-reloads for development

`npm run build` - compiles and minifies for production

`npm run lint` - lints and fixes files

`npm run test` - run cypress tests

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

## Usage

```bash
# install dependencies
npm install

# start dev server
npm run start
```

Open the browser. 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.vue) component

## What is worth to see here

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

## 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)
3 changes: 3 additions & 0 deletions samples/vue/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
module.exports = {
presets: ['@vue/cli-plugin-babel/preset'],
};
5 changes: 5 additions & 0 deletions samples/vue/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"baseUrl": "http://localhost:8080",
"screenshotOnRunFailure": false,
"video": false
}
70 changes: 70 additions & 0 deletions samples/vue/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/vue/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/vue/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/vue/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 5ce8af8

Please sign in to comment.