Merge pull request #375 from acelaya-forks/feature/servers-import-error

Feature/servers import error
This commit is contained in:
Alejandro Celaya 2020-12-30 21:04:59 +01:00 committed by GitHub
commit e9cef8a029
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 23 additions and 12 deletions

View file

@ -9,7 +9,7 @@ on:
jobs: jobs:
lint: lint:
continue-on-error: true continue-on-error: true
runs-on: ubuntu-latest runs-on: ubuntu-20.04
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v2 uses: actions/checkout@v2
@ -21,7 +21,7 @@ jobs:
- run: npm run lint - run: npm run lint
unit-tests: unit-tests:
runs-on: ubuntu-latest runs-on: ubuntu-20.04
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v2 uses: actions/checkout@v2
@ -38,7 +38,7 @@ jobs:
mutation-tests: mutation-tests:
continue-on-error: true continue-on-error: true
runs-on: ubuntu-latest runs-on: ubuntu-20.04
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v2 uses: actions/checkout@v2
@ -52,7 +52,7 @@ jobs:
- run: npm run mutate -- --mutate=$(git diff origin/main --name-only | grep -E 'src\/(.*).(ts|tsx)$' | paste -sd ",") - run: npm run mutate -- --mutate=$(git diff origin/main --name-only | grep -E 'src\/(.*).(ts|tsx)$' | paste -sd ",")
build-docker-image: build-docker-image:
runs-on: ubuntu-latest runs-on: ubuntu-20.04
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v2 uses: actions/checkout@v2

View file

@ -9,7 +9,7 @@ on:
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-20.04
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v2 uses: actions/checkout@v2

View file

@ -7,7 +7,7 @@ on:
jobs: jobs:
build: build:
runs-on: ubuntu-latest runs-on: ubuntu-20.04
steps: steps:
- name: Checkout code - name: Checkout code
uses: actions/checkout@v2 uses: actions/checkout@v2

View file

@ -4,7 +4,7 @@ All notable changes to this project will be documented in this file.
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org). The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org).
## [Unreleased] ## [3.0.1] - 2020-12-30
### Added ### Added
* *Nothing* * *Nothing*
@ -22,6 +22,7 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
* [#366](https://github.com/shlinkio/shlink-web-client/issues/366) Fixed text in visits menu jumping to next line in some tablet resolutions. * [#366](https://github.com/shlinkio/shlink-web-client/issues/366) Fixed text in visits menu jumping to next line in some tablet resolutions.
* [#367](https://github.com/shlinkio/shlink-web-client/issues/367) Removed conflicting overflow in visits table for mobile devices. * [#367](https://github.com/shlinkio/shlink-web-client/issues/367) Removed conflicting overflow in visits table for mobile devices.
* [#365](https://github.com/shlinkio/shlink-web-client/issues/365) Fixed weird rendering of short URLs list in tablets. * [#365](https://github.com/shlinkio/shlink-web-client/issues/365) Fixed weird rendering of short URLs list in tablets.
* [#372](https://github.com/shlinkio/shlink-web-client/issues/372) Fixed importing servers in Android devices.
## [3.0.0] - 2020-12-22 ## [3.0.0] - 2020-12-22

View file

@ -6,7 +6,7 @@
"repository": "https://github.com/shlinkio/shlink-web-client", "repository": "https://github.com/shlinkio/shlink-web-client",
"license": "MIT", "license": "MIT",
"scripts": { "scripts": {
"lint": "npm run lint:js && npm run lint:css", "lint": "npm run lint:css && npm run lint:js",
"lint:js": "eslint --ext .js,.ts,.tsx src test scripts config", "lint:js": "eslint --ext .js,.ts,.tsx src test scripts config",
"lint:js:fix": "npm run lint:js -- --fix", "lint:js:fix": "npm run lint:js -- --fix",
"lint:css": "stylelint src/*.scss src/**/*.scss", "lint:css": "stylelint src/*.scss src/**/*.scss",

View file

@ -1,13 +1,19 @@
import { CsvJson } from 'csvjson'; import { CsvJson } from 'csvjson';
import { ServerData } from '../data'; import { ServerData } from '../data';
const CSV_MIME_TYPE = 'text/csv';
interface CsvFile extends File {
type: 'text/csv' | 'text/comma-separated-values' | 'application/csv';
}
const CSV_MIME_TYPES = [ 'text/csv', 'text/comma-separated-values', 'application/csv' ];
const isCsv = (file?: File | null): file is CsvFile => !!file && CSV_MIME_TYPES.includes(file.type);
export default class ServersImporter { export default class ServersImporter {
public constructor(private readonly csvjson: CsvJson, private readonly fileReaderFactory: () => FileReader) {} public constructor(private readonly csvjson: CsvJson, private readonly fileReaderFactory: () => FileReader) {}
public readonly importServersFromFile = async (file?: File | null): Promise<ServerData[]> => { public readonly importServersFromFile = async (file?: File | null): Promise<ServerData[]> => {
if (!file || file.type !== CSV_MIME_TYPE) { if (!isCsv(file)) {
throw new Error('No file provided or file is not a CSV'); throw new Error('No file provided or file is not a CSV');
} }

View file

@ -29,8 +29,12 @@ describe('ServersImporter', () => {
); );
}); });
it('reads file when a CSV is provided', async () => { it.each([
await importer.importServersFromFile(Mock.of<File>({ type: 'text/csv' })); [ 'text/csv' ],
[ 'text/comma-separated-values' ],
[ 'application/csv' ],
])('reads file when a CSV is provided', async (type) => {
await importer.importServersFromFile(Mock.of<File>({ type }));
expect(readAsText).toHaveBeenCalledTimes(1); expect(readAsText).toHaveBeenCalledTimes(1);
expect(toObject).toHaveBeenCalledTimes(1); expect(toObject).toHaveBeenCalledTimes(1);