Skip to content

Commit

Permalink
feat: rolllup config improvements, adding tests, circle ci
Browse files Browse the repository at this point in the history
  • Loading branch information
Carlos Rodrigues committed Oct 23, 2019
1 parent 9cbf486 commit e5a190d
Show file tree
Hide file tree
Showing 31 changed files with 2,153 additions and 126 deletions.
13 changes: 6 additions & 7 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

version: 2
jobs:
build:
Expand All @@ -12,8 +11,8 @@ jobs:

- restore_cache:
keys:
- v1-dependencies-{{ checksum "yarn.lock" }}
- v1-dependencies-
- v1-dependencies-{{ checksum "yarn.lock" }}
- v1-dependencies-

- run:
name: Install Dependencies
Expand All @@ -32,10 +31,10 @@ jobs:
- run:
name: "Run Jest and Collect Coverage Reports"
command: yarn test --coverage --ci --runInBand

- store_artifacts:
path: coverage

- run:
- run:
name: "Publish coverage to coveralls"
command: yarn coveralls < coverage/lcov.info

- store_artifacts:
path: dist
11 changes: 1 addition & 10 deletions __tests__/arrayPagination.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { useArrayPagination } from "../src/vue-composable";
import { useArrayPagination } from "../src";
import { nextTick } from "./utils";
import { ref } from "@vue/composition-api";

Expand Down Expand Up @@ -43,13 +43,4 @@ describe("arrayPagination", () => {
arr.value = 1 as any;
expect(use.result.value).toHaveLength(0);
});

// TODO
it("should warn when you try to assign an string", async () => {

});

it('when changing the pageSize we should keep the current page results', ()=>{

})
});
74 changes: 73 additions & 1 deletion __tests__/pagination.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,11 @@ import { usePagination } from "../src/pagination";
import { nextTick } from "./utils";

