mirror of
https://github.com/scm-manager/scm-manager.git
synced 2025-11-09 15:05:44 +01:00
migrate ui-components from flow to typescript
This commit is contained in:
@@ -1,43 +1,44 @@
|
||||
import React from 'react';
|
||||
import { mount, shallow } from '@scm-manager/ui-tests/enzyme-router';
|
||||
import '@scm-manager/ui-tests/i18n';
|
||||
import Paginator from './Paginator';
|
||||
import React from "react";
|
||||
import { mount, shallow } from "@scm-manager/ui-tests/enzyme-router";
|
||||
import "@scm-manager/ui-tests/i18n";
|
||||
import Paginator from "./Paginator";
|
||||
|
||||
xdescribe('paginator rendering tests', () => {
|
||||
xdescribe("paginator rendering tests", () => {
|
||||
const dummyLink = {
|
||||
href: 'https://dummy',
|
||||
href: "https://dummy"
|
||||
};
|
||||
|
||||
it('should render all buttons but disabled, without links', () => {
|
||||
it("should render all buttons but disabled, without links", () => {
|
||||
const collection = {
|
||||
page: 10,
|
||||
pageTotal: 20,
|
||||
_links: {},
|
||||
_embedded: {},
|
||||
_embedded: {}
|
||||
};
|
||||
|
||||
const paginator = shallow(<Paginator collection={collection} />);
|
||||
const buttons = paginator.find('Button');
|
||||
const buttons = paginator.find("Button");
|
||||
expect(buttons.length).toBe(7);
|
||||
for (let button of buttons) {
|
||||
buttons.forEach(button => {
|
||||
// @ts-ignore ???
|
||||
expect(button.props.disabled).toBeTruthy();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
it('should render buttons for first page', () => {
|
||||
it("should render buttons for first page", () => {
|
||||
const collection = {
|
||||
page: 0,
|
||||
pageTotal: 148,
|
||||
_links: {
|
||||
first: dummyLink,
|
||||
next: dummyLink,
|
||||
last: dummyLink,
|
||||
last: dummyLink
|
||||
},
|
||||
_embedded: {},
|
||||
_embedded: {}
|
||||
};
|
||||
|
||||
const paginator = shallow(<Paginator collection={collection} />);
|
||||
const buttons = paginator.find('Button');
|
||||
const buttons = paginator.find("Button");
|
||||
expect(buttons.length).toBe(5);
|
||||
|
||||
// previous button
|
||||
@@ -52,15 +53,15 @@ xdescribe('paginator rendering tests', () => {
|
||||
// next button
|
||||
const nextButton = buttons.get(3).props;
|
||||
expect(nextButton.disabled).toBeFalsy();
|
||||
expect(nextButton.label).toBe('2');
|
||||
expect(nextButton.label).toBe("2");
|
||||
|
||||
// last button
|
||||
const lastButton = buttons.get(4).props;
|
||||
expect(lastButton.disabled).toBeFalsy();
|
||||
expect(lastButton.label).toBe('148');
|
||||
expect(lastButton.label).toBe("148");
|
||||
});
|
||||
|
||||
it('should render buttons for second page', () => {
|
||||
it("should render buttons for second page", () => {
|
||||
const collection = {
|
||||
page: 1,
|
||||
pageTotal: 148,
|
||||
@@ -68,13 +69,13 @@ xdescribe('paginator rendering tests', () => {
|
||||
first: dummyLink,
|
||||
prev: dummyLink,
|
||||
next: dummyLink,
|
||||
last: dummyLink,
|
||||
last: dummyLink
|
||||
},
|
||||
_embedded: {},
|
||||
_embedded: {}
|
||||
};
|
||||
|
||||
const paginator = shallow(<Paginator collection={collection} />);
|
||||
const buttons = paginator.find('Button');
|
||||
const buttons = paginator.find("Button");
|
||||
expect(buttons.length).toBe(6);
|
||||
|
||||
// previous button
|
||||
@@ -84,7 +85,7 @@ xdescribe('paginator rendering tests', () => {
|
||||
// first button
|
||||
const firstButton = buttons.get(2).props;
|
||||
expect(firstButton.disabled).toBeFalsy();
|
||||
expect(firstButton.label).toBe('1');
|
||||
expect(firstButton.label).toBe("1");
|
||||
|
||||
// current button
|
||||
const currentButton = buttons.get(3).props;
|
||||
@@ -94,27 +95,27 @@ xdescribe('paginator rendering tests', () => {
|
||||
// next button
|
||||
const nextButton = buttons.get(4).props;
|
||||
expect(nextButton.disabled).toBeFalsy();
|
||||
expect(nextButton.label).toBe('3');
|
||||
expect(nextButton.label).toBe("3");
|
||||
|
||||
// last button
|
||||
const lastButton = buttons.get(5).props;
|
||||
expect(lastButton.disabled).toBeFalsy();
|
||||
expect(lastButton.label).toBe('148');
|
||||
expect(lastButton.label).toBe("148");
|
||||
});
|
||||
|
||||
it('should render buttons for last page', () => {
|
||||
it("should render buttons for last page", () => {
|
||||
const collection = {
|
||||
page: 147,
|
||||
pageTotal: 148,
|
||||
_links: {
|
||||
first: dummyLink,
|
||||
prev: dummyLink,
|
||||
prev: dummyLink
|
||||
},
|
||||
_embedded: {},
|
||||
_embedded: {}
|
||||
};
|
||||
|
||||
const paginator = shallow(<Paginator collection={collection} />);
|
||||
const buttons = paginator.find('Button');
|
||||
const buttons = paginator.find("Button");
|
||||
expect(buttons.length).toBe(5);
|
||||
|
||||
// previous button
|
||||
@@ -124,12 +125,12 @@ xdescribe('paginator rendering tests', () => {
|
||||
// first button
|
||||
const firstButton = buttons.get(2).props;
|
||||
expect(firstButton.disabled).toBeFalsy();
|
||||
expect(firstButton.label).toBe('1');
|
||||
expect(firstButton.label).toBe("1");
|
||||
|
||||
// next button
|
||||
const nextButton = buttons.get(3).props;
|
||||
expect(nextButton.disabled).toBeFalsy();
|
||||
expect(nextButton.label).toBe('147');
|
||||
expect(nextButton.label).toBe("147");
|
||||
|
||||
// last button
|
||||
const lastButton = buttons.get(4).props;
|
||||
@@ -137,7 +138,7 @@ xdescribe('paginator rendering tests', () => {
|
||||
expect(lastButton.label).toBe(148);
|
||||
});
|
||||
|
||||
it('should render buttons for penultimate page', () => {
|
||||
it("should render buttons for penultimate page", () => {
|
||||
const collection = {
|
||||
page: 146,
|
||||
pageTotal: 148,
|
||||
@@ -145,13 +146,13 @@ xdescribe('paginator rendering tests', () => {
|
||||
first: dummyLink,
|
||||
prev: dummyLink,
|
||||
next: dummyLink,
|
||||
last: dummyLink,
|
||||
last: dummyLink
|
||||
},
|
||||
_embedded: {},
|
||||
_embedded: {}
|
||||
};
|
||||
|
||||
const paginator = shallow(<Paginator collection={collection} />);
|
||||
const buttons = paginator.find('Button');
|
||||
const buttons = paginator.find("Button");
|
||||
expect(buttons.length).toBe(6);
|
||||
|
||||
// previous button
|
||||
@@ -162,11 +163,11 @@ xdescribe('paginator rendering tests', () => {
|
||||
// first button
|
||||
const firstButton = buttons.get(2).props;
|
||||
expect(firstButton.disabled).toBeFalsy();
|
||||
expect(firstButton.label).toBe('1');
|
||||
expect(firstButton.label).toBe("1");
|
||||
|
||||
const currentButton = buttons.get(3).props;
|
||||
expect(currentButton.disabled).toBeFalsy();
|
||||
expect(currentButton.label).toBe('146');
|
||||
expect(currentButton.label).toBe("146");
|
||||
|
||||
// current button
|
||||
const nextButton = buttons.get(4).props;
|
||||
@@ -176,10 +177,10 @@ xdescribe('paginator rendering tests', () => {
|
||||
// last button
|
||||
const lastButton = buttons.get(5).props;
|
||||
expect(lastButton.disabled).toBeFalsy();
|
||||
expect(lastButton.label).toBe('148');
|
||||
expect(lastButton.label).toBe("148");
|
||||
});
|
||||
|
||||
it('should render buttons for a page in the middle', () => {
|
||||
it("should render buttons for a page in the middle", () => {
|
||||
const collection = {
|
||||
page: 41,
|
||||
pageTotal: 148,
|
||||
@@ -187,13 +188,13 @@ xdescribe('paginator rendering tests', () => {
|
||||
first: dummyLink,
|
||||
prev: dummyLink,
|
||||
next: dummyLink,
|
||||
last: dummyLink,
|
||||
last: dummyLink
|
||||
},
|
||||
_embedded: {},
|
||||
_embedded: {}
|
||||
};
|
||||
|
||||
const paginator = shallow(<Paginator collection={collection} />);
|
||||
const buttons = paginator.find('Button');
|
||||
const buttons = paginator.find("Button");
|
||||
expect(buttons.length).toBe(7);
|
||||
|
||||
// previous button
|
||||
@@ -204,12 +205,12 @@ xdescribe('paginator rendering tests', () => {
|
||||
// first button
|
||||
const firstButton = buttons.get(2).props;
|
||||
expect(firstButton.disabled).toBeFalsy();
|
||||
expect(firstButton.label).toBe('1');
|
||||
expect(firstButton.label).toBe("1");
|
||||
|
||||
// previous Button
|
||||
const previousButton = buttons.get(3).props;
|
||||
expect(previousButton.disabled).toBeFalsy();
|
||||
expect(previousButton.label).toBe('41');
|
||||
expect(previousButton.label).toBe("41");
|
||||
|
||||
// current button
|
||||
const currentButton = buttons.get(4).props;
|
||||
@@ -219,27 +220,27 @@ xdescribe('paginator rendering tests', () => {
|
||||
// next button
|
||||
const nextButton = buttons.get(5).props;
|
||||
expect(nextButton.disabled).toBeFalsy();
|
||||
expect(nextButton.label).toBe('43');
|
||||
expect(nextButton.label).toBe("43");
|
||||
|
||||
// last button
|
||||
const lastButton = buttons.get(6).props;
|
||||
expect(lastButton.disabled).toBeFalsy();
|
||||
expect(lastButton.label).toBe('148');
|
||||
expect(lastButton.label).toBe("148");
|
||||
});
|
||||
|
||||
it('should call the function with the last previous url', () => {
|
||||
it("should call the function with the last previous url", () => {
|
||||
const collection = {
|
||||
page: 41,
|
||||
pageTotal: 148,
|
||||
_links: {
|
||||
first: dummyLink,
|
||||
prev: {
|
||||
href: 'https://www.scm-manager.org',
|
||||
href: "https://www.scm-manager.org"
|
||||
},
|
||||
next: dummyLink,
|
||||
last: dummyLink,
|
||||
last: dummyLink
|
||||
},
|
||||
_embedded: {},
|
||||
_embedded: {}
|
||||
};
|
||||
|
||||
let urlToOpen;
|
||||
@@ -248,10 +249,10 @@ xdescribe('paginator rendering tests', () => {
|
||||
};
|
||||
|
||||
const paginator = mount(
|
||||
<Paginator collection={collection} onPageChange={callMe} />,
|
||||
<Paginator collection={collection} onPageChange={callMe} />
|
||||
);
|
||||
paginator.find('Button.pagination-previous').simulate('click');
|
||||
paginator.find("Button.pagination-previous").simulate("click");
|
||||
|
||||
expect(urlToOpen).toBe('https://www.scm-manager.org');
|
||||
expect(urlToOpen).toBe("https://www.scm-manager.org");
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user