Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added svelte example for xlsx-import #157

Merged
merged 3 commits into from
Apr 6, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 4 additions & 0 deletions samples/xlsx-import+svelte/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
/node_modules/
/public/build/

.DS_Store
5 changes: 5 additions & 0 deletions samples/xlsx-import+svelte/.prettierignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
lib
build
dist
coverage
node_modules
6 changes: 6 additions & 0 deletions samples/xlsx-import+svelte/.prettierrc
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
{
"printWidth": 120,
"trailingComma": "all",
"singleQuote": true,
"tabWidth": 4
}
3 changes: 3 additions & 0 deletions samples/xlsx-import+svelte/.vscode/extensions.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"recommendations": ["svelte.svelte-vscode"]
}
51 changes: 51 additions & 0 deletions samples/xlsx-import+svelte/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
# Svelte

This is an example how to use `xlsx-import` in Svelte.

**LIB Version:** `2.3.4`

## Scripts

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

`npm run build` - compiles and minifies for production

Siemienik marked this conversation as resolved.
Show resolved Hide resolved
`npm run test` - run cypress tests

`npm run validate` - perform some checks against codebase (types, unused css, etc.)

`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.svelte) component

## What is worth to see here

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

## 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/xlsx-import+svelte/cypress.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"baseUrl": "http://localhost:5000",
"screenshotOnRunFailure": false,
"video": false
}
72 changes: 72 additions & 0 deletions samples/xlsx-import+svelte/cypress/integration/app_page.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
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/xlsx-import+svelte/cypress/plugins/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
/// <reference types="cypress" />
Siemienik marked this conversation as resolved.
Show resolved Hide resolved
// ***********************************************************
// 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/xlsx-import+svelte/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/xlsx-import+svelte/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