describe("pagination", () => {
let warnSpy: jest.SpyInstance = undefined as any;
beforeAll(() => {
warnSpy = jest.spyOn(console, "warn").mockImplementation();
});

it("should return pagination", () => {
const use = usePagination({
pageSize: 10,
Expand Down Expand Up @@ -136,7 +141,7 @@ describe("pagination", () => {

expect(use.currentPage.value).toBe(1);
});

it("should `last`", async () => {
const use = usePagination({
pageSize: 10,
Expand Down Expand Up @@ -225,4 +230,71 @@ describe("pagination", () => {
expect(use.currentPage.value).toBe(2);
});
});


describe('validations', ()=>{
it("should warn when you try assign invalid value to pageSize", async () => {
const use = usePagination({
pageSize: 10,
currentPage: 1,
total: 100
});
const value = "11";

expect(use.currentPage.value).toBe(1);
expect(use.offset.value).toBe(0);

use.pageSize.value = value as any;

expect(warnSpy).toBeCalledWith(expect.stringContaining(`[pageSize] expected number but got: '${typeof value}' value: '${value}'`));
expect(use.pageSize.value).toBe(10);
});

it("should warn when you try assign invalid value to pageSize", async () => {
const use = usePagination({
pageSize: 10,
currentPage: 1,
total: 100
});
const value = "11";

expect(use.currentPage.value).toBe(1);
expect(use.offset.value).toBe(0);

use.currentPage.value = value as any;

expect(warnSpy).toBeCalledWith(expect.stringContaining(`[currentPage] expected number but got: '${typeof value}' value: '${value}'`));
expect(use.currentPage.value).toBe(1);
});

it("should warn when you try assign invalid value to offset", async () => {
const use = usePagination({
pageSize: 10,
currentPage: 2,
total: 100
});
const value = "11";

expect(use.currentPage.value).toBe(2);
expect(use.offset.value).toBe(10);

use.offset.value = value as any;

expect(warnSpy).toBeCalledWith(expect.stringContaining(`[offset] expected number but got: '${typeof value}' value: '${value}'`));
expect(use.offset.value).toBe(10);
});

})

it("when changing the pageSize offset shouldn't change", () => {
const use = usePagination({
pageSize: 10,
currentPage: 2,
total: 100
});

use.pageSize.value++;

expect(use.offset.value).toBe(10);
});
});
2 changes: 1 addition & 1 deletion dist/arrayPagination.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,4 @@ import { Ref } from "@vue/composition-api";
export interface ArrayPaginationResult<T extends Array<any>> extends PaginationResult {
result: Readonly<Ref<T>>;
}
export declare function useArrayPagination<T extends Array<TR>, TR>(array: RefTyped<T>, options: Omit<PaginationOptions, 'total'>): ArrayPaginationResult<T>;
export declare function useArrayPagination<T extends Array<TR>, TR>(array: RefTyped<T>, options?: Partial<Omit<PaginationOptions, 'total'>>): ArrayPaginationResult<T>;
4 changes: 2 additions & 2 deletions dist/event.d.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { Ref } from "@vue/composition-api";
import { RefTyped } from "./utils";
export declare type RemoveEventFunction = () => void;
export declare function useEvent<K extends keyof DocumentEventMap>(el: Element | Ref<Element>, name: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions): RemoveEventFunction;
export declare function useEvent<K extends keyof DocumentEventMap>(el: RefTyped<Element>, name: K, listener: (this: Document, ev: DocumentEventMap[K]) => any, options?: boolean | AddEventListenerOptions): RemoveEventFunction;
File renamed without changes.
9 changes: 4 additions & 5 deletions dist/onMouseMove.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Ref } from "@vue/composition-api";
import { RefElement } from "./utils";
import { RemoveEventFunction } from "./event";
declare type MouseMoveResult = {
export interface MouseMoveResult {
mouseX: Ref<number>;
mouseY: Ref<number>;
remove: RemoveEventFunction;
};
export declare function useMouseResize(el: RefElement, wait: number): MouseMoveResult;
export declare function useMouseResize(el: RefElement, options: boolean | AddEventListenerOptions, wait?: number): MouseMoveResult;
export {};
}
export declare function useMouseMove(el: RefElement, wait: number): MouseMoveResult;
export declare function useMouseMove(el: RefElement, options?: boolean | AddEventListenerOptions, wait?: number): MouseMoveResult;
7 changes: 3 additions & 4 deletions dist/onResize.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Ref } from "@vue/composition-api";
import { RefElement } from "./utils";
import { RemoveEventFunction } from "./event";
declare type ResizeResult = {
export interface ResizeResult {
height: Ref<number>;
width: Ref<number>;
remove: RemoveEventFunction;
};
}
export declare function useOnResize(el: RefElement, wait: number): ResizeResult;
export declare function useOnResize(el: RefElement, options: boolean | AddEventListenerOptions, wait?: number): ResizeResult;
export {};
export declare function useOnResize(el: RefElement, options?: boolean | AddEventListenerOptions, wait?: number): ResizeResult;
7 changes: 3 additions & 4 deletions dist/onScroll.d.ts
Original file line number Diff line number Diff line change
@@ -1,11 +1,10 @@
import { Ref } from "@vue/composition-api";
import { RefElement } from "./utils";
import { RemoveEventFunction } from "./event";
declare type ScrollResult = {
export interface ScrollResult {
scrollTop: Ref<number>;
scrollLeft: Ref<number>;
remove: RemoveEventFunction;
};
}
export declare function useOnScroll(el: RefElement, wait: number): ScrollResult;
export declare function useOnScroll(el: RefElement, options: boolean | AddEventListenerOptions, wait?: number): ScrollResult;
export {};
export declare function useOnScroll(el: RefElement, options?: boolean | AddEventListenerOptions, wait?: number): ScrollResult;
2 changes: 1 addition & 1 deletion dist/pagination.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export interface PaginationResult {
pageSize: Ref<number>;
total: Ref<number>;
currentPage: Ref<number>;
offset: Ref<number>;
lastPage: Readonly<Ref<number>>;
offset: Readonly<Ref<number>>;
next: PaginationControl;
prev: PaginationControl;
first: PaginationControl;
Expand Down

0 comments on commit e5a190d

Please sign in to comment.