inital commit

This commit is contained in:
2026-01-01 15:25:19 +05:30
commit f0ae49465a
36361 changed files with 4894111 additions and 0 deletions

152
node_modules/reactstrap/esm/__tests__/Accordion.spec.js generated vendored Normal file

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,42 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { AccordionBody, AccordionContext } from '..';
import { testForCustomClass } from '../testUtils';
describe('AccordionBody', function () {
it('should render with "accordion-body" class within "accordion-collapse', function () {
render( /*#__PURE__*/React.createElement(AccordionBody, {
accordionId: "cool-accordion",
"data-testid": "accordion-body"
}, "accordion body"));
expect(screen.getByTestId('accordion-body')).toHaveClass('accordion-collapse');
expect(screen.getByText(/accordion body/i)).toHaveClass('accordion-body');
});
it('should render additional classes', function () {
testForCustomClass(AccordionBody, {
accordionId: '1'
});
});
it('should render custom tag', function () {
render( /*#__PURE__*/React.createElement(AccordionBody, {
accordionId: "cool-accordion",
tag: "h1"
}, "accordion body"));
expect(screen.getByText(/accordion body/i).tagName).toMatch(/h1/i);
});
it('should be open if open == id', function () {
render( /*#__PURE__*/React.createElement(AccordionContext.Provider, {
value: {
open: 'cool-accordion'
}
}, /*#__PURE__*/React.createElement(AccordionBody, {
accordionId: "cool-accordion",
"data-testid": "accordion-body-1"
}), /*#__PURE__*/React.createElement(AccordionBody, {
accordionId: "not-cool-accordion",
"data-testid": "accordion-body-2"
})));
expect(screen.getByTestId('accordion-body-1')).toHaveClass('show');
expect(screen.getByTestId('accordion-body-2')).not.toHaveClass('show');
});
});

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,19 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { AccordionItem } from '..';
import { testForCustomClass, testForCustomTag } from '../testUtils';
describe('AccordionItem', function () {
it('should render with "accordion-item" class', function () {
render( /*#__PURE__*/React.createElement(AccordionItem, {
"data-testid": "accordion-item"
}));
expect(screen.getByTestId('accordion-item')).toHaveClass('accordion-item');
});
it('should render additional classes', function () {
testForCustomClass(AccordionItem);
});
it('should render custom tag', function () {
testForCustomTag(AccordionItem);
});
});

108
node_modules/reactstrap/esm/__tests__/Alert.spec.js generated vendored Normal file
View File

@@ -0,0 +1,108 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import user from '@testing-library/user-event';
import '@testing-library/jest-dom';
import { testForCustomClass, testForCustomTag } from '../testUtils';
import { Alert } from '..';
describe('Alert', function () {
beforeEach(function () {
jest.resetModules();
jest.useFakeTimers();
});
it('should render children', function () {
render( /*#__PURE__*/React.createElement(Alert, null, "Yo!"));
expect(screen.getByText('Yo!')).toBeInTheDocument();
});
it('should render additional classes', function () {
testForCustomClass(Alert);
});
it('should render custom tag', function () {
testForCustomTag(Alert);
});
it('should pass close className down', function () {
var noop = function noop() {};
render( /*#__PURE__*/React.createElement(Alert, {
toggle: noop,
closeClassName: "test-class-name"
}, "Yo!"));
expect(screen.getByLabelText('Close')).toHaveClass('test-class-name');
});
it('should pass other props down', function () {
render( /*#__PURE__*/React.createElement(Alert, {
"data-testprop": "testvalue"
}, "Yo!"));
expect(screen.getByText('Yo!')).toHaveAttribute('data-testprop', 'testvalue');
});
it('should have "success" as default color', function () {
render( /*#__PURE__*/React.createElement(Alert, null, "Yo!"));
expect(screen.getByText('Yo!')).toHaveClass('alert-success');
});
it('should accept color prop', function () {
render( /*#__PURE__*/React.createElement(Alert, {
color: "warning"
}, "Yo!"));
expect(screen.getByText('Yo!')).toHaveClass('alert-warning');
});
it('should use a div tag by default', function () {
render( /*#__PURE__*/React.createElement(Alert, null, "Yo!"));
expect(screen.getByText('Yo!').tagName.toLowerCase()).toEqual('div');
});
it('should be non dismissible by default', function () {
render( /*#__PURE__*/React.createElement(Alert, null, "Yo!"));
expect(screen.queryByLabelText('Close')).toBe(null);
expect(screen.getByText('Yo!')).not.toHaveClass('alert-dismissible');
});
it('should show dismiss button if passed toggle', function () {
render( /*#__PURE__*/React.createElement(Alert, {
color: "danger",
toggle: function toggle() {}
}, "Yo!"));
expect(screen.getByLabelText('Close')).toBeInTheDocument();
expect(screen.getByText('Yo!')).toHaveClass('alert-dismissible');
});
it('should be empty if not isOpen', function () {
render( /*#__PURE__*/React.createElement(Alert, {
isOpen: false
}, "Yo!"));
expect(screen.queryByText('Yo!')).toBe(null);
});
it('should be dismissible', function () {
var mockFn = jest.fn();
render( /*#__PURE__*/React.createElement(Alert, {
color: "danger",
toggle: mockFn
}, "Yo!"));
screen.getByText('Yo!');
user.click(screen.getByLabelText('Close'));
expect(mockFn).toHaveBeenCalled();
});
it('should render close button with custom aria-label', function () {
render( /*#__PURE__*/React.createElement(Alert, {
toggle: function toggle() {},
closeAriaLabel: "oseclay"
}, "Yo!"));
expect(screen.getByLabelText('oseclay')).toBeInTheDocument();
});
it('should have default transitionTimeouts', function () {
render( /*#__PURE__*/React.createElement(Alert, null, "Hello"));
expect(screen.getByText(/hello/i)).not.toHaveClass('show');
jest.advanceTimersByTime(150);
expect(screen.getByText(/hello/i)).toHaveClass('show');
});
it('should have support configurable transitionTimeouts', function () {
render( /*#__PURE__*/React.createElement(Alert, {
transition: {
timeout: 0,
appear: false,
enter: false,
exit: false
}
}, "Hello"));
expect(screen.getByText(/hello/i)).toHaveClass('show');
});
it('works with strict mode', function () {
var spy = jest.spyOn(console, 'error');
render( /*#__PURE__*/React.createElement(React.StrictMode, null, /*#__PURE__*/React.createElement(Alert, null, "Hello")));
expect(spy).not.toHaveBeenCalled();
});
});

39
node_modules/reactstrap/esm/__tests__/Badge.spec.js generated vendored Normal file
View File

@@ -0,0 +1,39 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { Badge } from '..';
import { testForChildrenInComponent, testForCustomTag, testForDefaultClass, testForDefaultTag } from '../testUtils';
describe('Badge', function () {
it('should render a span by default', function () {
testForDefaultTag(Badge, 'span');
});
it('should render an anchor when when href is provided', function () {
render( /*#__PURE__*/React.createElement(Badge, {
href: "#",
"data-testid": "badge"
}, "Yo!"));
expect(screen.getByTestId('badge').tagName.toLowerCase()).toBe('a');
});
it('should render a custom tag when provided', function () {
testForCustomTag(Badge);
});
it('should render children', function () {
testForChildrenInComponent(Badge);
});
it('should render badges with secondary color', function () {
testForDefaultClass(Badge, 'bg-secondary');
});
it('should render Badges with other colors', function () {
render( /*#__PURE__*/React.createElement(Badge, {
color: "danger",
"data-testid": "badge"
}, "Danger Badge"));
expect(screen.getByTestId('badge')).toHaveClass('bg-danger');
});
it('should render Badges as pills', function () {
render( /*#__PURE__*/React.createElement(Badge, {
pill: true,
"data-testid": "badge"
}, "Pill Badge"));
expect(screen.getByTestId('badge')).toHaveClass('rounded-pill');
});
});

View File

@@ -0,0 +1,25 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { Breadcrumb } from '..';
import { testForChildrenInComponent, testForCustomTag, testForDefaultTag } from '../testUtils';
describe('Breadcrumb', function () {
it('should render children', function () {
testForChildrenInComponent(Breadcrumb);
});
it('should render "nav" by default', function () {
testForDefaultTag(Breadcrumb, 'nav');
});
it('should render "ol" by default', function () {
render( /*#__PURE__*/React.createElement(Breadcrumb, null, "Yo!"));
expect(screen.getByText('Yo!').tagName.toLowerCase()).toMatch('ol');
});
it('should render with the "breadcrumb" class', function () {
render( /*#__PURE__*/React.createElement(Breadcrumb, {
"data-testid": "test"
}, "Yo!"));
expect(screen.getByText('Yo!')).toHaveClass('breadcrumb');
});
it('should render custom tag', function () {
testForCustomTag(Breadcrumb);
});
});

View File

@@ -0,0 +1,29 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { BreadcrumbItem } from '..';
import { testForChildrenInComponent, testForCustomTag, testForDefaultClass, testForDefaultTag } from '../testUtils';
describe('BreadcrumbItem', function () {
it('should render children', function () {
testForChildrenInComponent(BreadcrumbItem);
});
it('should render "li" by default', function () {
testForDefaultTag(BreadcrumbItem, 'li');
});
it('should render with the "breadcrumb-item" class', function () {
testForDefaultClass(BreadcrumbItem, 'breadcrumb-item');
});
it('should not render with the "active" class by default', function () {
render( /*#__PURE__*/React.createElement(BreadcrumbItem, null, "Yo!"));
expect(screen.getByText('Yo!')).not.toHaveClass('active');
});
it('should render with the "active" class when the avtive prop is truthy', function () {
render( /*#__PURE__*/React.createElement(BreadcrumbItem, {
active: true
}, "Yo!"));
expect(screen.getByText('Yo!')).toHaveClass('active');
});
it('should render custom tag', function () {
testForCustomTag(BreadcrumbItem);
});
});

123
node_modules/reactstrap/esm/__tests__/Button.spec.js generated vendored Normal file
View File

@@ -0,0 +1,123 @@
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import React from 'react';
import { render, screen } from '@testing-library/react';
import user from '@testing-library/user-event';
import { Button } from '..';
import { testForChildrenInComponent, testForDefaultClass, testForDefaultTag } from '../testUtils';
describe('Button', function () {
it('should render children', function () {
testForChildrenInComponent(Button);
});
it('should render custom element', function () {
function Link(props) {
return /*#__PURE__*/React.createElement("a", _extends({
href: "/home"
}, props), props.children);
}
render( /*#__PURE__*/React.createElement(Button, {
tag: Link
}, "Home"));
expect(screen.getByText(/home/i).tagName.toLowerCase()).toBe('a');
});
it('should render a button by default', function () {
testForDefaultTag(Button, 'button');
});
it('should render an anchor element if href exists', function () {
render( /*#__PURE__*/React.createElement(Button, {
href: "/home"
}, "Home"));
expect(screen.getByText(/home/i).tagName.toLowerCase()).toBe('a');
});
it('should render type as undefined by default when tag is "button"', function () {
render( /*#__PURE__*/React.createElement(Button, null, "Home"));
expect(screen.getByText(/home/i)).not.toHaveAttribute('type');
});
it('should render type as "button" by default when tag is "button" and onClick is provided', function () {
render( /*#__PURE__*/React.createElement(Button, {
onClick: function onClick() {}
}, "Home"));
expect(screen.getByText(/home/i)).toHaveAttribute('type', 'button');
});
it('should render type as user defined when defined by the user', function () {
var TYPE = 'submit';
render( /*#__PURE__*/React.createElement(Button, {
type: TYPE
}, "Home"));
expect(screen.getByText(/home/i)).toHaveAttribute('type', TYPE);
});
it('should not render type by default when the type is not defined and the tag is not "button"', function () {
render( /*#__PURE__*/React.createElement(Button, {
tag: "a"
}, "Home"));
expect(screen.getByText(/home/i)).not.toHaveAttribute('type');
});
it('should not render type by default when the type is not defined and the href is defined', function () {
render( /*#__PURE__*/React.createElement(Button, {
href: "#"
}, "Home"));
expect(screen.getByText(/home/i)).not.toHaveAttribute('type');
});
it('should render buttons with default color', function () {
testForDefaultClass(Button, 'btn-secondary');
});
it('should render buttons with other colors', function () {
render( /*#__PURE__*/React.createElement(Button, {
color: "danger"
}, "Home"));
expect(screen.getByText(/home/i)).toHaveClass('btn-danger');
});
it('should render buttons with outline variant', function () {
render( /*#__PURE__*/React.createElement(Button, {
outline: true
}, "Home"));
expect(screen.getByText(/home/i)).toHaveClass('btn-outline-secondary');
});
it('should render buttons with outline variant with different colors', function () {
render( /*#__PURE__*/React.createElement(Button, {
outline: true,
color: "info"
}, "Home"));
expect(screen.getByText(/home/i)).toHaveClass('btn-outline-info');
});
it('should render buttons at different sizes', function () {
render( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, {
size: "sm"
}, "Small Button"), /*#__PURE__*/React.createElement(Button, {
size: "lg"
}, "Large Button")));
expect(screen.getByText(/small/i)).toHaveClass('btn-sm');
expect(screen.getByText(/large/i)).toHaveClass('btn-lg');
});
it('should render block level buttons', function () {
render( /*#__PURE__*/React.createElement(Button, {
block: true
}, "Block Level Button"));
expect(screen.getByText(/block/i)).toHaveClass('d-block w-100');
});
it('should render close icon with custom child and props', function () {
var testChild = 'close this thing';
render( /*#__PURE__*/React.createElement(Button, {
close: true
}, testChild));
expect(screen.getByText(testChild)).toHaveClass('btn-close');
});
describe('onClick', function () {
it('calls props.onClick if it exists', function () {
var onClick = jest.fn();
render( /*#__PURE__*/React.createElement(Button, {
onClick: onClick
}, "Testing Click"));
user.click(screen.getByText(/testing click/i));
expect(onClick).toHaveBeenCalled();
});
it('is not called when disabled', function () {
var onClick = jest.fn();
render( /*#__PURE__*/React.createElement(Button, {
onClick: onClick,
disabled: true
}, "Testing Click"));
user.click(screen.getByText(/testing click/i));
expect(onClick).not.toHaveBeenCalled();
});
});
});

View File

@@ -0,0 +1,27 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { ButtonDropdown, DropdownToggle, DropdownMenu, DropdownItem } from '..';
describe('ButtonDropdown', function () {
var isOpen;
var toggle;
beforeEach(function () {
toggle = function toggle() {};
});
it('should render a single child', function () {
render( /*#__PURE__*/React.createElement(ButtonDropdown, {
isOpen: true,
toggle: toggle
}, "Ello world"));
expect(screen.getByText('Ello world')).toBeInTheDocument();
});
it('should render multiple children when isOpen', function () {
isOpen = true;
render( /*#__PURE__*/React.createElement(ButtonDropdown, {
isOpen: true,
toggle: toggle
}, /*#__PURE__*/React.createElement(DropdownToggle, null, "Toggle"), /*#__PURE__*/React.createElement(DropdownMenu, null, /*#__PURE__*/React.createElement(DropdownItem, null, "Test"))));
expect(screen.getByText(/toggle/i)).toBeInTheDocument();
expect(screen.getByText(/test/i)).toBeInTheDocument();
});
});

View File

@@ -0,0 +1,27 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { ButtonGroup } from '..';
import { testForChildrenInComponent, testForCustomTag } from '../testUtils';
describe('ButtonGroup', function () {
it('should render children', function () {
testForChildrenInComponent(ButtonGroup);
});
it('should render different size classes', function () {
render( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(ButtonGroup, {
size: "sm"
}, "Small Button"), /*#__PURE__*/React.createElement(ButtonGroup, {
size: "lg"
}, "Large Button")));
expect(screen.getByText(/small/i)).toHaveClass('btn-group-sm');
expect(screen.getByText(/large/i)).toHaveClass('btn-group-lg');
});
it('should render vertical class', function () {
render( /*#__PURE__*/React.createElement(ButtonGroup, {
vertical: true
}, "Vertical Group"));
expect(screen.getByText(/vertical/i)).toHaveClass('btn-group-vertical');
});
it('should render custom tag', function () {
testForCustomTag(ButtonGroup);
});
});

View File

@@ -0,0 +1,56 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import user from '@testing-library/user-event';
import { ButtonToggle } from '..';
import { testForChildrenInComponent } from '../testUtils';
describe('ButtonToggle', function () {
it('should render children', function () {
testForChildrenInComponent(ButtonToggle);
});
it('should have button already toggled for defaultValue true', function () {
render( /*#__PURE__*/React.createElement(ButtonToggle, {
defaultValue: true
}, "Ello world"));
expect(screen.getByText(/world/i)).toHaveClass('active');
});
describe('onClick', function () {
it('calls props.onClick if it exists', function () {
var onClick = jest.fn();
render( /*#__PURE__*/React.createElement(ButtonToggle, {
onClick: onClick
}, "Testing Click"));
user.click(screen.getByText(/testing click/i));
expect(onClick).toHaveBeenCalled();
});
it('should not call props.onClick if it exists and button is disabled', function () {
var onClick = jest.fn();
render( /*#__PURE__*/React.createElement(ButtonToggle, {
onClick: onClick,
disabled: true
}, "Testing Click"));
user.click(screen.getByText(/testing click/i));
expect(onClick).not.toHaveBeenCalled();
});
});
describe('onFocus', function () {
it('calls props.onFocus if it exists', function () {
var onFocus = jest.fn();
render( /*#__PURE__*/React.createElement(ButtonToggle, {
onFocus: onFocus
}, "Testing Click"));
screen.getByText(/testing click/i).focus();
expect(onFocus).toHaveBeenCalled();
});
});
describe('onBlur', function () {
it('calls props.onBlur if it exists', function () {
var onBlur = jest.fn();
render( /*#__PURE__*/React.createElement(ButtonToggle, {
onBlur: onBlur
}, "Testing Click"));
screen.getByText(/testing click/i).focus();
screen.getByText(/testing click/i).blur();
expect(onBlur).toHaveBeenCalled();
});
});
});

View File

@@ -0,0 +1,13 @@
import { ButtonToolbar } from '..';
import { testForChildrenInComponent, testForCustomTag, testForDefaultClass } from '../testUtils';
describe('ButtonToolbar', function () {
it('should render children', function () {
testForChildrenInComponent(ButtonToolbar);
});
it('should render with the "btn-toolbar" class', function () {
testForDefaultClass(ButtonToolbar, 'btn-toolbar');
});
it('should render custom tag', function () {
testForCustomTag(ButtonToolbar);
});
});

38
node_modules/reactstrap/esm/__tests__/Card.spec.js generated vendored Normal file
View File

@@ -0,0 +1,38 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { Card } from '..';
import { testForCustomClass, testForCustomTag, testForDefaultClass } from '../testUtils';
describe('Card', function () {
it('should render with "card" class', function () {
testForDefaultClass(Card, 'card');
});
it('should render with "bg-primary" class', function () {
render( /*#__PURE__*/React.createElement(Card, {
inverse: true,
body: true,
color: "primary"
}, "Yo!"));
expect(screen.getByText('Yo!')).toHaveClass('card card-body bg-primary text-white');
});
it('should render with "outline" class when a color is provided', function () {
render( /*#__PURE__*/React.createElement(Card, {
outline: true,
body: true,
color: "primary"
}, "Yo!"));
expect(screen.getByText('Yo!')).toHaveClass('card card-body border-primary');
});
it('should not render with "outline" class when a color is not provided (no default)', function () {
render( /*#__PURE__*/React.createElement(Card, {
outline: true,
body: true
}, "Yo!"));
expect(screen.getByText('Yo!').className).not.toMatch(/border/i);
});
it('should render additional classes', function () {
testForCustomClass(Card);
});
it('should render custom tag', function () {
testForCustomTag(Card);
});
});

13
node_modules/reactstrap/esm/__tests__/CardBody.spec.js generated vendored Normal file
View File

@@ -0,0 +1,13 @@
import { CardBody } from '..';
import { testForCustomClass, testForCustomTag, testForDefaultClass } from '../testUtils';
describe('CardBody', function () {
it('should render with "card-body" class', function () {
testForDefaultClass(CardBody, 'card-body');
});
it('should render additional classes', function () {
testForCustomClass(CardBody);
});
it('should render custom tag', function () {
testForCustomTag(CardBody);
});
});

View File

@@ -0,0 +1,13 @@
import { CardColumns } from '..';
import { testForCustomClass, testForCustomTag, testForDefaultClass } from '../testUtils';
describe('CardColumns', function () {
it('should render with "card-columns" class', function () {
testForDefaultClass(CardColumns, 'card-columns');
});
it('should render additional classes', function () {
testForCustomClass(CardColumns);
});
it('should render custom tag', function () {
testForCustomTag(CardColumns);
});
});

13
node_modules/reactstrap/esm/__tests__/CardDeck.spec.js generated vendored Normal file
View File

@@ -0,0 +1,13 @@
import { CardDeck } from '..';
import { testForCustomClass, testForCustomTag, testForDefaultClass } from '../testUtils';
describe('CardDeck', function () {
it('should render with "card-deck" class', function () {
testForDefaultClass(CardDeck, 'card-deck');
});
it('should render additional classes', function () {
testForCustomClass(CardDeck);
});
it('should render custom tag', function () {
testForCustomTag(CardDeck);
});
});

View File

@@ -0,0 +1,13 @@
import { CardFooter } from '..';
import { testForCustomClass, testForCustomTag, testForDefaultClass } from '../testUtils';
describe('CardFooter', function () {
it('should render with "card-footer" class', function () {
testForDefaultClass(CardFooter, 'card-footer');
});
it('should render additional classes', function () {
testForCustomClass(CardFooter);
});
it('should render custom tag', function () {
testForCustomTag(CardFooter);
});
});

View File

@@ -0,0 +1,13 @@
import { CardGroup } from '..';
import { testForCustomClass, testForCustomTag, testForDefaultClass } from '../testUtils';
describe('CardGroup', function () {
it('should render with "card-group" class', function () {
testForDefaultClass(CardGroup, 'card-group');
});
it('should render additional classes', function () {
testForCustomClass(CardGroup);
});
it('should render custom tag', function () {
testForCustomTag(CardGroup);
});
});

View File

@@ -0,0 +1,13 @@
import { CardHeader } from '..';
import { testForCustomClass, testForCustomTag, testForDefaultClass } from '../testUtils';
describe('CardHeader', function () {
it('should render with "card-header" class', function () {
testForDefaultClass(CardHeader, 'card-header');
});
it('should render additional classes', function () {
testForCustomClass(CardHeader);
});
it('should render custom tag', function () {
testForCustomTag(CardHeader);
});
});

31
node_modules/reactstrap/esm/__tests__/CardImg.spec.js generated vendored Normal file
View File

@@ -0,0 +1,31 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { CardImg } from '..';
import { testForCustomClass, testForCustomTag, testForDefaultClass } from '../testUtils';
describe('CardImg', function () {
it('should render with "card-img" class', function () {
testForDefaultClass(CardImg, 'card-img');
});
it('should render top class name', function () {
render( /*#__PURE__*/React.createElement(CardImg, {
top: true,
alt: "awesome poster",
src: "/path/image.png"
}));
expect(screen.getByAltText(/awesome poster/i)).toHaveClass('card-img-top');
});
it('should render bottom class name', function () {
render( /*#__PURE__*/React.createElement(CardImg, {
bottom: true,
alt: "awesome poster",
src: "/path/image.png"
}));
expect(screen.getByAltText(/awesome poster/i)).toHaveClass('card-img-bottom');
});
it('should render custom tag', function () {
testForCustomTag(CardImg);
});
it('should render additional classes', function () {
testForCustomClass(CardImg);
});
});

View File

@@ -0,0 +1,13 @@
import { CardImgOverlay } from '..';
import { testForCustomClass, testForCustomTag, testForDefaultClass } from '../testUtils';
describe('CardImgOverlay', function () {
it('should render with "card-img-overlay" class', function () {
testForDefaultClass(CardImgOverlay, 'card-img-overlay');
});
it('should render additional classes', function () {
testForCustomClass(CardImgOverlay);
});
it('should render custom tag', function () {
testForCustomTag(CardImgOverlay);
});
});

13
node_modules/reactstrap/esm/__tests__/CardLink.spec.js generated vendored Normal file
View File

@@ -0,0 +1,13 @@
import { CardLink } from '..';
import { testForCustomClass, testForCustomTag, testForDefaultClass } from '../testUtils';
describe('CardLink', function () {
it('should render with "card-link" class', function () {
testForDefaultClass(CardLink, 'card-link');
});
it('should render additional classes', function () {
testForCustomClass(CardLink);
});
it('should render custom tag', function () {
testForCustomTag(CardLink);
});
});

View File

@@ -0,0 +1,16 @@
import { CardSubtitle } from '..';
import { testForCustomClass, testForCustomTag, testForDefaultClass, testForDefaultTag } from '../testUtils';
describe('CardSubtitle', function () {
it('should render with "card-subtitle" class', function () {
testForDefaultClass(CardSubtitle, 'card-subtitle');
});
it('should render additional classes', function () {
testForCustomClass(CardSubtitle);
});
it('should render custom tag', function () {
testForCustomTag(CardSubtitle);
});
it('should render a "div" tag by default', function () {
testForDefaultTag(CardSubtitle, 'div');
});
});

13
node_modules/reactstrap/esm/__tests__/CardText.spec.js generated vendored Normal file
View File

@@ -0,0 +1,13 @@
import { CardText } from '..';
import { testForCustomClass, testForCustomTag, testForDefaultClass } from '../testUtils';
describe('CardText', function () {
it('should render with "card-text" class', function () {
testForDefaultClass(CardText, 'card-text');
});
it('should render additional classes', function () {
testForCustomClass(CardText);
});
it('should render custom tag', function () {
testForCustomTag(CardText);
});
});

View File

@@ -0,0 +1,16 @@
import { CardTitle } from '..';
import { testForCustomClass, testForCustomTag, testForDefaultClass, testForDefaultTag } from '../testUtils';
describe('CardTitle', function () {
it('should render with "card-title" class', function () {
testForDefaultClass(CardTitle, 'card-title');
});
it('should render additional classes', function () {
testForCustomClass(CardTitle);
});
it('should render custom tag', function () {
testForCustomTag(CardTitle);
});
it('should render a "div" tag by default', function () {
testForDefaultTag(CardTitle, 'div');
});
});

615
node_modules/reactstrap/esm/__tests__/Carousel.spec.js generated vendored Normal file
View File

@@ -0,0 +1,615 @@
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import user from '@testing-library/user-event';
import { Carousel } from '..';
import CarouselItem from '../CarouselItem';
import CarouselIndicators from '../CarouselIndicators';
import CarouselControl from '../CarouselControl';
import CarouselCaption from '../CarouselCaption';
import { CarouselContext } from '../CarouselContext';
var DEFAULT_TIMER_TIME = 600;
describe('Carousel', function () {
beforeEach(function () {
jest.useFakeTimers();
});
afterEach(function () {
jest.clearAllTimers();
});
var items = [{
src: '',
altText: 'a',
caption: 'caption 1'
}, {
src: '',
altText: 'b',
caption: 'caption 2'
}, {
src: '',
altText: 'c',
caption: 'caption 3'
}];
var slides = items.map(function (item, idx) {
return /*#__PURE__*/React.createElement(CarouselItem, {
key: idx
}, /*#__PURE__*/React.createElement(CarouselCaption, {
captionText: item.caption,
captionHeader: item.caption
}));
});
describe('captions', function () {
it('should render a header and a caption', function () {
render( /*#__PURE__*/React.createElement(CarouselCaption, {
captionHeader: "abc",
captionText: "def"
}));
expect(screen.getByText('abc').tagName.toLowerCase()).toBe('h3');
expect(screen.getByText('def').tagName.toLowerCase()).toBe('p');
});
});
describe('items', function () {
it('should render custom tag', function () {
render( /*#__PURE__*/React.createElement(CarouselItem, {
tag: "main"
}, "Hello"));
expect(screen.getByText(/hello/i).tagName.toLowerCase()).toBe('main');
});
it('should render an image if one is passed in', function () {
render( /*#__PURE__*/React.createElement(CarouselItem, null, /*#__PURE__*/React.createElement("img", {
src: items[0].src,
alt: items[0].altText
})));
expect(screen.getByAltText(items[0].altText)).toBeInTheDocument();
});
it('should render a caption if one is passed in', function () {
render( /*#__PURE__*/React.createElement(CarouselItem, null, /*#__PURE__*/React.createElement(CarouselCaption, {
captionHeader: "header",
captionText: "text"
})));
expect(screen.getByText('header')).toBeInTheDocument();
expect(screen.getByText('text')).toBeInTheDocument();
});
describe('transitions', function () {
it('should add the appropriate classes when entering right', function () {
var wrapper = function wrapper(_ref) {
var children = _ref.children;
return /*#__PURE__*/React.createElement(CarouselContext.Provider, {
value: {
direction: 'end'
}
}, children);
};
var _render = render( /*#__PURE__*/React.createElement(CarouselItem, {
"in": false
}, "the mandalorian"), {
wrapper: wrapper
}),
rerender = _render.rerender;
rerender( /*#__PURE__*/React.createElement(CarouselItem, {
"in": true
}, "the mandalorian"));
expect(screen.getByText(/the mandalorian/i)).toHaveClass('carousel-item carousel-item-start carousel-item-next');
jest.advanceTimersByTime(DEFAULT_TIMER_TIME);
expect(screen.getByText(/the mandalorian/i)).toHaveClass('carousel-item active');
rerender( /*#__PURE__*/React.createElement(CarouselItem, {
"in": false
}, "the mandalorian"));
expect(screen.getByText(/the mandalorian/i)).toHaveClass('carousel-item active carousel-item-start');
jest.advanceTimersByTime(DEFAULT_TIMER_TIME);
expect(screen.getByText(/the mandalorian/i)).toHaveClass('carousel-item');
});
it('should add the appropriate classes when entering left', function () {
var wrapper = function wrapper(_ref2) {
var children = _ref2.children;
return /*#__PURE__*/React.createElement(CarouselContext.Provider, {
value: {
direction: 'start'
}
}, children);
};
var _render2 = render( /*#__PURE__*/React.createElement(CarouselItem, {
"in": false
}, "the mandalorian"), {
wrapper: wrapper
}),
rerender = _render2.rerender;
rerender( /*#__PURE__*/React.createElement(CarouselItem, {
"in": true
}, "the mandalorian"));
expect(screen.getByText(/the mandalorian/i)).toHaveClass('carousel-item carousel-item-end carousel-item-prev');
jest.advanceTimersByTime(DEFAULT_TIMER_TIME);
expect(screen.getByText(/the mandalorian/i)).toHaveClass('carousel-item active');
rerender( /*#__PURE__*/React.createElement(CarouselItem, {
"in": false
}, "the mandalorian"));
expect(screen.getByText(/the mandalorian/i)).toHaveClass('carousel-item active carousel-item-end');
jest.advanceTimersByTime(DEFAULT_TIMER_TIME);
expect(screen.getByText(/the mandalorian/i)).toHaveClass('carousel-item');
});
it('should call all callbacks when transitioning in and out', function () {
var callbacks = {
onEnter: jest.fn(),
onEntering: jest.fn(),
onEntered: jest.fn(),
onExit: jest.fn(),
onExiting: jest.fn(),
onExited: jest.fn()
};
var _render3 = render( /*#__PURE__*/React.createElement(CarouselItem, _extends({
"in": false
}, callbacks))),
rerender = _render3.rerender;
rerender( /*#__PURE__*/React.createElement(CarouselItem, _extends({
"in": true
}, callbacks)));
expect(callbacks.onEnter).toHaveBeenCalled();
expect(callbacks.onEntering).toHaveBeenCalled();
expect(callbacks.onEntered).not.toHaveBeenCalled();
jest.advanceTimersByTime(DEFAULT_TIMER_TIME);
expect(callbacks.onEntered).toHaveBeenCalled();
expect(callbacks.onExit).not.toHaveBeenCalled();
rerender( /*#__PURE__*/React.createElement(CarouselItem, _extends({
"in": false
}, callbacks)));
expect(callbacks.onExit).toHaveBeenCalled();
expect(callbacks.onExiting).toHaveBeenCalled();
expect(callbacks.onExited).not.toHaveBeenCalled();
jest.advanceTimersByTime(DEFAULT_TIMER_TIME);
expect(callbacks.onExiting).toHaveBeenCalled();
expect(callbacks.onExited).toHaveBeenCalled();
});
});
});
describe('indicators', function () {
it('should render a list with the right number of items', function () {
render( /*#__PURE__*/React.createElement(CarouselIndicators, {
items: items,
activeIndex: 0,
onClickHandler: function onClickHandler() {}
}));
expect(screen.getAllByLabelText(/caption/i).length).toBe(3);
});
it('should append the correct active class', function () {
render( /*#__PURE__*/React.createElement(CarouselIndicators, {
items: items,
activeIndex: 0,
onClickHandler: function onClickHandler() {}
}));
expect(screen.getByLabelText(/caption 1/i)).toHaveClass('active');
});
it('should call the click hanlder', function () {
var onClick = jest.fn();
render( /*#__PURE__*/React.createElement(CarouselIndicators, {
items: items,
activeIndex: 0,
onClickHandler: onClick
}));
user.click(screen.getByLabelText(/caption 1/i));
expect(onClick).toHaveBeenCalled();
});
});
describe('controls', function () {
it('should render an anchor tag', function () {
render( /*#__PURE__*/React.createElement(CarouselControl, {
direction: "next",
onClickHandler: function onClickHandler() {}
}));
expect(screen.getByRole('button').tagName.toLowerCase()).toBe('a');
});
it('should call the onClickHandler', function () {
var onClick = jest.fn();
render( /*#__PURE__*/React.createElement(CarouselControl, {
direction: "next",
onClickHandler: onClick
}));
user.click(screen.getByRole('button'));
expect(onClick).toHaveBeenCalled();
});
});
describe('rendering', function () {
it('should show the carousel indicators', function () {
render( /*#__PURE__*/React.createElement(Carousel, {
activeIndex: 0,
next: function next() {},
previous: function previous() {}
}, /*#__PURE__*/React.createElement(CarouselIndicators, {
items: items,
"data-testid": "c3po",
activeIndex: 0,
onClickHandler: function onClickHandler() {}
}), slides));
expect(screen.getByTestId('c3po')).toHaveClass('carousel-indicators');
});
it('should show controls', function () {
render( /*#__PURE__*/React.createElement(Carousel, {
activeIndex: 0,
next: function next() {},
previous: function previous() {}
}, slides, /*#__PURE__*/React.createElement(CarouselControl, {
direction: "prev",
directionText: "Previous",
onClickHandler: function onClickHandler() {}
}), /*#__PURE__*/React.createElement(CarouselControl, {
direction: "next",
directionText: "Next",
onClickHandler: function onClickHandler() {}
})));
screen.getAllByRole('button').forEach(function (element) {
expect(element.className).toMatch(/carousel-control/i);
});
});
it('should show a single slide', function () {
render( /*#__PURE__*/React.createElement(Carousel, {
activeIndex: 0,
next: function next() {},
previous: function previous() {},
"data-testid": "carousel"
}, slides));
expect(screen.getByTestId('carousel').getElementsByClassName('active').length).toBe(1);
});
it('should show indicators and controls', function () {
render( /*#__PURE__*/React.createElement(Carousel, {
activeIndex: 0,
next: function next() {},
previous: function previous() {}
}, /*#__PURE__*/React.createElement(CarouselIndicators, {
items: items,
"data-testid": "carousel-indicator",
activeIndex: 0,
onClickHandler: function onClickHandler() {}
}), slides, /*#__PURE__*/React.createElement(CarouselControl, {
direction: "prev",
"data-testid": "prev",
directionText: "Previous",
onClickHandler: function onClickHandler() {}
}), /*#__PURE__*/React.createElement(CarouselControl, {
direction: "next",
"data-testid": "next",
directionText: "Next",
onClickHandler: function onClickHandler() {}
})));
expect(screen.getByTestId('carousel-indicator')).toBeInTheDocument();
expect(screen.getByTestId('prev')).toBeInTheDocument();
expect(screen.getByTestId('next')).toBeInTheDocument();
});
it('should tolerate booleans, null and undefined values rendered as children of Carousel', function () {
render( /*#__PURE__*/React.createElement(Carousel, {
activeIndex: 0,
next: function next() {},
previous: function previous() {}
}, null, true, false, undefined, function () {}(), /*#__PURE__*/React.createElement(CarouselIndicators, {
items: items,
"data-testid": "carousel-indicator",
activeIndex: 0,
onClickHandler: function onClickHandler() {}
}), slides, /*#__PURE__*/React.createElement(CarouselControl, {
direction: "prev",
"data-testid": "prev",
directionText: "Previous",
onClickHandler: function onClickHandler() {}
}), /*#__PURE__*/React.createElement(CarouselControl, {
direction: "next",
"data-testid": "next",
directionText: "Next",
onClickHandler: function onClickHandler() {}
})));
expect(screen.getByTestId('carousel-indicator')).toBeInTheDocument();
expect(screen.getByTestId('prev')).toBeInTheDocument();
expect(screen.getByTestId('next')).toBeInTheDocument();
});
it('should not have the class "carousel-dark" by default', function () {
render( /*#__PURE__*/React.createElement(Carousel, {
"data-testid": "star-wars",
activeIndex: 0,
next: function next() {},
previous: function previous() {}
}, slides));
expect(screen.getByTestId('star-wars')).not.toHaveClass('carousel-dark');
});
it('should have the class "carousel-dark" when dark prop is true', function () {
render( /*#__PURE__*/React.createElement(Carousel, {
"data-testid": "star-wars",
dark: true,
activeIndex: 0,
next: function next() {},
previous: function previous() {}
}, slides));
expect(screen.getByTestId('star-wars')).toHaveClass('carousel-dark');
});
});
describe('carouseling', function () {
var carouselItems = [{
src: '',
altText: 'a',
caption: 'Grogu'
}, {
src: '',
altText: 'b',
caption: 'Boba Fett'
}, {
src: '',
altText: 'c',
caption: 'The Mandalorian'
}];
var carouselSlides = carouselItems.map(function (item, idx) {
return /*#__PURE__*/React.createElement(CarouselItem, {
key: idx
}, item.caption);
});
it('should set second slide to active if second indicator clicked', function () {
var _render4 = render( /*#__PURE__*/React.createElement(Carousel, {
activeIndex: 0,
next: function next() {},
previous: function previous() {}
}, /*#__PURE__*/React.createElement(CarouselIndicators, {
items: carouselItems,
"data-testid": "boba-fett",
activeIndex: 0,
onClickHandler: function onClickHandler() {
return function () {};
}
}), carouselSlides, /*#__PURE__*/React.createElement(CarouselControl, {
direction: "prev",
directionText: "Previous",
onClickHandler: function onClickHandler() {}
}), /*#__PURE__*/React.createElement(CarouselControl, {
direction: "next",
directionText: "Next",
onClickHandler: function onClickHandler() {}
}))),
rerender = _render4.rerender;
user.click(screen.getByLabelText(/boba fett/i));
rerender( /*#__PURE__*/React.createElement(Carousel, {
activeIndex: 1,
next: function next() {},
previous: function previous() {}
}, /*#__PURE__*/React.createElement(CarouselIndicators, {
items: carouselItems,
"data-testid": "boba-fett",
activeIndex: 1,
onClickHandler: function onClickHandler() {
return function () {};
}
}), carouselSlides, /*#__PURE__*/React.createElement(CarouselControl, {
direction: "prev",
directionText: "Previous",
onClickHandler: function onClickHandler() {}
}), /*#__PURE__*/React.createElement(CarouselControl, {
direction: "next",
directionText: "Next",
onClickHandler: function onClickHandler() {}
})));
expect(screen.getByText(/boba fett/i)).toHaveClass('carousel-item carousel-item-start carousel-item-next');
jest.advanceTimersByTime(DEFAULT_TIMER_TIME);
expect(screen.getByText(/boba fett/i)).toHaveClass('carousel-item active');
});
it('should go right when the index increases', function () {
var _render5 = render( /*#__PURE__*/React.createElement(Carousel, {
interval: 1000,
activeIndex: 0,
next: function next() {},
previous: function previous() {}
}, carouselSlides)),
rerender = _render5.rerender;
rerender( /*#__PURE__*/React.createElement(Carousel, {
interval: 1000,
activeIndex: 1,
next: function next() {},
previous: function previous() {}
}, carouselSlides));
expect(screen.getByText(/boba fett/i)).toHaveClass('carousel-item carousel-item-start carousel-item-next');
jest.advanceTimersByTime(DEFAULT_TIMER_TIME);
expect(screen.getByText(/boba fett/i)).toHaveClass('active');
});
it('should go left when the index decreases', function () {
var _render6 = render( /*#__PURE__*/React.createElement(Carousel, {
interval: 1000,
activeIndex: 1,
next: function next() {},
previous: function previous() {}
}, carouselSlides)),
rerender = _render6.rerender;
rerender( /*#__PURE__*/React.createElement(Carousel, {
interval: 1000,
activeIndex: 0,
next: function next() {},
previous: function previous() {}
}, carouselSlides));
expect(screen.getByText(/grogu/i)).toHaveClass('carousel-item carousel-item-prev carousel-item-end');
jest.advanceTimersByTime(DEFAULT_TIMER_TIME);
expect(screen.getByText(/grogu/i)).toHaveClass('active');
});
it('should go right if transitioning from the last to first slide by non-indicator', function () {
var _render7 = render( /*#__PURE__*/React.createElement(Carousel, {
interval: 1000,
activeIndex: 2,
next: function next() {},
previous: function previous() {}
}, carouselSlides)),
rerender = _render7.rerender;
rerender( /*#__PURE__*/React.createElement(Carousel, {
interval: 1000,
activeIndex: 0,
next: function next() {},
previous: function previous() {}
}, carouselSlides));
expect(screen.getByText(/grogu/i)).toHaveClass('carousel-item carousel-item-start carousel-item-next');
jest.advanceTimersByTime(DEFAULT_TIMER_TIME);
expect(screen.getByText(/grogu/i)).toHaveClass('active');
});
it('should go left if transitioning from the last to first slide by indicator', function () {
var _render8 = render( /*#__PURE__*/React.createElement(Carousel, {
interval: 1000,
activeIndex: 2,
next: function next() {},
previous: function previous() {}
}, /*#__PURE__*/React.createElement(CarouselIndicators, {
items: carouselItems,
activeIndex: 2,
onClickHandler: function onClickHandler() {}
}), carouselSlides, /*#__PURE__*/React.createElement(CarouselControl, {
direction: "prev",
directionText: "Previous",
onClickHandler: function onClickHandler() {}
}), /*#__PURE__*/React.createElement(CarouselControl, {
direction: "next",
directionText: "Next",
onClickHandler: function onClickHandler() {}
}))),
rerender = _render8.rerender;
user.click(screen.getByLabelText(/grogu/i));
rerender( /*#__PURE__*/React.createElement(Carousel, {
interval: 1000,
activeIndex: 0,
next: function next() {},
previous: function previous() {}
}, /*#__PURE__*/React.createElement(CarouselIndicators, {
items: carouselItems,
activeIndex: 0,
onClickHandler: function onClickHandler() {}
}), carouselSlides, /*#__PURE__*/React.createElement(CarouselControl, {
direction: "prev",
directionText: "Previous",
onClickHandler: function onClickHandler() {}
}), /*#__PURE__*/React.createElement(CarouselControl, {
direction: "next",
directionText: "Next",
onClickHandler: function onClickHandler() {}
})));
expect(screen.getByText(/grogu/i)).toHaveClass('carousel-item carousel-item-end carousel-item-prev');
});
it('should go left if transitioning from the first to last slide by non-indicator', function () {
var _render9 = render( /*#__PURE__*/React.createElement(Carousel, {
interval: 1000,
activeIndex: 0,
next: function next() {},
previous: function previous() {}
}, carouselSlides)),
rerender = _render9.rerender;
rerender( /*#__PURE__*/React.createElement(Carousel, {
interval: 1000,
activeIndex: 2,
next: function next() {},
previous: function previous() {}
}, carouselSlides));
expect(screen.getByText(/the mandalorian/i)).toHaveClass('carousel-item carousel-item-end carousel-item-prev');
jest.advanceTimersByTime(DEFAULT_TIMER_TIME);
expect(screen.getByText(/the mandalorian/i)).toHaveClass('active');
});
it('should go right if transitioning from the first to last slide by indicator', function () {
var _render10 = render( /*#__PURE__*/React.createElement(Carousel, {
interval: 1000,
activeIndex: 0,
next: function next() {},
previous: function previous() {}
}, /*#__PURE__*/React.createElement(CarouselIndicators, {
items: carouselItems,
activeIndex: 0,
onClickHandler: function onClickHandler() {}
}), carouselSlides, /*#__PURE__*/React.createElement(CarouselControl, {
direction: "prev",
directionText: "Previous",
onClickHandler: function onClickHandler() {}
}), /*#__PURE__*/React.createElement(CarouselControl, {
direction: "next",
directionText: "Next",
onClickHandler: function onClickHandler() {}
}))),
rerender = _render10.rerender;
user.click(screen.getByLabelText(/the mandalorian/i));
rerender( /*#__PURE__*/React.createElement(Carousel, {
interval: 1000,
activeIndex: 2,
next: function next() {},
previous: function previous() {}
}, /*#__PURE__*/React.createElement(CarouselIndicators, {
items: carouselItems,
activeIndex: 2,
onClickHandler: function onClickHandler() {}
}), carouselSlides, /*#__PURE__*/React.createElement(CarouselControl, {
direction: "prev",
directionText: "Previous",
onClickHandler: function onClickHandler() {}
}), /*#__PURE__*/React.createElement(CarouselControl, {
direction: "next",
directionText: "Next",
onClickHandler: function onClickHandler() {}
})));
expect(screen.getByText(/the mandalorian/i)).toHaveClass('carousel-item carousel-item-start carousel-item-next');
jest.advanceTimersByTime(DEFAULT_TIMER_TIME);
expect(screen.getByText(/the mandalorian/i)).toHaveClass('active');
});
});
describe('interval', function () {
it('should not autoplay by default', function () {
var next = jest.fn();
render( /*#__PURE__*/React.createElement(Carousel, {
next: next,
previous: function previous() {},
interval: 1000,
activeIndex: 0
}, slides));
jest.advanceTimersByTime(1000);
expect(next).not.toHaveBeenCalled();
});
it('should autoplay when ride is carousel', function () {
var next = jest.fn();
render( /*#__PURE__*/React.createElement(Carousel, {
next: next,
previous: function previous() {},
interval: 1000,
activeIndex: 0,
ride: "carousel"
}, slides));
jest.advanceTimersByTime(1000);
expect(next).toHaveBeenCalled();
});
it('should accept a number', function () {
var next = jest.fn();
render( /*#__PURE__*/React.createElement(Carousel, {
next: next,
previous: function previous() {},
interval: 1000,
activeIndex: 0,
ride: "carousel"
}, slides));
jest.advanceTimersByTime(1000);
expect(next).toHaveBeenCalled();
});
it('should accept a boolean', function () {
var next = jest.fn();
render( /*#__PURE__*/React.createElement(Carousel, {
next: next,
previous: function previous() {},
activeIndex: 0,
interval: false
}, slides));
jest.advanceTimersByTime(5000);
expect(next).not.toHaveBeenCalled();
});
it('should default to 5000', function () {
var next = jest.fn();
render( /*#__PURE__*/React.createElement(Carousel, {
next: next,
previous: function previous() {},
activeIndex: 0,
ride: "carousel"
}, slides));
jest.advanceTimersByTime(5000);
expect(next).toHaveBeenCalled();
});
it('it should accept a string', function () {
var next = jest.fn();
render( /*#__PURE__*/React.createElement(Carousel, {
next: next,
previous: function previous() {},
interval: "1000",
activeIndex: 0,
ride: "carousel"
}, slides));
jest.advanceTimersByTime(1000);
expect(next).toHaveBeenCalled();
});
});
});

View File

@@ -0,0 +1,52 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import user from '@testing-library/user-event';
import '@testing-library/jest-dom';
import CloseButton from '../CloseButton';
describe('CloseButton', function () {
it('should render a close button', function () {
render( /*#__PURE__*/React.createElement(CloseButton, {
"data-testid": "close-btn"
}));
expect(screen.getByTestId('close-btn')).toHaveClass('btn-close');
});
it('should render white variant', function () {
render( /*#__PURE__*/React.createElement(CloseButton, {
variant: "white",
"data-testid": "close-btn"
}));
expect(screen.getByTestId('close-btn')).toHaveClass('btn-close-white');
});
describe('onClick', function () {
it('calls props.onClick if it exists', function () {
var onClick = jest.fn();
render( /*#__PURE__*/React.createElement(CloseButton, {
onClick: onClick,
"data-testid": "btn-close"
}));
user.click(screen.getByTestId('btn-close'));
expect(onClick).toHaveBeenCalled();
});
it('returns the value returned by props.onClick', function () {
var onClick = jest.fn(function () {
return 1234;
});
render( /*#__PURE__*/React.createElement(CloseButton, {
onClick: onClick,
"data-testid": "btn-close"
}));
user.click(screen.getByTestId('btn-close'));
expect(onClick.mock.results[0].value).toBe(1234);
});
it('is not called when disabled', function () {
var onClick = jest.fn();
render( /*#__PURE__*/React.createElement(CloseButton, {
onClick: onClick,
disabled: true,
"data-testid": "btn-close"
}));
user.click(screen.getByTestId('btn-close'));
expect(onClick).not.toHaveBeenCalled();
});
});
});

122
node_modules/reactstrap/esm/__tests__/Col.spec.js generated vendored Normal file
View File

@@ -0,0 +1,122 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { Col } from '..';
describe('Col', function () {
it('should render default .col markup', function () {
render( /*#__PURE__*/React.createElement(Col, {
"data-testid": "col"
}));
expect(screen.getByTestId('col')).toHaveClass('col');
});
it('should render children', function () {
render( /*#__PURE__*/React.createElement(Col, {
"data-testid": "col"
}, "Children"));
expect(screen.getByText(/children/i)).toBeInTheDocument();
});
it('should pass additional classNames', function () {
render( /*#__PURE__*/React.createElement(Col, {
className: "extra",
"data-testid": "col"
}));
expect(screen.getByTestId('col')).toHaveClass('extra');
});
it('should allow custom columns to be defined', function () {
render( /*#__PURE__*/React.createElement(Col, {
widths: ['base', 'jumbo'],
base: "4",
jumbo: "6",
"data-testid": "col"
}));
expect(screen.getByTestId('col')).toHaveClass('col-4');
expect(screen.getByTestId('col')).toHaveClass('col-jumbo-6');
expect(screen.getByTestId('col')).not.toHaveClass('col');
});
it('should allow custom columns to be defined with objects', function () {
render( /*#__PURE__*/React.createElement(Col, {
widths: ['base', 'jumbo', 'spaceship'],
spaceship: {
size: 1,
order: 2,
offset: 4
},
"data-testid": "col"
}));
expect(screen.getByTestId('col')).toHaveClass('col-spaceship-1');
expect(screen.getByTestId('col')).toHaveClass('order-spaceship-2');
expect(screen.getByTestId('col')).toHaveClass('offset-spaceship-4');
expect(screen.getByTestId('col')).not.toHaveClass('col');
});
it('should pass col size specific classes as Strings', function () {
render( /*#__PURE__*/React.createElement(Col, {
sm: "6",
"data-testid": "col"
}));
expect(screen.getByTestId('col')).toHaveClass('col-sm-6');
expect(screen.getByTestId('col')).not.toHaveClass('col');
});
it('should pass col size specific classes as Numbers', function () {
render( /*#__PURE__*/React.createElement(Col, {
sm: 6,
"data-testid": "col"
}));
expect(screen.getByTestId('col')).toHaveClass('col-sm-6');
expect(screen.getByTestId('col')).not.toHaveClass('col');
});
it('should pass col size as flex with values "auto" or without value', function () {
render( /*#__PURE__*/React.createElement(Col, {
xs: "auto",
sm: true,
"data-testid": "col"
}));
expect(screen.getByTestId('col')).not.toHaveClass('col');
expect(screen.getByTestId('col')).toHaveClass('col-auto');
expect(screen.getByTestId('col')).toHaveClass('col-sm');
});
it('should pass col size specific classes via Objects', function () {
render( /*#__PURE__*/React.createElement(Col, {
sm: {
size: 6,
order: 2,
offset: 2
},
"data-testid": "col"
}));
expect(screen.getByTestId('col')).not.toHaveClass('col');
expect(screen.getByTestId('col')).toHaveClass('col-sm-6');
expect(screen.getByTestId('col')).toHaveClass('order-sm-2');
expect(screen.getByTestId('col')).toHaveClass('offset-sm-2');
});
it('should pass col size specific classes via Objects including 0', function () {
render( /*#__PURE__*/React.createElement(Col, {
sm: {
size: 6,
order: 0,
offset: 0
},
"data-testid": "col"
}));
expect(screen.getByTestId('col')).not.toHaveClass('col');
expect(screen.getByTestId('col')).toHaveClass('col-sm-6');
expect(screen.getByTestId('col')).toHaveClass('order-sm-0');
expect(screen.getByTestId('col')).toHaveClass('offset-sm-0');
});
it('should pass col size when passing via object with size "auto"', function () {
render( /*#__PURE__*/React.createElement(Col, {
sm: {
size: 'auto',
offset: 2
},
"data-testid": "col"
}));
expect(screen.getByTestId('col')).toHaveClass('col-sm-auto');
expect(screen.getByTestId('col')).not.toHaveClass('col');
});
it('should render custom tag', function () {
render( /*#__PURE__*/React.createElement(Col, {
tag: "main"
}, "Yo!"));
expect(screen.getByText(/yo!/i).tagName.toLowerCase()).toBe('main');
});
});

139
node_modules/reactstrap/esm/__tests__/Collapse.spec.js generated vendored Normal file
View File

@@ -0,0 +1,139 @@
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { Collapse } from '..';
describe('Collapse', function () {
beforeEach(function () {
jest.useFakeTimers();
});
afterEach(function () {
jest.clearAllTimers();
});
it('should render children', function () {
render( /*#__PURE__*/React.createElement(Collapse, null, "Hello"));
expect(screen.getByText(/hello/i)).toBeInTheDocument();
});
it('works with strict mode', function () {
var spy = jest.spyOn(console, 'error');
render( /*#__PURE__*/React.createElement(React.StrictMode, null, /*#__PURE__*/React.createElement(Collapse, null)));
expect(spy).not.toHaveBeenCalled();
});
it('should have default isOpen value as false', function () {
render( /*#__PURE__*/React.createElement(Collapse, null, "Hello"));
expect(screen.getByText(/hello/i)).not.toHaveClass('show');
});
it('should render with class "collapse"', function () {
render( /*#__PURE__*/React.createElement(Collapse, null, "Hello"));
expect(screen.getByText(/hello/i)).toHaveClass('collapse');
});
it('should render with class "collapse-horizontal" if it has prop horizontal', function () {
render( /*#__PURE__*/React.createElement(Collapse, {
horizontal: true
}, "Hello"));
expect(screen.getByText(/hello/i)).toHaveClass('collapse-horizontal');
});
it('should render with class "navbar-collapse" if it has prop navbar', function () {
render( /*#__PURE__*/React.createElement(Collapse, {
navbar: true
}, "Hello"));
expect(screen.getByText(/hello/i)).toHaveClass('navbar-collapse');
});
it('should render with class "show" when isOpen is true', function () {
render( /*#__PURE__*/React.createElement(Collapse, {
isOpen: true
}, "Hello"));
expect(screen.getByText(/hello/i)).toHaveClass('show');
});
it('should set height to null when isOpen is true', function () {
render( /*#__PURE__*/React.createElement(Collapse, {
isOpen: true,
"data-testid": "collapse"
}));
expect(screen.getByTestId('collapse').style.height).toBe('');
});
it('should not set height when isOpen is false', function () {
render( /*#__PURE__*/React.createElement(Collapse, {
isOpen: false,
"data-testid": "collapse"
}));
expect(screen.getByTestId('collapse').style.height).toBe('');
});
it('should forward all styles', function () {
render( /*#__PURE__*/React.createElement(Collapse, {
isOpen: false,
"data-testid": "collapse",
style: {
backgroundColor: 'black'
}
}));
expect(screen.getByTestId('collapse').style.backgroundColor).toBe('black');
});
it('should forward all callbacks', function () {
var callbacks = {
onEnter: jest.fn(),
onEntering: jest.fn(),
onEntered: jest.fn(),
onExit: jest.fn(),
onExiting: jest.fn(),
onExited: jest.fn()
};
var _render = render( /*#__PURE__*/React.createElement(Collapse, _extends({
isOpen: false
}, callbacks))),
rerender = _render.rerender;
rerender( /*#__PURE__*/React.createElement(Collapse, _extends({
isOpen: true
}, callbacks)));
expect(callbacks.onEnter).toHaveBeenCalled();
expect(callbacks.onEntering).toHaveBeenCalled();
expect(callbacks.onEntered).not.toHaveBeenCalled();
jest.advanceTimersByTime(350);
expect(callbacks.onEntered).toHaveBeenCalled();
expect(callbacks.onExit).not.toHaveBeenCalled();
rerender( /*#__PURE__*/React.createElement(Collapse, _extends({
isOpen: false
}, callbacks)));
expect(callbacks.onExit).toHaveBeenCalled();
expect(callbacks.onExiting).toHaveBeenCalled();
expect(callbacks.onExited).not.toHaveBeenCalled();
jest.advanceTimersByTime(350);
expect(callbacks.onExiting).toHaveBeenCalled();
expect(callbacks.onExited).toHaveBeenCalled();
});
it('should apply correct bootstrap classes', function () {
var _render2 = render( /*#__PURE__*/React.createElement(Collapse, {
isOpen: false,
"data-testid": "collapse"
})),
rerender = _render2.rerender;
rerender( /*#__PURE__*/React.createElement(Collapse, {
isOpen: true,
"data-testid": "collapse"
}));
expect(screen.getByTestId('collapse')).toHaveClass('collapsing');
jest.advanceTimersByTime(350);
expect(screen.getByTestId('collapse')).toHaveClass('collapse show');
rerender( /*#__PURE__*/React.createElement(Collapse, {
isOpen: false,
"data-testid": "collapse"
}));
expect(screen.getByTestId('collapse')).toHaveClass('collapsing');
jest.advanceTimersByTime(350);
expect(screen.getByTestId('collapse')).toHaveClass('collapse');
});
it('should set inline style to 0 when isOpen change to false and remove after transition', function () {
var _render3 = render( /*#__PURE__*/React.createElement(Collapse, {
isOpen: true,
"data-testid": "collapse"
})),
rerender = _render3.rerender;
rerender( /*#__PURE__*/React.createElement(Collapse, {
isOpen: false,
"data-testid": "collapse"
}));
expect(screen.getByTestId('collapse').style.height).toBe('0px');
jest.advanceTimersByTime(380);
expect(screen.getByTestId('collapse').style.height).toBe('');
});
});

View File

@@ -0,0 +1,37 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { Container } from '..';
import { testForChildrenInComponent, testForCustomClass, testForCustomTag } from '../testUtils';
describe('Container', function () {
it('should render .container markup', function () {
render( /*#__PURE__*/React.createElement(Container, {
"data-testid": "container"
}));
expect(screen.getByTestId('container')).toHaveClass('container');
});
it('should render .container-fluid markup', function () {
render( /*#__PURE__*/React.createElement(Container, {
fluid: true,
"data-testid": "container"
}));
expect(screen.getByTestId('container')).toHaveClass('container-fluid');
});
it('should render children', function () {
testForChildrenInComponent(Container);
});
it('should pass additional classNames', function () {
testForCustomClass(Container);
});
it('should render custom tag', function () {
testForCustomTag(Container);
});
it('should render responsive breakpoints with string fluid props', function () {
render( /*#__PURE__*/React.createElement(Container, {
fluid: "md",
"data-testid": "container"
}));
expect(screen.getByTestId('container')).toHaveClass('container-md');
expect(screen.getByTestId('container')).not.toHaveClass('container-fluid');
});
});

982
node_modules/reactstrap/esm/__tests__/Dropdown.spec.js generated vendored Normal file

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,136 @@
function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
import React from 'react';
import user from '@testing-library/user-event';
import { render, screen } from '@testing-library/react';
import { DropdownItem } from '..';
import { testForChildrenInComponent, testForDefaultTag, customDropdownRender } from '../testUtils';
describe('DropdownItem', function () {
it('should render a single child', function () {
testForChildrenInComponent(DropdownItem);
});
it('should render type as "button" by default', function () {
testForDefaultTag(DropdownItem, 'button');
});
it('should not render type when tag is "button" and toggle is false', function () {
render( /*#__PURE__*/React.createElement(DropdownItem, {
toggle: false
}, "Home"));
expect(screen.getByText('Home')).not.toHaveAttribute('type');
});
it('should render type as user defined when defined by the user', function () {
render( /*#__PURE__*/React.createElement(DropdownItem, {
type: "submit"
}, "Home"));
expect(screen.getByText('Home')).toHaveAttribute('type', 'submit');
});
it('should not render type by default when the type is not defined and the tag is not "button"', function () {
render( /*#__PURE__*/React.createElement(DropdownItem, {
tag: "a"
}, "Home"));
expect(screen.getByText('Home')).not.toHaveAttribute('type');
});
it('should render custom element', function () {
function Link(props) {
return /*#__PURE__*/React.createElement("a", _extends({
href: "/home"
}, props), props.children);
}
render( /*#__PURE__*/React.createElement(DropdownItem, {
tag: Link
}, "Home"));
expect(screen.getByText('Home')).toHaveAttribute('href', '/home');
expect(screen.getByText('Home').tagName.toLowerCase()).toMatch('a');
});
it('should render dropdown item text', function () {
render( /*#__PURE__*/React.createElement(DropdownItem, {
text: true
}, "text"));
expect(screen.getByText('text')).toHaveClass('dropdown-item-text');
expect(screen.getByText('text').tagName.toLowerCase()).toMatch('span');
});
describe('header', function () {
it('should render h6 tag heading', function () {
render( /*#__PURE__*/React.createElement(DropdownItem, {
header: true
}, "Heading"));
expect(screen.getByText('Heading')).toHaveClass('dropdown-header');
expect(screen.getByText('Heading').tagName.toLowerCase()).toMatch('h6');
});
});
describe('active', function () {
it('should render an active class', function () {
render( /*#__PURE__*/React.createElement(DropdownItem, {
active: true,
"data-testid": "divider"
}));
expect(screen.getByTestId('divider')).toHaveClass('active');
});
});
describe('divider', function () {
it('should render a divider element', function () {
render( /*#__PURE__*/React.createElement(DropdownItem, {
divider: true,
"data-testid": "divider"
}));
expect(screen.getByTestId('divider')).toHaveClass('dropdown-divider');
});
});
describe('link (with href)', function () {
it('should render an anchor tag', function () {
render( /*#__PURE__*/React.createElement(DropdownItem, {
href: "#"
}, "GO!"));
expect(screen.getByText('GO!')).toHaveClass('dropdown-item');
expect(screen.getByText('GO!').tagName.toLowerCase()).toMatch('a');
});
});
describe('onClick', function () {
it('should not be called when disabled', function () {
var onClick = jest.fn();
render( /*#__PURE__*/React.createElement(DropdownItem, {
disabled: true,
onClick: onClick
}, "Item"));
user.click(screen.getByText('Item'));
expect(onClick).not.toHaveBeenCalled();
});
it('should not be called when divider is set', function () {
var onClick = jest.fn();
render( /*#__PURE__*/React.createElement(DropdownItem, {
divider: true,
onClick: onClick
}, "Item"));
user.click(screen.getByText('Item'));
expect(onClick).not.toHaveBeenCalled();
});
it('should not be called when header item', function () {
var onClick = jest.fn();
render( /*#__PURE__*/React.createElement(DropdownItem, {
header: true,
onClick: onClick
}, "Item"));
user.click(screen.getByText('Item'));
expect(onClick).not.toHaveBeenCalled();
});
it('should be called when not disabled, heading, or divider', function () {
var onClick = jest.fn();
customDropdownRender( /*#__PURE__*/React.createElement(DropdownItem, {
onClick: onClick
}, "Item"), {
toggle: function toggle() {}
});
user.click(screen.getByText(/item/i));
expect(onClick).toBeCalled();
});
it('should call toggle', function () {
var toggle = jest.fn();
customDropdownRender( /*#__PURE__*/React.createElement(DropdownItem, {
onClick: function onClick() {}
}, "Item"), {
toggle: toggle
});
user.click(screen.getByText(/item/i));
expect(toggle).toHaveBeenCalled();
});
});
});

View File

@@ -0,0 +1,150 @@
import React from 'react';
import { screen } from '@testing-library/react';
import { Popper } from 'react-popper';
import '@testing-library/jest-dom';
import { DropdownMenu } from '..';
import { customDropdownRender } from '../testUtils';
describe('DropdownMenu', function () {
var contextProps = {
isOpen: false,
direction: 'down',
inNavbar: false
};
beforeEach(function () {
contextProps.isOpen = false;
contextProps.direction = 'down';
contextProps.inNavbar = false;
Popper.mockClear();
});
it('should render children', function () {
customDropdownRender( /*#__PURE__*/React.createElement(DropdownMenu, null, "Content"), contextProps);
expect(screen.getByText(/content/i)).toBeInTheDocument();
});
it('should not have the class "show" when isOpen context is false', function () {
customDropdownRender( /*#__PURE__*/React.createElement(DropdownMenu, null, "Content"), contextProps);
expect(screen.getByText(/content/i)).not.toHaveClass('show');
});
it('should have the class "show" when isOpen context is true', function () {
contextProps.isOpen = true;
customDropdownRender( /*#__PURE__*/React.createElement(DropdownMenu, null, "Content"), contextProps);
expect(screen.getByText(/content/i)).toHaveClass('show');
});
it('should render left aligned menus by default', function () {
contextProps.isOpen = true;
customDropdownRender( /*#__PURE__*/React.createElement(DropdownMenu, null, "Ello world"), contextProps);
expect(screen.getByText(/ello world/i)).not.toHaveClass('dropdown-menu-end');
});
it('should render right aligned menus', function () {
contextProps.isOpen = true;
customDropdownRender( /*#__PURE__*/React.createElement(DropdownMenu, {
end: true
}, "Ello world"), contextProps);
expect(screen.getByText(/ello world/i)).toHaveClass('dropdown-menu-end');
});
it('should render down when direction is unknown on the context', function () {
contextProps.isOpen = true;
contextProps.direction = 'unknown';
customDropdownRender( /*#__PURE__*/React.createElement(DropdownMenu, null, "Ello world"), contextProps);
expect(screen.getByText(/ello world/i)).toHaveAttribute('data-popper-placement', 'bottom-start');
});
it('should render down when direction is "down" on the context', function () {
contextProps.isOpen = true;
customDropdownRender( /*#__PURE__*/React.createElement(DropdownMenu, null, "Ello world"), contextProps);
expect(screen.getByText(/ello world/i)).toHaveAttribute('data-popper-placement', 'bottom-start');
});
it('should render up when direction is "up" on the context', function () {
contextProps.isOpen = true;
contextProps.direction = 'up';
customDropdownRender( /*#__PURE__*/React.createElement(DropdownMenu, null, "Ello world"), contextProps);
expect(screen.getByText(/ello world/i)).toHaveAttribute('data-popper-placement', 'top-start');
// expect(wrapper.find(Popper).prop('placement')).toBe('top-start');
});
it('should render left when direction is "start" on the context', function () {
contextProps.isOpen = true;
contextProps.direction = 'start';
customDropdownRender( /*#__PURE__*/React.createElement(DropdownMenu, null, "Ello world"), contextProps);
expect(screen.getByText(/ello world/i)).toHaveAttribute('data-popper-placement', 'left-start');
// expect(wrapper.find(Popper).prop('placement')).toBe('left-start');
});
it('should render right when direction is "end" on the context', function () {
contextProps.isOpen = true;
contextProps.direction = 'end';
customDropdownRender( /*#__PURE__*/React.createElement(DropdownMenu, null, "Ello world"), contextProps);
expect(screen.getByText(/ello world/i)).toHaveAttribute('data-popper-placement', 'right-start');
// expect(wrapper.find(Popper).prop('placement')).toBe('right-start');
});
it('should not disable flip modifier by default', function () {
contextProps.isOpen = true;
customDropdownRender( /*#__PURE__*/React.createElement(DropdownMenu, null, "Ello world"), contextProps);
expect(Popper.mock.calls[0][0].modifiers[0]).toMatchObject({
name: 'flip',
enabled: true
});
});
it('should disable flip modifier when flip is false', function () {
contextProps.isOpen = true;
customDropdownRender( /*#__PURE__*/React.createElement(DropdownMenu, {
flip: false
}, "Ello world"), contextProps);
expect(Popper.mock.calls.length).toBe(1);
expect(Popper.mock.calls[0][0].modifiers[0]).toMatchObject({
name: 'flip',
enabled: false
});
});
it('should position using fixed mode', function () {
contextProps.isOpen = true;
customDropdownRender( /*#__PURE__*/React.createElement(DropdownMenu, {
strategy: "fixed"
}, "Ello world"), contextProps);
expect(Popper.mock.calls[0][0].strategy).toBe('fixed');
});
it('should not render Popper when isOpen is false', function () {
customDropdownRender( /*#__PURE__*/React.createElement(DropdownMenu, {
end: true
}, "Ello world"), contextProps);
expect(Popper).not.toBeCalled();
});
it('should render custom tag', function () {
contextProps.isOpen = true;
customDropdownRender( /*#__PURE__*/React.createElement(DropdownMenu, {
tag: "main"
}, "Yo!"), contextProps);
expect(screen.getByText(/yo/i).tagName).toBe('MAIN');
});
describe('using container', function () {
var element;
beforeEach(function () {
element = document.createElement('div');
document.body.appendChild(element);
});
afterEach(function () {
document.body.removeChild(element);
element = null;
});
it('should render inside container', function () {
contextProps.isOpen = true;
element.innerHTML = '<div id="anotherContainer"></div>';
customDropdownRender( /*#__PURE__*/React.createElement(DropdownMenu, {
container: "#anotherContainer"
}, "My body"), contextProps);
expect(document.getElementById('anotherContainer').innerHTML).toContain('My body');
});
});
it('should not have the class "dropdown-menu-dark" by default', function () {
contextProps.isOpen = true;
customDropdownRender( /*#__PURE__*/React.createElement(DropdownMenu, null, "Keep it light"), contextProps);
expect(screen.getByText(/keep it light/i)).not.toHaveClass('dropdown-menu-dark');
});
it('should have the class "dropdown-menu-dark" when dark is true', function () {
contextProps.isOpen = true;
customDropdownRender( /*#__PURE__*/React.createElement(DropdownMenu, {
dark: true,
"data-testid": "dark-menu"
}, "Let's go dark"), contextProps);
expect(screen.getByTestId('dark-menu')).toHaveClass('dropdown-menu-dark');
});
});

View File

@@ -0,0 +1,127 @@
import React from 'react';
import { createEvent, fireEvent, screen } from '@testing-library/react';
import user from '@testing-library/user-event';
import { DropdownToggle } from '..';
import { customDropdownRender } from '../testUtils';
describe('DropdownToggle', function () {
var contextProps = {
isOpen: false,
direction: 'down',
inNavbar: false,
toggle: jest.fn()
};
beforeEach(function () {
contextProps.isOpen = false;
contextProps.direction = 'down';
contextProps.inNavbar = false;
contextProps.toggle.mockClear();
});
it('should wrap text', function () {
customDropdownRender( /*#__PURE__*/React.createElement(DropdownToggle, null, "Ello world"), contextProps);
expect(screen.getByText(/ello world/i)).toBeInTheDocument();
});
it('should add default visually-hidden content', function () {
customDropdownRender( /*#__PURE__*/React.createElement(DropdownToggle, null), contextProps);
expect(screen.getByText(/toggle dropdown/i)).toHaveClass('visually-hidden');
});
it('should add default visually-hidden content', function () {
customDropdownRender( /*#__PURE__*/React.createElement(DropdownToggle, {
"aria-label": "Dropup Toggle"
}), contextProps);
expect(screen.getByText(/dropup toggle/i)).toHaveClass('visually-hidden');
});
it('should render elements', function () {
customDropdownRender( /*#__PURE__*/React.createElement(DropdownToggle, null, "Click Me"), contextProps);
expect(screen.getByText(/click me/i).tagName).toBe('BUTTON');
});
it('should render a caret', function () {
customDropdownRender( /*#__PURE__*/React.createElement(DropdownToggle, {
caret: true
}, "Ello world"), contextProps);
expect(screen.getByText(/ello world/i)).toHaveClass('dropdown-toggle');
});
describe('color', function () {
it('should render the dropdown as a BUTTON element with default color secondary', function () {
customDropdownRender( /*#__PURE__*/React.createElement(DropdownToggle, {
"data-testid": "rick"
}), contextProps);
expect(screen.getByTestId(/rick/i)).toHaveClass('btn-secondary');
});
it('should render the dropdown as a BUTTON element with explicit color success', function () {
customDropdownRender( /*#__PURE__*/React.createElement(DropdownToggle, {
color: "success",
"data-testid": "morty"
}), contextProps);
expect(screen.getByTestId(/morty/i)).toHaveClass('btn-success');
});
it('should render the dropdown as an A element with no color attribute', function () {
customDropdownRender( /*#__PURE__*/React.createElement(DropdownToggle, {
tag: "a",
"data-testid": "pickle-rick"
}), contextProps);
expect(screen.getByTestId(/pickle-rick/i).tagName).toBe('A');
expect(screen.getByTestId(/pickle-rick/i)).not.toHaveAttribute('color');
});
it('should render the dropdown as a DIV element with no color attribute', function () {
customDropdownRender( /*#__PURE__*/React.createElement(DropdownToggle, {
tag: "div",
color: "success",
"data-testid": "tiny-rick"
}), contextProps);
expect(screen.getByTestId(/tiny-rick/i).tagName).toBe('DIV');
expect(screen.getByTestId(/tiny-rick/i)).not.toHaveAttribute('color');
});
});
it('should render a split', function () {
customDropdownRender( /*#__PURE__*/React.createElement(DropdownToggle, {
split: true
}, "Ello world"), contextProps);
expect(screen.getByText(/ello world/i)).toHaveClass('dropdown-toggle-split');
});
describe('onClick', function () {
it('should call props.onClick if it exists', function () {
var onClick = jest.fn();
customDropdownRender( /*#__PURE__*/React.createElement(DropdownToggle, {
onClick: onClick
}, "Ello world"), contextProps);
user.click(screen.getByText(/ello world/i));
expect(onClick).toHaveBeenCalledTimes(1);
});
it('should call context.toggle when present ', function () {
contextProps.toggle = jest.fn();
var _customDropdownRender = customDropdownRender( /*#__PURE__*/React.createElement(DropdownToggle, null, "Ello world"), contextProps),
container = _customDropdownRender.container;
user.click(screen.getByText(/ello world/i));
expect(contextProps.toggle).toHaveBeenCalledTimes(1);
});
});
describe('disabled', function () {
it('should not call onClick when disabled', function () {
var onClick = jest.fn();
customDropdownRender( /*#__PURE__*/React.createElement(DropdownToggle, {
disabled: true,
onClick: onClick
}, "Ello world"), contextProps);
user.click(screen.getByText(/ello world/i));
expect(onClick).not.toBeCalled();
});
});
describe('nav', function () {
it('should add .nav-link class', function () {
customDropdownRender( /*#__PURE__*/React.createElement(DropdownToggle, {
nav: true
}, "Ello world"), contextProps);
expect(screen.getByText(/ello world/i)).toHaveClass('nav-link');
expect(screen.getByText(/ello world/i).tagName).toBe('A');
});
it('should preventDefault', function () {
customDropdownRender( /*#__PURE__*/React.createElement(DropdownToggle, {
nav: true
}, "Ello world"), contextProps);
var node = screen.getByText(/ello world/i);
var click = createEvent.click(node);
fireEvent(node, click);
expect(click.defaultPrevented).toBeTruthy();
});
});
});

126
node_modules/reactstrap/esm/__tests__/Fade.spec.js generated vendored Normal file
View File

@@ -0,0 +1,126 @@
function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
import React from 'react';
import { render, screen } from '@testing-library/react';
import user from '@testing-library/user-event';
import { TransitionGroup } from 'react-transition-group';
import { Fade } from '..';
import { testForCustomTag } from '../testUtils';
var Helper = /*#__PURE__*/function (_React$Component) {
_inherits(Helper, _React$Component);
var _super = _createSuper(Helper);
function Helper(props) {
var _this;
_classCallCheck(this, Helper);
_this = _super.call(this, props);
_this.toggle = _this.toggle.bind(_assertThisInitialized(_this));
_this.state = {
showItem: props.showItem
};
return _this;
}
_createClass(Helper, [{
key: "toggle",
value: function toggle() {
this.setState(function (prevState) {
return {
showItem: !prevState.showItem
};
});
}
}, {
key: "render",
value: function render() {
return /*#__PURE__*/React.createElement("div", null, /*#__PURE__*/React.createElement("div", {
className: "trigger",
onClick: this.toggle
}, "Toggle"), /*#__PURE__*/React.createElement(TransitionGroup, {
component: "div"
}, this.state.showItem ? this.props.children : null));
}
}]);
return Helper;
}(React.Component);
describe('Fade', function () {
beforeEach(function () {
jest.useFakeTimers();
});
afterEach(function () {
jest.clearAllTimers();
});
it('should transition classes from "fade" to "fade show" on appear', function () {
render( /*#__PURE__*/React.createElement(Helper, {
showItem: true
}, /*#__PURE__*/React.createElement(Fade, null, "Yo!"), /*#__PURE__*/React.createElement(Fade, {
appear: false
}, "Yo 2!")));
expect(screen.getByText('Yo!')).toHaveClass('fade');
expect(screen.getByText('Yo!')).not.toHaveClass('show');
expect(screen.getByText('Yo 2!')).toHaveClass('fade');
expect(screen.getByText('Yo 2!')).toHaveClass('show');
jest.advanceTimersByTime(300);
expect(screen.getByText('Yo!')).toHaveClass('fade');
expect(screen.getByText('Yo!')).toHaveClass('show');
expect(screen.getByText('Yo 2!')).toHaveClass('fade');
expect(screen.getByText('Yo 2!')).toHaveClass('show');
user.click(document.getElementsByClassName('trigger')[0]);
expect(screen.getByText('Yo!')).toHaveClass('fade');
expect(screen.getByText('Yo!')).not.toHaveClass('show');
expect(screen.getByText('Yo 2!')).toHaveClass('fade');
expect(screen.getByText('Yo 2!')).not.toHaveClass('show');
});
it('should transition classes from "fade" to "fade show" on enter', function () {
var onEnter = jest.fn();
var onExit = jest.fn();
render( /*#__PURE__*/React.createElement(Helper, {
showItem: false
}, /*#__PURE__*/React.createElement(Fade, {
onEnter: onEnter,
onExit: onExit,
key: Math.random()
}, "Yo 3!"), /*#__PURE__*/React.createElement(Fade, {
appear: false,
enter: false,
exit: false,
key: Math.random()
}, "Yo 4!")));
expect(document.getElementsByClassName('fade').length).toBe(0);
expect(document.getElementsByClassName('fade show').length).toBe(0);
user.click(document.getElementsByClassName('trigger')[0]);
expect(onEnter).toHaveBeenCalled();
expect(onExit).not.toHaveBeenCalled();
expect(document.getElementsByClassName('fade').length).toBe(2);
expect(document.getElementsByClassName('fade show').length).toBe(1);
jest.advanceTimersByTime(300);
expect(onEnter).toHaveBeenCalled();
expect(onExit).not.toHaveBeenCalled();
expect(document.getElementsByClassName('fade show').length).toBe(2);
user.click(document.getElementsByClassName('trigger')[0]);
expect(onExit).toHaveBeenCalled();
expect(document.getElementsByClassName('fade show').length).toBe(0);
});
it('should pass className down', function () {
render( /*#__PURE__*/React.createElement(Fade, {
className: "test-class-name"
}, "Yo!"));
expect(screen.getByText(/yo/i)).toHaveClass('test-class-name');
});
it('should pass other props down', function () {
render( /*#__PURE__*/React.createElement(Fade, {
"data-testprop": "testvalue"
}, "Yo"));
expect(screen.getByText(/yo/i)).toHaveAttribute('data-testprop', 'testvalue');
});
it('should support custom tag', function () {
testForCustomTag(Fade);
});
});

16
node_modules/reactstrap/esm/__tests__/Form.spec.js generated vendored Normal file
View File

@@ -0,0 +1,16 @@
import { Form } from '..';
import { testForChildrenInComponent, testForCustomClass, testForCustomTag, testForDefaultTag } from '../testUtils';
describe('Form', function () {
it('should render with "form" tag', function () {
testForDefaultTag(Form, 'form');
});
it('should render children', function () {
testForChildrenInComponent(Form);
});
it('should render additional classes', function () {
testForCustomClass(Form);
});
it('should render custom tag', function () {
testForCustomTag(Form);
});
});

View File

@@ -0,0 +1,34 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { FormFeedback } from '..';
import { testForChildrenInComponent, testForCustomClass, testForCustomTag, testForDefaultClass, testForDefaultTag } from '../testUtils';
describe('FormFeedback', function () {
it('should render with "div" tag by default', function () {
testForDefaultTag(FormFeedback, 'div');
});
it('should render children', function () {
testForChildrenInComponent(FormFeedback);
});
it('should render with "invalid-feedback" class', function () {
testForDefaultClass(FormFeedback, 'invalid-feedback');
});
it('should render with "valid-feedback" class', function () {
render( /*#__PURE__*/React.createElement(FormFeedback, {
valid: true
}, "Yo!"));
expect(screen.getByText(/yo/i)).toHaveClass('valid-feedback');
});
it('should render with "valid-tooltip" class', function () {
render( /*#__PURE__*/React.createElement(FormFeedback, {
valid: true,
tooltip: true
}, "Yo!"));
expect(screen.getByText(/yo/i)).toHaveClass('valid-tooltip');
});
it('should render additional classes', function () {
testForCustomClass(FormFeedback);
});
it('should render custom tag', function () {
testForCustomTag(FormFeedback);
});
});

135
node_modules/reactstrap/esm/__tests__/FormGroup.spec.js generated vendored Normal file
View File

@@ -0,0 +1,135 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { FormGroup } from '..';
import { testForChildrenInComponent, testForCustomClass, testForCustomTag, testForDefaultClass, testForDefaultTag } from '../testUtils';
describe('FormGroup', function () {
it('should render with "div" tag by default', function () {
testForDefaultTag(FormGroup, 'div');
});
it('should render children', function () {
testForChildrenInComponent(FormGroup);
});
it('should render with "mb-3" class by default', function () {
testForDefaultClass(FormGroup, 'mb-3');
});
it('should not render with "form-check" nor "form-check-inline" class by default', function () {
render( /*#__PURE__*/React.createElement(FormGroup, null, "Yo!"));
expect(screen.getByText('Yo!')).not.toHaveClass('form-check');
expect(screen.getByText('Yo!')).not.toHaveClass('form-check-inline');
});
it('should render with "form-check" class when check prop is truthy', function () {
render( /*#__PURE__*/React.createElement(FormGroup, {
check: true
}, "Yo!"));
expect(screen.getByText('Yo!')).toHaveClass('form-check');
});
it('should render with "form-check" and "form-switch" class when switch prop is truthy', function () {
render( /*#__PURE__*/React.createElement(FormGroup, {
"switch": true
}, "Yo!"));
expect(screen.getByText('Yo!')).toHaveClass('form-check');
expect(screen.getByText('Yo!')).toHaveClass('form-switch');
});
it('should not render with "form-check-inline" class when check prop is truthy and inline prop is falsy', function () {
render( /*#__PURE__*/React.createElement(FormGroup, {
check: true
}, "Yo!"));
expect(screen.getByText('Yo!')).not.toHaveClass('form-check-inline');
});
it('should not render with "form-check-inline" class when switch prop is truthy and inline prop is falsy', function () {
render( /*#__PURE__*/React.createElement(FormGroup, {
"switch": true
}, "Yo!"));
expect(screen.getByText('Yo!')).not.toHaveClass('form-check-inline');
});
it('should render with "form-check" and "form-check-inline" classes when check prop and inline prop are both truthy', function () {
render( /*#__PURE__*/React.createElement(FormGroup, {
check: true,
inline: true
}, "Yo!"));
expect(screen.getByText('Yo!')).toHaveClass('form-check');
expect(screen.getByText('Yo!')).toHaveClass('form-check-inline');
});
it('should render with "form-check" and "form-switch" and "form-check-inline" classes when check prop and inline prop are both truthy', function () {
render( /*#__PURE__*/React.createElement(FormGroup, {
"switch": true,
inline: true
}, "Yo!"));
expect(screen.getByText('Yo!')).toHaveClass('form-check');
expect(screen.getByText('Yo!')).toHaveClass('form-switch');
expect(screen.getByText('Yo!')).toHaveClass('form-check-inline');
});
it('should not render with "form-check-inline" class when check and switch prop are falsy and inline prop is truthy', function () {
render( /*#__PURE__*/React.createElement(FormGroup, {
inline: true
}, "Yo!"));
expect(screen.getByText('Yo!')).not.toHaveClass('form-check');
});
it('should not render with "mb-3" class when noMargin prop is truthy', function () {
render( /*#__PURE__*/React.createElement(FormGroup, {
noMargin: true
}, "Yo!"));
expect(screen.getByText('Yo!')).not.toHaveClass('mb-3');
});
it('should not render with "mb-3" class when check prop is truthy', function () {
render( /*#__PURE__*/React.createElement(FormGroup, {
check: true
}, "Yo!"));
expect(screen.getByText('Yo!')).not.toHaveClass('mb-3');
});
it('should not render with "mb-3" class when switch prop is truthy', function () {
render( /*#__PURE__*/React.createElement(FormGroup, {
"switch": true
}, "Yo!"));
expect(screen.getByText('Yo!')).not.toHaveClass('mb-3');
});
it('should not render with "disabled" class when disabled prop is truthy but check and switch are not', function () {
render( /*#__PURE__*/React.createElement(FormGroup, {
disabled: true
}, "Yo!"));
expect(screen.getByText('Yo!')).not.toHaveClass('disabled');
});
it('should render with "disabled" class when both check disabled props are truthy', function () {
render( /*#__PURE__*/React.createElement(FormGroup, {
check: true,
disabled: true
}, "Yo!"));
expect(screen.getByText('Yo!')).toHaveClass('disabled');
expect(screen.getByText('Yo!')).toHaveClass('form-check');
});
it('should render with "disabled" class when both switch and disabled props are truthy', function () {
render( /*#__PURE__*/React.createElement(FormGroup, {
"switch": true,
disabled: true
}, "Yo!"));
expect(screen.getByText('Yo!')).toHaveClass('disabled');
expect(screen.getByText('Yo!')).toHaveClass('form-check');
});
it('should render with "row" class when row prop is truthy', function () {
render( /*#__PURE__*/React.createElement(FormGroup, {
row: true
}, "Yo!"));
expect(screen.getByText('Yo!')).toHaveClass('row');
});
it('should not render with "row" class when row prop is not truthy', function () {
render( /*#__PURE__*/React.createElement(FormGroup, null, "Yo!"));
expect(screen.getByText('Yo!')).not.toHaveClass('row');
});
it('should render with "form-floating" class when floating prop is truthy', function () {
render( /*#__PURE__*/React.createElement(FormGroup, {
floating: true
}, "Yo!"));
expect(screen.getByText('Yo!')).toHaveClass('form-floating');
});
it('should not render with "form-floating" class when floating prop is falsey', function () {
render( /*#__PURE__*/React.createElement(FormGroup, null, "Yo!"));
expect(screen.getByText('Yo!')).not.toHaveClass('form-floating');
});
it('should render additional classes', function () {
testForCustomClass(FormGroup);
});
it('should render custom tag', function () {
testForCustomTag(FormGroup);
});
});

44
node_modules/reactstrap/esm/__tests__/FormText.spec.js generated vendored Normal file
View File

@@ -0,0 +1,44 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { FormText } from '..';
import { testForChildrenInComponent, testForCustomClass, testForCustomTag, testForDefaultClass, testForDefaultTag } from '../testUtils';
describe('FormText', function () {
it('should render with "form" tag', function () {
testForDefaultTag(FormText, 'small');
});
it('should render children', function () {
testForChildrenInComponent(FormText);
});
it('should render with "form-text" class when not inline', function () {
testForDefaultClass(FormText, 'form-text');
});
it('should not render with "form-text" class when inline', function () {
render( /*#__PURE__*/React.createElement(FormText, {
inline: true
}, "Yo!"));
expect(screen.getByText('Yo!')).not.toHaveClass('form-text');
});
it('should render with "text-muted" class by default', function () {
render( /*#__PURE__*/React.createElement(FormText, null, "Yo!"));
expect(screen.getByText('Yo!')).toHaveClass('text-muted');
});
it('should render without "text-*" class when color is and empty string', function () {
render( /*#__PURE__*/React.createElement(FormText, {
color: ""
}, "Yo!"));
expect(screen.getByText('Yo!')).not.toHaveClass('text-*');
});
it('should render with "text-${color}" class when color is provided', function () {
render( /*#__PURE__*/React.createElement(FormText, {
color: "yoyo"
}, "Yo!"));
expect(screen.getByText('Yo!')).toHaveClass('text-yoyo');
});
it('should render additional classes', function () {
testForCustomClass(FormText);
});
it('should render custom tag', function () {
testForCustomTag(FormText);
});
});

318
node_modules/reactstrap/esm/__tests__/Input.spec.js generated vendored Normal file
View File

@@ -0,0 +1,318 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { Input } from '..';
import { testForDefaultTag } from '../testUtils';
describe('Input', function () {
it('should render with "input" tag when no type is provided', function () {
testForDefaultTag(Input, 'input');
});
it('should render with "type" tag when type is "select"', function () {
var _render = render( /*#__PURE__*/React.createElement(Input, {
type: "select"
}, "Yo!")),
container = _render.container;
expect(container.querySelector('select')).toBeInTheDocument();
});
it('should render with "textarea" tag when type is "textarea"', function () {
render( /*#__PURE__*/React.createElement(Input, {
type: "textarea",
"data-testid": "input"
}));
expect(screen.getByTestId('input').tagName.toLowerCase()).toMatch('textarea');
});
it('should render with "input" tag when plaintext prop is truthy', function () {
render( /*#__PURE__*/React.createElement(Input, {
type: "select",
plaintext: true,
"data-testid": "input"
}));
expect(screen.getByTestId('input').tagName.toLowerCase()).toMatch('input');
});
it('should render with "form-control-plaintext" class when plaintext prop is truthy', function () {
render( /*#__PURE__*/React.createElement(Input, {
type: "select",
plaintext: true,
"data-testid": "input"
}));
expect(screen.getByTestId('input')).toHaveClass('form-control-plaintext');
});
it('should not render with "form-control" class when plaintext prop is truthy', function () {
render( /*#__PURE__*/React.createElement(Input, {
type: "select",
plaintext: true,
"data-testid": "input"
}));
expect(screen.getByTestId('input')).not.toHaveClass('form-control');
});
it('should render with custom tag when plaintext prop is truthy and tag is provided', function () {
render( /*#__PURE__*/React.createElement(Input, {
type: "select",
plaintext: true,
tag: "div",
"data-testid": "input"
}));
expect(screen.getByTestId('input').tagName.toLowerCase()).toMatch('div');
});
it('should render with custom tag when plaintext prop is not truthy and tag is provided', function () {
render( /*#__PURE__*/React.createElement(Input, {
tag: "div",
"data-testid": "input"
}));
expect(screen.getByTestId('input').tagName.toLowerCase()).toMatch('div');
});
it('should render with "input" tag when type is not a special case', function () {
render( /*#__PURE__*/React.createElement(Input, {
type: "email",
"data-testid": "input"
}));
expect(screen.getByTestId('input').tagName.toLowerCase()).toMatch('input');
});
it('should not render children', function () {
render( /*#__PURE__*/React.createElement(Input, null, "Yo!"));
expect(screen.queryByText('Yo!')).not.toBeInTheDocument();
});
it('should render without children when type is "textarea"', function () {
render( /*#__PURE__*/React.createElement(Input, {
type: "textarea"
}, "Yo!"));
expect(screen.queryByText('Yo!')).not.toBeInTheDocument();
});
it('should render children when type is select', function () {
render( /*#__PURE__*/React.createElement(Input, {
type: "select"
}, "Yo!"));
expect(screen.getByText('Yo!')).toBeInTheDocument();
});
it('should render children when tag is select', function () {
render( /*#__PURE__*/React.createElement(Input, {
tag: "select"
}, "Yo!"));
expect(screen.getByText('Yo!')).toBeInTheDocument();
});
it('should pass children when tag is a custom component', function () {
render( /*#__PURE__*/React.createElement(Input, {
tag: function tag(props) {
return props.children;
}
}, "Yo!"));
expect(screen.getByText('Yo!')).toBeInTheDocument();
});
it('should not render with "is-invalid" class when valid is false', function () {
render( /*#__PURE__*/React.createElement(Input, {
valid: false,
"data-testid": "input"
}));
expect(screen.getByTestId('input')).not.toHaveClass('is-invalid');
});
it('should not render with "is-valid" class when invalid is false', function () {
render( /*#__PURE__*/React.createElement(Input, {
invalid: false,
"data-testid": "input"
}));
expect(screen.getByTestId('input')).not.toHaveClass('is-valid');
});
it('should render with "is-invalid" class when invalid is true', function () {
render( /*#__PURE__*/React.createElement(Input, {
invalid: true,
"data-testid": "input"
}));
expect(screen.getByTestId('input')).toHaveClass('is-invalid');
});
it('should render with "is-valid" class when valid is true', function () {
render( /*#__PURE__*/React.createElement(Input, {
valid: true,
"data-testid": "input"
}));
expect(screen.getByTestId('input')).toHaveClass('is-valid');
});
it('should render with "form-control-${bsSize}" class when bsSize is "lg" or "sm"', function () {
render( /*#__PURE__*/React.createElement(Input, {
bsSize: "lg",
"data-testid": "input"
}));
expect(screen.getByTestId('input')).toHaveClass('form-control-lg');
});
it('should render with "form-select-${bsSize}" class when bsSize is "lg" or "sm" and type is select', function () {
render( /*#__PURE__*/React.createElement(Input, {
type: "select",
bsSize: "lg",
"data-testid": "input"
}));
expect(screen.getByTestId('input')).toHaveClass('form-select-lg');
});
it('should render with "form-control" class when size is nor "lg" nor "sm"', function () {
render( /*#__PURE__*/React.createElement(Input, {
bsSize: "5",
"data-testid": "input"
}));
expect(screen.getByTestId('input')).toHaveClass('form-control');
expect(screen.getByTestId('input')).not.toHaveClass('form-control-sm');
expect(screen.getByTestId('input')).not.toHaveClass('form-control-lg');
});
it('should render with "form-select" class when size is nor "lg" nor "sm" and type is select', function () {
render( /*#__PURE__*/React.createElement(Input, {
type: "select",
bsSize: "5",
"data-testid": "input"
}));
expect(screen.getByTestId('input')).toHaveClass('form-select');
expect(screen.getByTestId('input')).not.toHaveClass('form-select-sm form-select-lg');
});
it('should render with "form-control-${bsSize}" class when bsSize is provided', function () {
render( /*#__PURE__*/React.createElement(Input, {
bsSize: "sm",
"data-testid": "input"
}));
expect(screen.getByTestId('input')).toHaveClass('form-control-sm');
});
it('should render with "form-select-${bsSize}" class when bsSize is provided and type is select', function () {
render( /*#__PURE__*/React.createElement(Input, {
type: "select",
bsSize: "sm",
"data-testid": "input"
}));
expect(screen.getByTestId('input')).toHaveClass('form-select-sm');
});
it('should render with "form-control" class by default', function () {
render( /*#__PURE__*/React.createElement(Input, {
"data-testid": "input"
}));
expect(screen.getByTestId('input')).toHaveClass('form-control');
});
it('should not render with "form-control-plaintext" nor "form-check-input" class by default', function () {
render( /*#__PURE__*/React.createElement(Input, {
"data-testid": "input"
}));
expect(screen.getByTestId('input')).not.toHaveClass('form-control-plaintext');
expect(screen.getByTestId('input')).not.toHaveClass('form-check-input');
});
it('should not render with "form-control-plaintext" nor "form-check-input" class when type is file', function () {
render( /*#__PURE__*/React.createElement(Input, {
type: "file",
"data-testid": "input"
}));
expect(screen.getByTestId('input')).not.toHaveClass('form-control-plaintext');
expect(screen.getByTestId('input')).not.toHaveClass('form-check-input');
});
it('should not render with "form-control" nor "form-control-plaintext" nor "form-check-input" class when type is select', function () {
render( /*#__PURE__*/React.createElement(Input, {
type: "select",
"data-testid": "input"
}));
expect(screen.getByTestId('input')).not.toHaveClass('form-control');
expect(screen.getByTestId('input')).not.toHaveClass('form-control-plaintext');
expect(screen.getByTestId('input')).not.toHaveClass('form-check-input');
});
it('should not render with "form-control" nor "form-check-input" class when plaintext prop is truthy', function () {
render( /*#__PURE__*/React.createElement(Input, {
type: "file",
plaintext: true,
"data-testid": "input"
}));
expect(screen.getByTestId('input')).not.toHaveClass('form-control');
expect(screen.getByTestId('input')).not.toHaveClass('form-check-input');
});
it('should not render nor "form-control-plaintext" nor "form-control" class when type is radio', function () {
render( /*#__PURE__*/React.createElement(Input, {
type: "radio",
"data-testid": "input"
}));
expect(screen.getByTestId('input')).not.toHaveClass('form-control');
expect(screen.getByTestId('input')).not.toHaveClass('form-control-plaintext');
});
it('should not render nor "form-control-plaintext" nor "form-control" class when type is checkbox', function () {
render( /*#__PURE__*/React.createElement(Input, {
type: "checkbox",
"data-testid": "input"
}));
expect(screen.getByTestId('input')).not.toHaveClass('form-control');
expect(screen.getByTestId('input')).not.toHaveClass('form-control-plaintext');
});
it('should render with "form-check-input" class when type is checkbox', function () {
render( /*#__PURE__*/React.createElement(Input, {
type: "checkbox",
"data-testid": "input"
}));
expect(screen.getByTestId('input')).toHaveClass('form-check-input');
});
it('should render with "form-check-input" class when type is radio', function () {
render( /*#__PURE__*/React.createElement(Input, {
type: "radio",
"data-testid": "input"
}));
expect(screen.getByTestId('input')).toHaveClass('form-check-input');
});
it('should render with "form-check-input" class when type is switch', function () {
render( /*#__PURE__*/React.createElement(Input, {
type: "switch",
"data-testid": "input"
}));
expect(screen.getByTestId('input')).toHaveClass('form-check-input');
});
it('should not render with "form-check-input" nor "form-control" class when type is checkbox and addon is truthy', function () {
render( /*#__PURE__*/React.createElement(Input, {
addon: true,
type: "checkbox",
"data-testid": "input"
}));
expect(screen.getByTestId('input')).not.toHaveClass('form-check-input');
expect(screen.getByTestId('input')).not.toHaveClass('form-control');
});
it('should not render with "form-check-input" nor "form-control" class when type is radio and addon is truthy', function () {
render( /*#__PURE__*/React.createElement(Input, {
addon: true,
type: "radio",
"data-testid": "input"
}));
expect(screen.getByTestId('input')).not.toHaveClass('form-check-input');
expect(screen.getByTestId('input')).not.toHaveClass('form-control');
});
it('should render with "form-select" class when type is select', function () {
render( /*#__PURE__*/React.createElement(Input, {
type: "select",
"data-testid": "input"
}));
expect(screen.getByTestId('input')).toHaveClass('form-select');
});
it('should render with "form-control" class when type is file', function () {
render( /*#__PURE__*/React.createElement(Input, {
type: "file",
"data-testid": "input"
}));
expect(screen.getByTestId('input')).toHaveClass('form-control');
});
it('should render additional classes', function () {
render( /*#__PURE__*/React.createElement(Input, {
className: "other",
"data-testid": "input"
}));
expect(screen.getByTestId('input')).toHaveClass('other');
});
it('should render checkbox type when type is switch', function () {
render( /*#__PURE__*/React.createElement(Input, {
type: "switch",
"data-testid": "input"
}));
expect(screen.getByTestId('input')).toHaveAttribute('type', 'checkbox');
});
it('should render "select" and "textarea" without type property', function () {
render( /*#__PURE__*/React.createElement(Input, {
type: "select"
}, "Yo!"));
render( /*#__PURE__*/React.createElement(Input, {
type: "textarea",
"data-testid": "input"
}));
expect(screen.getByTestId('input')).not.toHaveAttribute('type');
expect(screen.getByText('Yo!')).not.toHaveAttribute('type');
});
it('should render with "form-range" not "form-control" class when type is range', function () {
render( /*#__PURE__*/React.createElement(Input, {
type: "range",
"data-testid": "input"
}));
expect(screen.getByTestId('input')).toHaveClass('form-range');
expect(screen.getByTestId('input')).not.toHaveClass('form-control');
});
});

View File

@@ -0,0 +1,55 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import user from '@testing-library/user-event';
import '@testing-library/jest-dom';
import { InputGroup, DropdownMenu, DropdownToggle, DropdownItem, Input } from '..';
import Dropdown from '../Dropdown';
import { testForChildrenInComponent, testForCustomClass, testForCustomTag, testForDefaultClass, testForDefaultTag } from '../testUtils';
describe('InputGroup', function () {
it('should render with "div" tag', function () {
testForDefaultTag(InputGroup, 'div');
});
it('should render children', function () {
testForChildrenInComponent(InputGroup);
});
it('should render with "input-group" class', function () {
testForDefaultClass(InputGroup, 'input-group');
});
it('should render with "input-group-${size}" class when size is passed', function () {
render( /*#__PURE__*/React.createElement(InputGroup, {
size: "whatever"
}, "Yo!"));
expect(screen.getByText(/yo!/i)).toHaveClass('input-group-whatever');
});
it('should render additional classes', function () {
testForCustomClass(InputGroup);
});
it('should render custom tag', function () {
testForCustomTag(InputGroup);
});
describe('When type="dropdown"', function () {
it('should render Dropdown', function () {
render( /*#__PURE__*/React.createElement(InputGroup, {
type: "dropdown",
"data-testid": "drpdwn"
}));
expect(screen.getByTestId('drpdwn')).toHaveClass('dropdown');
});
it('should call toggle when input is clicked', function () {
var toggle = jest.fn();
render( /*#__PURE__*/React.createElement(InputGroup, {
type: "dropdown",
isOpen: true,
toggle: toggle
}, /*#__PURE__*/React.createElement(Input, null), /*#__PURE__*/React.createElement(DropdownToggle, null, "Toggle"), /*#__PURE__*/React.createElement(DropdownMenu, {
right: true
}, /*#__PURE__*/React.createElement(DropdownItem, null, "Test"), /*#__PURE__*/React.createElement(DropdownItem, {
id: "divider",
divider: true
}))));
expect(toggle).not.toBeCalled();
user.click(document.querySelector('input.form-control'));
expect(toggle).toBeCalled();
});
});
});

View File

@@ -0,0 +1,16 @@
import { InputGroupText } from '..';
import { testForCustomClass, testForCustomTag, testForDefaultClass, testForDefaultTag } from '../testUtils';
describe('InputGroupText', function () {
it('should render with "input-group-text" class', function () {
testForDefaultClass(InputGroupText, 'input-group-text');
});
it('should render additional classes', function () {
testForCustomClass(InputGroupText);
});
it('should render with "span" tag by default', function () {
testForDefaultTag(InputGroupText, 'span');
});
it('should render custom tag', function () {
testForCustomTag(InputGroupText);
});
});

173
node_modules/reactstrap/esm/__tests__/Label.spec.js generated vendored Normal file
View File

@@ -0,0 +1,173 @@
import React from 'react';
import { screen, render } from '@testing-library/react';
import { Label } from '..';
import { testForDefaultTag, testForCustomClass, testForChildrenInComponent, testForCustomTag } from '../testUtils';
describe('Label', function () {
it('should render a label tag by default', function () {
testForDefaultTag(Label, 'label');
});
it('should render children', function () {
testForChildrenInComponent(Label);
});
it('should pass additional classNames', function () {
testForCustomClass(Label);
});
it('should render with "col-form-label" class when a col is provided', function () {
render( /*#__PURE__*/React.createElement(Label, {
sm: "6"
}, "Yo!"));
expect(screen.getByText(/yo/i)).toHaveClass('col-form-label');
});
it('should not render with "form-label" class when a col is provided', function () {
render( /*#__PURE__*/React.createElement(Label, {
sm: "6"
}, "Yo!"));
expect(screen.getByText(/yo!/i)).not.toHaveClass('form-label');
});
it('should render with "form-label" class when a col is not provided', function () {
render( /*#__PURE__*/React.createElement(Label, null, "Yo!"));
expect(screen.getByText(/yo!/i)).toHaveClass('form-label');
});
it('should render with "form-check-label" class when check is specified', function () {
render( /*#__PURE__*/React.createElement(Label, {
check: true
}, "Yo!"));
expect(screen.getByText(/yo!/i)).toHaveClass('form-check-label');
});
it('should not render with "form-label" class when check is specified', function () {
render( /*#__PURE__*/React.createElement(Label, {
check: true
}, "Yo!"));
expect(screen.getByText(/yo!/i)).not.toHaveClass('form-label');
});
it('should pass col size specific classes as Strings', function () {
render( /*#__PURE__*/React.createElement(Label, {
sm: "6"
}, "Yo!"));
expect(screen.getByText(/yo!/i)).toHaveClass('col-sm-6');
});
it('should pass col size specific classes as Strings (auto)', function () {
render( /*#__PURE__*/React.createElement(Label, {
sm: "auto"
}, "Yo!"));
expect(screen.getByText(/yo!/i)).toHaveClass('col-sm-auto');
});
it('should pass col size specific classes as Strings ("")', function () {
render( /*#__PURE__*/React.createElement(Label, {
sm: ""
}, "Yo!"));
expect(screen.getByText(/yo!/i)).toHaveClass('col-sm');
});
it('should pass col size specific classes as Strings (true)', function () {
render( /*#__PURE__*/React.createElement(Label, {
sm: true
}, "Yo!"));
expect(screen.getByText(/yo!/i)).toHaveClass('col-sm');
});
it('should pass col size specific classes as Strings (xs)', function () {
render( /*#__PURE__*/React.createElement(Label, {
xs: "6"
}, "Yo!"));
expect(screen.getByText(/yo!/i)).toHaveClass('col-6');
});
it('should pass col size specific classes as Strings (xs="")', function () {
render( /*#__PURE__*/React.createElement(Label, {
xs: ""
}, "Yo!"));
expect(screen.getByText(/yo!/i)).toHaveClass('col');
});
it('should pass col size specific classes as Strings (xs (true))', function () {
render( /*#__PURE__*/React.createElement(Label, {
xs: true
}, "Yo!"));
expect(screen.getByText(/yo!/i)).toHaveClass('col');
});
it('should pass col size specific classes as Strings (xs="auto")', function () {
render( /*#__PURE__*/React.createElement(Label, {
xs: "auto"
}, "Yo!"));
expect(screen.getByText(/yo!/i)).toHaveClass('col-auto');
});
it('should render with "visually-hidden" class when hidden prop is truthy', function () {
render( /*#__PURE__*/React.createElement(Label, {
hidden: true
}, "Yo!"));
expect(screen.getByText(/yo!/i)).toHaveClass('visually-hidden');
});
it('should render with "col-form-label-${size}" class when size is provided', function () {
render( /*#__PURE__*/React.createElement(Label, {
size: "lg"
}, "Yo!"));
expect(screen.getByText(/yo!/i)).toHaveClass('col-form-label-lg');
});
it('should pass col size specific classes as Numbers', function () {
render( /*#__PURE__*/React.createElement(Label, {
sm: 6
}, "Yo!"));
expect(screen.getByText(/yo!/i)).toHaveClass('col-sm-6');
});
it('should pass col size specific classes as Numbers (xs)', function () {
render( /*#__PURE__*/React.createElement(Label, {
xs: 6
}, "Yo!"));
expect(screen.getByText(/yo!/i)).toHaveClass('col-6');
});
it('should pass col size specific classes via Objects', function () {
render( /*#__PURE__*/React.createElement(Label, {
sm: {
size: 6,
order: 2,
offset: 2
}
}, "Yo!"));
expect(screen.getByText(/yo!/i)).toHaveClass('col-sm-6');
expect(screen.getByText(/yo!/i)).toHaveClass('order-sm-2');
expect(screen.getByText(/yo!/i)).toHaveClass('offset-sm-2');
});
it('should pass col size specific classes via Objects (xs)', function () {
render( /*#__PURE__*/React.createElement(Label, {
xs: {
size: 6,
order: 2,
offset: 2
}
}, "Yo!"));
expect(screen.getByText(/yo!/i)).toHaveClass('col-6');
expect(screen.getByText(/yo!/i)).toHaveClass('order-2');
expect(screen.getByText(/yo!/i)).toHaveClass('offset-2');
});
it('should pass multiple col size specific classes via Objects', function () {
render( /*#__PURE__*/React.createElement(Label, {
xs: {
size: 4,
order: 3,
offset: 3
},
sm: {
size: 6,
order: 2,
offset: 2
},
md: {
size: 7,
order: 1,
offset: 1
}
}, "Yo!"));
expect(screen.getByText(/yo/i)).toHaveClass('col-4');
expect(screen.getByText(/yo/i)).toHaveClass('order-3');
expect(screen.getByText(/yo/i)).toHaveClass('offset-3');
expect(screen.getByText(/yo/i)).toHaveClass('col-sm-6');
expect(screen.getByText(/yo/i)).toHaveClass('order-sm-2');
expect(screen.getByText(/yo/i)).toHaveClass('offset-sm-2');
expect(screen.getByText(/yo/i)).toHaveClass('col-md-7');
expect(screen.getByText(/yo/i)).toHaveClass('order-md-1');
expect(screen.getByText(/yo/i)).toHaveClass('offset-md-1');
});
it('should render custom tag', function () {
render( /*#__PURE__*/React.createElement(Label, {
tag: "main"
}, "Yo!"));
testForCustomTag(Label, {}, 'main');
});
});

27
node_modules/reactstrap/esm/__tests__/List.spec.js generated vendored Normal file
View File

@@ -0,0 +1,27 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { List } from '..';
import { testForCustomClass, testForCustomTag, testForDefaultTag } from '../testUtils';
describe('List', function () {
it('should render with "ul" tag', function () {
testForDefaultTag(List, 'ul');
});
it('should render with "list-inline" class when type is "inline"', function () {
render( /*#__PURE__*/React.createElement(List, {
type: "inline"
}, "Yo!"));
expect(screen.getByText('Yo!')).toHaveClass('list-inline');
});
it('should render with "list-unstyled" class when type is "unstyled"', function () {
render( /*#__PURE__*/React.createElement(List, {
type: "unstyled"
}, "Yo!"));
expect(screen.getByText('Yo!')).toHaveClass('list-unstyled');
});
it('should render additional classes', function () {
testForCustomClass(List);
});
it('should render custom tag', function () {
testForCustomTag(List);
});
});

View File

@@ -0,0 +1,50 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { ListGroup } from '..';
import { testForCustomClass, testForCustomTag, testForDefaultClass } from '../testUtils';
describe('ListGroup', function () {
it('should render with "list-group" class', function () {
testForDefaultClass(ListGroup, 'list-group');
});
it('should render with "flush"', function () {
render( /*#__PURE__*/React.createElement(ListGroup, {
flush: true
}, "Yo!"));
expect(screen.getByText('Yo!')).toHaveClass('list-group-flush');
expect(screen.getByText('Yo!')).toHaveClass('list-group');
});
it('should render with "horizontal"', function () {
render( /*#__PURE__*/React.createElement(ListGroup, {
horizontal: true
}, "Yo!"));
expect(screen.getByText('Yo!')).toHaveClass('list-group-horizontal');
});
it('should not render with "horizontal" if flush is true', function () {
render( /*#__PURE__*/React.createElement(ListGroup, {
flush: true,
horizontal: true
}, "Yo!"));
expect(screen.getByText('Yo!')).toHaveClass('list-group');
expect(screen.getByText('Yo!')).toHaveClass('list-group-flush');
expect(screen.getByText('Yo!')).not.toHaveClass('list-group-horizontal');
});
it('should render with "horizontal-{breakpoint}"', function () {
render( /*#__PURE__*/React.createElement(ListGroup, {
horizontal: "lg"
}, "Yo!"));
expect(screen.getByText('Yo!')).toHaveClass('list-group');
expect(screen.getByText('Yo!')).toHaveClass('list-group-horizontal-lg');
});
it('should render with "numbered"', function () {
render( /*#__PURE__*/React.createElement(ListGroup, {
numbered: true
}, "Yo!"));
expect(screen.getByText('Yo!')).toHaveClass('list-group-numbered');
});
it('should render additional classes', function () {
testForCustomClass(ListGroup);
});
it('should render custom tag', function () {
testForCustomTag(ListGroup);
});
});

View File

@@ -0,0 +1,46 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import user from '@testing-library/user-event';
import { ListGroupItem } from '..';
import { testForChildrenInComponent, testForDefaultClass } from '../testUtils';
describe('ListGroupItem', function () {
it('should render children', function () {
testForChildrenInComponent(ListGroupItem);
});
it('should render with "list-group-item" class', function () {
testForDefaultClass(ListGroupItem, 'list-group-item');
});
it('should render with "active" class when active is passed', function () {
render( /*#__PURE__*/React.createElement(ListGroupItem, {
active: true
}, "Yo!"));
expect(screen.getByText('Yo!')).toHaveClass('active');
});
it('should render with "disabled" class when disabled is passed', function () {
render( /*#__PURE__*/React.createElement(ListGroupItem, {
disabled: true
}, "Yo!"));
expect(screen.getByText('Yo!')).toHaveClass('disabled');
});
it('should render with "list-group-item-action" class when action is passed', function () {
render( /*#__PURE__*/React.createElement(ListGroupItem, {
action: true
}, "Yo!"));
expect(screen.getByText('Yo!')).toHaveClass('list-group-item-action');
});
it('should render with "list-group-item-${color}" class when color is passed', function () {
render( /*#__PURE__*/React.createElement(ListGroupItem, {
color: "success"
}, "Yo!"));
expect(screen.getByText('Yo!')).toHaveClass('list-group-item-success');
});
it('should prevent click event when disabled is passed', function () {
var onDisableClick = jest.fn();
render( /*#__PURE__*/React.createElement(ListGroupItem, {
disabled: true,
onClick: onDisableClick
}, "Yo!"));
user.click(screen.getByText('Yo!'));
expect(onDisableClick).not.toHaveBeenCalled();
});
});

View File

@@ -0,0 +1,10 @@
import { ListGroupItemHeading } from '..';
import { testForChildrenInComponent, testForDefaultClass } from '../testUtils';
describe('ListGroupItem', function () {
it('should render children', function () {
testForChildrenInComponent(ListGroupItemHeading);
});
it('should render with "list-group-item-heading" class', function () {
testForDefaultClass(ListGroupItemHeading, 'list-group-item-heading');
});
});

View File

@@ -0,0 +1,10 @@
import { ListGroupItemText } from '..';
import { testForChildrenInComponent, testForCustomClass, testForDefaultClass } from '../testUtils';
describe('ListGroupItem', function () {
it('should render children', function () {
testForChildrenInComponent(ListGroupItemText);
});
it('should render with "list-group-item-text" class', function () {
testForDefaultClass(ListGroupItemText, 'list-group-item-text');
});
});

View File

@@ -0,0 +1,16 @@
import { ListInlineItem } from '..';
import { testForChildrenInComponent, testForCustomClass, testForCustomTag, testForDefaultClass } from '../testUtils';
describe('ListInlineItem', function () {
it('should render children', function () {
testForChildrenInComponent(ListInlineItem);
});
it('should render with "list-inline-item" class', function () {
testForDefaultClass(ListInlineItem, 'list-inline-item');
});
it('should render additional classes', function () {
testForCustomClass(ListInlineItem);
});
it('should render custom tag', function () {
testForCustomTag(ListInlineItem);
});
});

129
node_modules/reactstrap/esm/__tests__/Media.spec.js generated vendored Normal file
View File

@@ -0,0 +1,129 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { Media } from '..';
import { testForChildrenInComponent, testForCustomTag, testForDefaultClass, testForDefaultTag } from '../testUtils';
describe('Media', function () {
it('should render a div tag by default', function () {
testForDefaultTag(Media, 'div');
});
it('should render an h4 tag by default for heading', function () {
render( /*#__PURE__*/React.createElement(Media, {
"data-testid": "test",
heading: true
}));
expect(screen.getByTestId('test').tagName.toLowerCase()).toBe('h4');
});
it('should render an a tag by default Media with an href', function () {
render( /*#__PURE__*/React.createElement(Media, {
href: "#",
"data-testid": "test"
}));
expect(screen.getByTestId('test').tagName.toLowerCase()).toBe('a');
});
it('should render an img tag by default for object', function () {
render( /*#__PURE__*/React.createElement(Media, {
object: true,
"data-testid": "test"
}));
expect(screen.getByTestId('test').tagName.toLowerCase()).toBe('img');
});
it('should render an img tag by default Media with a src', function () {
render( /*#__PURE__*/React.createElement(Media, {
src: "#",
"data-testid": "test"
}));
expect(screen.getByTestId('test').tagName.toLowerCase()).toBe('img');
});
it('should render a ul tag by default for list', function () {
render( /*#__PURE__*/React.createElement(Media, {
list: true,
"data-testid": "test"
}));
expect(screen.getByTestId('test').tagName.toLowerCase()).toBe('ul');
});
it('should pass additional classNames', function () {
render( /*#__PURE__*/React.createElement(Media, {
className: "extra",
"data-testid": "test"
}));
expect(screen.getByTestId('test')).toHaveClass('extra');
});
it('should render custom tag', function () {
testForCustomTag(Media);
});
it('should render body', function () {
render( /*#__PURE__*/React.createElement(Media, {
body: true,
"data-testid": "test"
}));
expect(screen.getByTestId('test')).toHaveClass('media-body');
});
it('should render heading', function () {
render( /*#__PURE__*/React.createElement(Media, {
heading: true,
"data-testid": "test"
}));
expect(screen.getByTestId('test')).toHaveClass('media-heading');
});
it('should render left', function () {
render( /*#__PURE__*/React.createElement(Media, {
left: true,
"data-testid": "test"
}));
expect(screen.getByTestId('test')).toHaveClass('media-left');
});
it('should render right', function () {
render( /*#__PURE__*/React.createElement(Media, {
right: true,
"data-testid": "test"
}));
expect(screen.getByTestId('test')).toHaveClass('media-right');
});
it('should render top', function () {
render( /*#__PURE__*/React.createElement(Media, {
top: true,
"data-testid": "test"
}));
expect(screen.getByTestId('test')).toHaveClass('media-top');
});
it('should render bottom', function () {
render( /*#__PURE__*/React.createElement(Media, {
bottom: true,
"data-testid": "test"
}));
expect(screen.getByTestId('test')).toHaveClass('media-bottom');
});
it('should render middle', function () {
render( /*#__PURE__*/React.createElement(Media, {
middle: true,
"data-testid": "test"
}));
expect(screen.getByTestId('test')).toHaveClass('media-middle');
});
it('should render object', function () {
render( /*#__PURE__*/React.createElement(Media, {
object: true,
"data-testid": "test"
}));
expect(screen.getByTestId('test')).toHaveClass('media-object');
});
it('should render media', function () {
testForDefaultClass(Media, 'media');
});
it('should render list', function () {
render( /*#__PURE__*/React.createElement(Media, {
list: true,
"data-testid": "test"
}, /*#__PURE__*/React.createElement(Media, {
tag: "li"
}), /*#__PURE__*/React.createElement(Media, {
tag: "li"
}), /*#__PURE__*/React.createElement(Media, {
tag: "li"
})));
expect(screen.getByTestId('test').querySelectorAll('li').length).toBe(3);
});
it('should render children', function () {
testForChildrenInComponent(Media);
});
});

849
node_modules/reactstrap/esm/__tests__/Modal.spec.js generated vendored Normal file
View File

@@ -0,0 +1,849 @@
/* eslint-disable jsx-a11y/no-noninteractive-tabindex */
import React from 'react';
import { render, screen } from '@testing-library/react';
import user from '@testing-library/user-event';
import '@testing-library/jest-dom';
import { Modal, ModalBody, ModalHeader, ModalFooter, Button } from '..';
describe('Modal', function () {
var toggle = function toggle() {};
beforeEach(function () {
jest.useFakeTimers();
});
afterEach(function () {
jest.clearAllTimers();
// rtl doesn't clear attributes added to body, so manually clearing them
document.body.removeAttribute('style');
document.body.removeAttribute('class');
});
it('should render modal portal into DOM', function () {
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle
}, "Yo!"));
expect(screen.getByText(/yo/i)).toBeInTheDocument();
});
it('should render with the class "modal-dialog"', function () {
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle
}, "Yo!"));
expect(screen.getByText(/yo/i).parentElement).toHaveClass('modal-dialog');
});
it('should render external content when present', function () {
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle,
external: /*#__PURE__*/React.createElement("button", {
className: "cool-close-button"
}, "crazy button")
}, "Yo!"));
expect(screen.getByText(/crazy button/i)).toBeInTheDocument();
expect(screen.getByText(/crazy button/i).nextElementSibling.className.split(' ').indexOf('modal-dialog') > -1).toBe(true);
});
it('should render with the backdrop with the class "modal-backdrop" by default', function () {
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle
}, "Yo!"));
expect(document.getElementsByClassName('modal-backdrop').length).toBe(1);
});
it('should render with the backdrop with the class "modal-backdrop" when backdrop is "static"', function () {
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle,
backdrop: "static"
}, "Yo!"));
expect(document.getElementsByClassName('modal-backdrop').length).toBe(1);
});
it('should not render with the backdrop with the class "modal-backdrop" when backdrop is "false"', function () {
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle,
backdrop: false
}, "Yo!"));
expect(document.getElementsByClassName('modal-dialog').length).toBe(1);
expect(document.getElementsByClassName('modal-backdrop').length).toBe(0);
});
it('should render with the class "modal-dialog-scrollable" when scrollable is "true"', function () {
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle,
scrollable: true
}, "Yo!"));
expect(document.getElementsByClassName('modal-dialog-scrollable').length).toBe(1);
});
it('should render with class "modal-dialog" and have custom class name if provided', function () {
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle,
className: "my-custom-modal"
}, "Yo!"));
expect(document.getElementsByClassName('modal-dialog').length).toBe(1);
expect(document.getElementsByClassName('my-custom-modal').length).toBe(1);
});
it('should render with class "modal-dialog" w/o centered class if not provided', function () {
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle
}, "Yo!"));
jest.advanceTimersByTime(300);
expect(document.getElementsByClassName('modal-dialog').length).toBe(1);
expect(document.getElementsByClassName('modal-dialog-centered').length).toBe(0);
});
it('should render with class "modal-dialog" and centered class if provided', function () {
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle,
centered: true
}, "Yo!"));
expect(document.getElementsByClassName('modal-dialog').length).toBe(1);
expect(document.getElementsByClassName('modal-dialog-centered').length).toBe(1);
});
describe('fullscreen', function () {
it('should render non fullscreen by default', function () {
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle
}, "Yo!"));
expect(document.getElementsByClassName('modal-dialog').length).toBe(1);
expect(document.getElementsByClassName('modal-fullscreen').length).toBe(0);
});
it('should always render fullscreen if true', function () {
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle,
fullscreen: true
}, "Yo!"));
expect(document.getElementsByClassName('modal-dialog').length).toBe(1);
expect(document.getElementsByClassName('modal-fullscreen').length).toBe(1);
});
it('should render fullscreen below breakpoint if breakpoint is provided', function () {
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle,
fullscreen: "lg"
}, "Yo!"));
expect(document.getElementsByClassName('modal-dialog').length).toBe(1);
expect(document.getElementsByClassName('modal-fullscreen').length).toBe(0);
expect(document.getElementsByClassName('modal-fullscreen-lg-down').length).toBe(1);
});
});
it('should render with additional props if provided', function () {
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle,
style: {
maxWidth: '95%'
}
}, "Yo!"));
expect(document.getElementsByClassName('modal-dialog').length).toBe(1);
expect(document.getElementsByClassName('modal-dialog')[0].style.maxWidth).toBe('95%');
});
it('should render without fade transition if provided with fade={false}', function () {
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle,
fade: false,
modalClassName: "fadeless-modal"
}, "Howdy!"));
var matchedModals = document.getElementsByClassName('fadeless-modal');
var matchedModal = matchedModals[0];
expect(matchedModals.length).toBe(1);
// Modal should not have the 'fade' class
expect(matchedModal.className.split(' ').indexOf('fade') < 0).toBe(true);
});
it('should render when expected when passed modalTransition and backdropTransition props', function () {
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle,
modalTransition: {
timeout: 2
},
backdropTransition: {
timeout: 10
},
modalClassName: "custom-timeout-modal"
}, "Hello, world!"));
expect(document.getElementsByClassName('custom-timeout-modal').length).toBe(1);
});
it('should render with class "modal" and have custom class name if provided with modalClassName', function () {
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle,
modalClassName: "my-custom-modal"
}, "Yo!"));
expect(document.querySelectorAll('.modal.my-custom-modal').length).toBe(1);
});
it('should render with custom class name if provided with wrapClassName', function () {
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle,
wrapClassName: "my-custom-modal"
}, "Yo!"));
expect(document.getElementsByClassName('my-custom-modal').length).toBe(1);
});
it('should render with class "modal-content" and have custom class name if provided with contentClassName', function () {
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle,
contentClassName: "my-custom-modal"
}, "Yo!"));
expect(document.querySelectorAll('.modal-content.my-custom-modal').length).toBe(1);
});
it('should render with class "modal-backdrop" and have custom class name if provided with backdropClassName', function () {
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle,
backdropClassName: "my-custom-modal"
}, "Yo!"));
expect(document.querySelectorAll('.modal-backdrop.my-custom-modal').length).toBe(1);
});
it('should render with the class "modal-${size}" when size is passed', function () {
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle,
size: "crazy"
}, "Yo!"));
expect(document.getElementsByClassName('modal-dialog').length).toBe(1);
expect(document.getElementsByClassName('modal-crazy').length).toBe(1);
});
it('should render modal when isOpen is true', function () {
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle
}, "Yo!"));
expect(document.getElementsByClassName('modal').length).toBe(1);
expect(document.getElementsByClassName('modal-backdrop').length).toBe(1);
});
it('should render modal with default role of "dialog"', function () {
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle
}, "Yo!"));
expect(document.getElementsByClassName('modal')[0].getAttribute('role')).toBe('dialog');
});
it('should render modal with provided role', function () {
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle,
role: "alert"
}, "Yo!"));
expect(document.getElementsByClassName('modal')[0].getAttribute('role')).toBe('alert');
});
it('should render modal with aria-labelledby provided labelledBy', function () {
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle,
labelledBy: "myModalTitle"
}, "Yo!"));
expect(document.getElementsByClassName('modal')[0].getAttribute('aria-labelledby')).toBe('myModalTitle');
});
it('should not render modal when isOpen is false', function () {
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: false,
toggle: toggle
}, "Yo!"));
expect(document.getElementsByClassName('modal').length).toBe(0);
expect(document.getElementsByClassName('modal-backdrop').length).toBe(0);
});
it('should toggle modal', function () {
var _render = render( /*#__PURE__*/React.createElement(Modal, {
isOpen: false,
toggle: toggle
}, "Yo!")),
rerender = _render.rerender;
expect(document.getElementsByClassName('modal').length).toBe(0);
expect(document.getElementsByClassName('modal-backdrop').length).toBe(0);
rerender( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle
}, "Yo!"));
expect(document.getElementsByClassName('modal').length).toBe(1);
expect(document.getElementsByClassName('modal-backdrop').length).toBe(1);
});
it('should call onClosed & onOpened', function () {
var onOpened = jest.fn();
var onClosed = jest.fn();
var _render2 = render( /*#__PURE__*/React.createElement(Modal, {
isOpen: false,
onOpened: onOpened,
onClosed: onClosed,
toggle: toggle
}, "Yo!")),
rerender = _render2.rerender;
expect(onOpened).not.toHaveBeenCalled();
expect(onClosed).not.toHaveBeenCalled();
rerender( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
onOpened: onOpened,
onClosed: onClosed,
toggle: toggle
}, "Yo!"));
jest.advanceTimersByTime(300);
expect(onOpened).toHaveBeenCalledTimes(1);
rerender( /*#__PURE__*/React.createElement(Modal, {
isOpen: false,
onOpened: onOpened,
onClosed: onClosed,
toggle: toggle
}, "Yo!"));
jest.advanceTimersByTime(300);
expect(onOpened).toHaveBeenCalledTimes(1);
expect(onClosed).toHaveBeenCalledTimes(1);
});
it('should call onClosed & onOpened when fade={false}', function () {
var onOpened = jest.fn();
var onClosed = jest.fn();
var _render3 = render( /*#__PURE__*/React.createElement(Modal, {
isOpen: false,
onOpened: onOpened,
onClosed: onClosed,
toggle: toggle,
fade: false
}, "Yo!")),
rerender = _render3.rerender;
expect(onOpened).not.toHaveBeenCalled();
expect(onClosed).not.toHaveBeenCalled();
rerender( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
onOpened: onOpened,
onClosed: onClosed,
toggle: toggle,
fade: false
}, "Yo!"));
jest.advanceTimersByTime(1);
expect(onOpened).toHaveBeenCalledTimes(1);
expect(onClosed).not.toHaveBeenCalled();
rerender( /*#__PURE__*/React.createElement(Modal, {
isOpen: false,
onOpened: onOpened,
onClosed: onClosed,
toggle: toggle,
fade: false
}, "Yo!"));
jest.advanceTimersByTime(1);
expect(onClosed).toHaveBeenCalledTimes(1);
expect(onOpened).toHaveBeenCalledTimes(1);
});
it('should call toggle when escape key pressed and not for enter key', function () {
var toggle = jest.fn();
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle
}, "Yo!"));
user.keyboard('{enter}');
expect(toggle).not.toHaveBeenCalled();
user.keyboard('{esc}');
expect(toggle).toHaveBeenCalled();
});
it('should not call toggle when escape key pressed when keyboard is false', function () {
var toggle = jest.fn();
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle,
keyboard: false
}, "Yo!"));
user.keyboard('{esc}');
expect(toggle).not.toHaveBeenCalled();
});
it('should call toggle when clicking backdrop', function () {
var toggle = jest.fn();
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle
}, /*#__PURE__*/React.createElement("button", {
id: "clicker"
}, "Does Nothing")));
user.click(screen.getByText(/does nothing/i));
expect(toggle).not.toHaveBeenCalled();
user.click(document.body.getElementsByClassName('modal')[0]);
expect(toggle).toHaveBeenCalled();
});
it('should not call toggle when clicking backdrop and backdrop is "static"', function () {
var toggle = jest.fn();
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle,
backdrop: "static"
}, /*#__PURE__*/React.createElement("button", {
id: "clicker"
}, "Does Nothing")));
user.click(document.getElementsByClassName('modal-backdrop')[0]);
expect(toggle).not.toHaveBeenCalled();
});
it('should not call toggle when escape key pressed and backdrop is "static" and keyboard=false', function () {
var toggle = jest.fn();
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle,
backdrop: "static",
keyboard: false
}, "Yo!"));
user.keyboard('{esc}');
expect(toggle).not.toHaveBeenCalled();
});
it('should call toggle when escape key pressed and backdrop is "static" and keyboard=true', function () {
var toggle = jest.fn();
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle,
backdrop: "static",
keyboard: true
}, /*#__PURE__*/React.createElement("button", {
id: "clicker"
}, "Does Nothing")));
user.keyboard('{esc}');
expect(toggle).toHaveBeenCalled();
});
it('should animate when backdrop is "static" and escape key pressed and keyboard=false', function () {
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle,
backdrop: "static",
keyboard: false,
"data-testid": "mandalorian"
}, /*#__PURE__*/React.createElement("button", {
id: "clicker"
}, "Does Nothing")));
user.keyboard('{esc}');
expect(screen.getByTestId('mandalorian').parentElement).toHaveClass('modal-static');
jest.advanceTimersByTime(300);
expect(screen.getByTestId('mandalorian').parentElement).not.toHaveClass('modal-static');
});
it('should animate when backdrop is "static" and backdrop is clicked', function () {
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle,
backdrop: "static",
"data-testid": "mandalorian"
}, /*#__PURE__*/React.createElement("button", {
id: "clicker"
}, "Does Nothing")));
user.click(document.getElementsByClassName('modal')[0]);
expect(screen.getByTestId('mandalorian').parentElement).toHaveClass('modal-static');
jest.advanceTimersByTime(300);
expect(screen.getByTestId('mandalorian').parentElement).not.toHaveClass('modal-static');
});
it('should not animate when backdrop is "static" and modal is clicked', function () {
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle,
backdrop: "static",
"data-testid": "mandalorian"
}, /*#__PURE__*/React.createElement("button", {
id: "clicker"
}, "Does Nothing")));
user.click(document.getElementsByClassName('modal-dialog')[0]);
expect(screen.getByTestId('mandalorian').parentElement).not.toHaveClass('modal-static');
});
it('should destroy this._element', function () {
var _render4 = render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle,
wrapClassName: "weird-class"
}, /*#__PURE__*/React.createElement("button", {
id: "clicker"
}, "Does Nothing"))),
rerender = _render4.rerender;
var element = document.getElementsByClassName('weird-class')[0].parentElement;
expect(element).toBeInTheDocument();
rerender( /*#__PURE__*/React.createElement(Modal, {
isOpen: false,
toggle: toggle,
wrapClassName: "weird-class"
}, /*#__PURE__*/React.createElement("button", {
id: "clicker"
}, "Does Nothing")));
jest.advanceTimersByTime(300);
expect(element).not.toBeInTheDocument();
});
it('should destroy this._element when unmountOnClose prop set to true', function () {
var _render5 = render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle,
unmountOnClose: true,
wrapClassName: "weird-class"
}, /*#__PURE__*/React.createElement("button", {
id: "clicker"
}, "Does Nothing"))),
rerender = _render5.rerender;
var element = document.getElementsByClassName('weird-class')[0].parentElement;
expect(element).toBeInTheDocument();
rerender( /*#__PURE__*/React.createElement(Modal, {
isOpen: false,
toggle: toggle,
unmountOnClose: true,
wrapClassName: "weird-class"
}, /*#__PURE__*/React.createElement("button", {
id: "clicker"
}, "Does Nothing")));
jest.advanceTimersByTime(300);
expect(element).not.toBeInTheDocument();
});
it('should not destroy this._element when unmountOnClose prop set to false', function () {
var _render6 = render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle,
unmountOnClose: false,
wrapClassName: "weird-class"
}, /*#__PURE__*/React.createElement("button", {
id: "clicker"
}, "Does Nothing"))),
rerender = _render6.rerender;
var element = document.getElementsByClassName('weird-class')[0].parentElement;
expect(element).toBeInTheDocument();
rerender( /*#__PURE__*/React.createElement(Modal, {
isOpen: false,
toggle: toggle,
unmountOnClose: false,
wrapClassName: "weird-class"
}, /*#__PURE__*/React.createElement("button", {
id: "clicker"
}, "Does Nothing")));
expect(element).toBeInTheDocument();
});
it('should destroy this._element on unmount', function () {
var _render7 = render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle,
wrapClassName: "weird-class"
}, /*#__PURE__*/React.createElement("button", {
id: "clicker"
}, "Does Nothing"))),
unmount = _render7.unmount;
unmount();
jest.advanceTimersByTime(300);
expect(document.getElementsByClassName('modal').length).toBe(0);
});
it('should render nested modals', function () {
var _render8 = render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle
}, /*#__PURE__*/React.createElement(ModalBody, null, /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: function toggle() {}
}, "Yo!")))),
unmount = _render8.unmount;
expect(document.getElementsByClassName('modal-dialog').length).toBe(2);
expect(document.body.className).toBe('modal-open');
unmount();
expect(document.getElementsByClassName('modal-dialog').length).toBe(0);
});
it('should remove exactly modal-open class from body', function () {
// set a body class which includes modal-open
document.body.className = 'my-modal-opened';
var _render9 = render( /*#__PURE__*/React.createElement(Modal, {
isOpen: false,
toggle: toggle
}, "Yo!")),
rerender = _render9.rerender;
expect(document.body.className).toBe('my-modal-opened');
rerender( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle
}, "Yo!"));
expect(document.body.className).toBe('my-modal-opened modal-open');
// using this to test if replace will leave a space when removing modal-open
document.body.className += ' modal-opened';
expect(document.body.className).toBe('my-modal-opened modal-open modal-opened');
rerender( /*#__PURE__*/React.createElement(Modal, {
isOpen: false,
toggle: toggle
}, "Yo!"));
jest.advanceTimersByTime(300);
expect(document.body.className).toBe('my-modal-opened modal-opened');
});
it('should call onEnter & onExit props if provided', function () {
var onEnter = jest.fn();
var onExit = jest.fn();
var _render10 = render( /*#__PURE__*/React.createElement(Modal, {
isOpen: false,
onEnter: onEnter,
onExit: onExit,
toggle: toggle
}, "Yo!")),
rerender = _render10.rerender,
unmount = _render10.unmount;
expect(onEnter).toHaveBeenCalled();
expect(onExit).not.toHaveBeenCalled();
onEnter.mockReset();
onExit.mockReset();
rerender( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
onEnter: onEnter,
onExit: onExit,
toggle: toggle
}, "Yo!"));
expect(onEnter).not.toHaveBeenCalled();
expect(onExit).not.toHaveBeenCalled();
onEnter.mockReset();
onExit.mockReset();
rerender( /*#__PURE__*/React.createElement(Modal, {
isOpen: false,
onEnter: onEnter,
onExit: onExit,
toggle: toggle
}, "Yo!"));
unmount();
expect(onEnter).not.toHaveBeenCalled();
expect(onExit).toHaveBeenCalled();
});
it('should update element z index when prop changes', function () {
var _render11 = render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
zIndex: 0,
wrapClassName: "sandman"
}, "Yo!")),
rerender = _render11.rerender;
expect(document.getElementsByClassName('sandman')[0].parentElement.style.zIndex).toBe('0');
rerender( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
zIndex: 1,
wrapClassName: "sandman"
}, "Yo!"));
expect(document.getElementsByClassName('sandman')[0].parentElement.style.zIndex).toBe('1');
});
it('should allow focus on only focusable elements and tab through them', function () {
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle
}, /*#__PURE__*/React.createElement(ModalHeader, {
toggle: toggle
}, "Modal title"), /*#__PURE__*/React.createElement(ModalBody, null, /*#__PURE__*/React.createElement("a", {
alt: "test",
href: "/"
}, "First Test"), /*#__PURE__*/React.createElement("map", {
name: "test"
}, /*#__PURE__*/React.createElement("area", {
alt: "test",
href: "/",
coords: "200,5,200,30"
})), /*#__PURE__*/React.createElement("input", {
type: "text",
"aria-label": "test text input"
}), /*#__PURE__*/React.createElement("input", {
type: "hidden"
}), /*#__PURE__*/React.createElement("input", {
type: "text",
disabled: true,
value: "Test"
}), /*#__PURE__*/React.createElement("select", {
name: "test",
id: "select_test"
}, /*#__PURE__*/React.createElement("option", null, "Second item")), /*#__PURE__*/React.createElement("select", {
name: "test",
id: "select_test_disabled",
disabled: true
}, /*#__PURE__*/React.createElement("option", null, "Third item")), /*#__PURE__*/React.createElement("textarea", {
name: "textarea_test",
id: "textarea_test",
cols: "30",
rows: "10",
"aria-label": "test text area"
}), /*#__PURE__*/React.createElement("textarea", {
name: "textarea_test_disabled",
id: "textarea_test_disabled",
cols: "30",
rows: "10",
disabled: true
}), /*#__PURE__*/React.createElement("object", null, "Test"), /*#__PURE__*/React.createElement("span", {
tabIndex: "0"
}, "test tab index")), /*#__PURE__*/React.createElement(ModalFooter, null, /*#__PURE__*/React.createElement(Button, {
disabled: true,
color: "primary",
onClick: toggle
}, "Do Something"), ' ', /*#__PURE__*/React.createElement(Button, {
color: "secondary",
onClick: toggle
}, "Cancel"))));
user.tab();
expect(screen.getByLabelText(/close/i)).toHaveFocus();
user.tab();
expect(screen.getByText(/first test/i)).toHaveFocus();
user.tab();
expect(screen.getByLabelText(/test text input/i)).toHaveFocus();
user.tab();
expect(screen.getByText(/second item/i).parentElement).toHaveFocus();
user.tab();
expect(screen.getByLabelText(/test text area/i)).toHaveFocus();
user.tab();
expect(screen.getByText(/test tab index/i)).toHaveFocus();
user.tab();
expect(screen.getByText(/cancel/i)).toHaveFocus();
user.tab();
expect(screen.getByLabelText(/close/i)).toHaveFocus();
});
it('should return the focus to the last focused element before the modal has opened', function () {
var _render12 = render( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
className: "focus"
}, "Focused"), /*#__PURE__*/React.createElement(Modal, {
isOpen: false
}, /*#__PURE__*/React.createElement(ModalBody, null, "Whatever")))),
rerender = _render12.rerender;
user.tab();
expect(screen.getByText(/focused/i)).toHaveFocus();
rerender( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
className: "focus"
}, "Focused"), /*#__PURE__*/React.createElement(Modal, {
isOpen: true
}, /*#__PURE__*/React.createElement(ModalBody, null, "Whatever"))));
rerender( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
className: "focus"
}, "Focused"), /*#__PURE__*/React.createElement(Modal, {
isOpen: false
}, /*#__PURE__*/React.createElement(ModalBody, null, "Whatever"))));
jest.runAllTimers();
expect(screen.getByText(/focused/i)).toHaveFocus();
});
it('should not return the focus to the last focused element before the modal has opened when "returnFocusAfterClose" is false', function () {
var _render13 = render( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
className: "focus"
}, "Focused"), /*#__PURE__*/React.createElement(Modal, {
returnFocusAfterClose: false,
isOpen: false
}, /*#__PURE__*/React.createElement(ModalBody, null, "Whatever")))),
rerender = _render13.rerender;
user.tab();
expect(screen.getByText(/focused/i)).toHaveFocus();
rerender( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
className: "focus"
}, "Focused"), /*#__PURE__*/React.createElement(Modal, {
returnFocusAfterClose: false,
isOpen: true
}, /*#__PURE__*/React.createElement(ModalBody, null, "Whatever"))));
rerender( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
className: "focus"
}, "Focused"), /*#__PURE__*/React.createElement(Modal, {
returnFocusAfterClose: false,
isOpen: false
}, /*#__PURE__*/React.createElement(ModalBody, null, "Whatever"))));
jest.runAllTimers();
expect(screen.getByText(/focused/i)).not.toHaveFocus();
});
it('should return the focus to the last focused element before the modal has opened when "unmountOnClose" is false', function () {
var _render14 = render( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
className: "focus"
}, "Focused"), /*#__PURE__*/React.createElement(Modal, {
unmountOnClose: false,
isOpen: false
}, /*#__PURE__*/React.createElement(ModalBody, null, "Whatever")))),
rerender = _render14.rerender;
user.tab();
expect(screen.getByText(/focused/i)).toHaveFocus();
rerender( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
className: "focus"
}, "Focused"), /*#__PURE__*/React.createElement(Modal, {
unmountOnClose: false,
isOpen: true
}, /*#__PURE__*/React.createElement(ModalBody, null, "Whatever"))));
rerender( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
className: "focus"
}, "Focused"), /*#__PURE__*/React.createElement(Modal, {
unmountOnClose: false,
isOpen: false
}, /*#__PURE__*/React.createElement(ModalBody, null, "Whatever"))));
jest.runAllTimers();
expect(screen.getByText(/focused/i)).toHaveFocus();
});
it('should not return the focus to the last focused element before the modal has opened when "returnFocusAfterClose" is false and "unmountOnClose" is false', function () {
var _render15 = render( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
className: "focus"
}, "Focused"), /*#__PURE__*/React.createElement(Modal, {
unmountOnClose: false,
returnFocusAfterClose: false,
isOpen: false
}, /*#__PURE__*/React.createElement(ModalBody, null, "Whatever")))),
rerender = _render15.rerender;
user.tab();
expect(screen.getByText(/focused/i)).toHaveFocus();
rerender( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
className: "focus"
}, "Focused"), /*#__PURE__*/React.createElement(Modal, {
unmountOnClose: false,
returnFocusAfterClose: false,
isOpen: true
}, /*#__PURE__*/React.createElement(ModalBody, null, "Whatever"))));
rerender( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
className: "focus"
}, "Focused"), /*#__PURE__*/React.createElement(Modal, {
unmountOnClose: false,
returnFocusAfterClose: false,
isOpen: false
}, /*#__PURE__*/React.createElement(ModalBody, null, "Whatever"))));
jest.runAllTimers();
expect(screen.getByText(/focused/i)).not.toHaveFocus();
});
it('should attach/detach trapFocus for dialogs', function () {
var addEventListener = jest.spyOn(document, 'addEventListener');
var removeEventListener = jest.spyOn(document, 'removeEventListener');
var _render16 = render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true
}, /*#__PURE__*/React.createElement(ModalBody, null, /*#__PURE__*/React.createElement(Button, {
className: "focus"
}, "focusable element")))),
unmount = _render16.unmount;
expect(addEventListener).toHaveBeenCalledTimes(1);
expect(addEventListener).toHaveBeenCalledWith('focus', expect.any(Function), true);
unmount();
expect(removeEventListener).toHaveBeenCalledTimes(1);
expect(removeEventListener).toHaveBeenCalledWith('focus', expect.any(Function), true);
addEventListener.mockRestore();
removeEventListener.mockRestore();
});
it('should trap focus inside the open dialog', function () {
var _render17 = render( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, {
className: "first"
}, "Focused"), /*#__PURE__*/React.createElement(Modal, {
isOpen: false,
trapFocus: true
}, /*#__PURE__*/React.createElement(ModalBody, null, "Something else to see", /*#__PURE__*/React.createElement(Button, {
className: "focus"
}, "focusable element"))))),
rerender = _render17.rerender;
screen.getByText(/focused/i).focus();
expect(screen.getByText(/focused/i)).toHaveFocus();
rerender( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, {
className: "first"
}, "Focused"), /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
trapFocus: true,
"data-testid": "modal"
}, /*#__PURE__*/React.createElement(ModalBody, null, "Something else to see", /*#__PURE__*/React.createElement(Button, {
className: "focus"
}, "focusable element")))));
jest.runAllTimers();
expect(screen.getByText(/focused/i)).not.toHaveFocus();
expect(screen.getByTestId('modal').parentElement).toHaveFocus();
// pressing tab shouldn't move focus outside the modal
user.tab();
expect(screen.getByText(/focusable element/i)).toHaveFocus();
user.tab();
expect(screen.getByText(/focusable element/i)).toHaveFocus();
});
it('tab should focus on inside modal children for nested modal', function () {
render( /*#__PURE__*/React.createElement(Modal, {
isOpen: true,
toggle: toggle
}, /*#__PURE__*/React.createElement(ModalBody, null, /*#__PURE__*/React.createElement(Button, {
className: "b0",
onClick: toggle
}, "Cancel"), /*#__PURE__*/React.createElement(Modal, {
isOpen: true
}, /*#__PURE__*/React.createElement(ModalBody, null, /*#__PURE__*/React.createElement(Button, {
className: "b1"
}, "Click 1"))))));
user.tab();
expect(screen.getByText(/click 1/i)).toHaveFocus();
// pressing tab doesn't take focus out of inside modal
user.tab();
expect(screen.getByText(/click 1/i)).toHaveFocus();
});
it('works with strict mode', function () {
var spy = jest.spyOn(console, 'error');
render( /*#__PURE__*/React.createElement(React.StrictMode, null, /*#__PURE__*/React.createElement(Modal, {
isOpen: true
}, "Hello")));
expect(spy).not.toHaveBeenCalled();
});
});

View File

@@ -0,0 +1,13 @@
import { ModalBody } from '..';
import { testForCustomClass, testForCustomTag, testForDefaultClass } from '../testUtils';
describe('ModalBody', function () {
it('should render with "modal-body" class', function () {
testForDefaultClass(ModalBody, 'modal-body');
});
it('should render additional classes', function () {
testForCustomClass(ModalBody, {});
});
it('should render custom tag', function () {
testForCustomTag(ModalBody);
});
});

View File

@@ -0,0 +1,13 @@
import { ModalFooter } from '..';
import { testForCustomClass, testForCustomTag, testForDefaultClass } from '../testUtils';
describe('ModalFooter', function () {
it('should render with "modal-footer" class', function () {
testForDefaultClass(ModalFooter, 'modal-footer');
});
it('should render additional classes', function () {
testForCustomClass(ModalFooter);
});
it('should render custom tag', function () {
testForCustomTag(ModalFooter);
});
});

View File

@@ -0,0 +1,36 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { ModalHeader } from '..';
import { testForCustomClass, testForDefaultClass } from '../testUtils';
describe('ModalHeader', function () {
it('should render with "modal-header" class', function () {
testForDefaultClass(ModalHeader, 'modal-header');
});
it('should render additional classes', function () {
testForCustomClass(ModalHeader);
});
it('should render close button', function () {
render( /*#__PURE__*/React.createElement(ModalHeader, {
toggle: function toggle() {},
"data-testid": "test",
className: "other"
}, "Yo!"));
var node = screen.getByTestId('test').querySelector('button');
expect(node.tagName.toLowerCase()).toBe('button');
expect(node).toHaveClass('btn-close');
});
it('should render custom tag', function () {
render( /*#__PURE__*/React.createElement(ModalHeader, {
tag: "main"
}, "hello"));
expect(screen.getByText(/hello/i).tagName.toLowerCase()).toBe('main');
});
it('should render custom wrapping tag', function () {
render( /*#__PURE__*/React.createElement(ModalHeader, {
"data-testid": "test",
wrapTag: "main"
}));
expect(screen.getByTestId('test').tagName.toLowerCase()).toMatch('main');
});
});

91
node_modules/reactstrap/esm/__tests__/Nav.spec.js generated vendored Normal file
View File

@@ -0,0 +1,91 @@
import React from 'react';
import { screen, render } from '@testing-library/react';
import '@testing-library/jest-dom';
import { Nav } from '..';
import { testForChildrenInComponent, testForCustomClass, testForCustomTag, testForDefaultClass } from '../testUtils';
describe('Nav', function () {
it('should render .nav markup', function () {
testForDefaultClass(Nav, 'nav');
});
it('should render custom tag', function () {
testForCustomTag(Nav);
});
it('should render children', function () {
testForChildrenInComponent(Nav);
});
it('should handle justified prop', function () {
var _render = render( /*#__PURE__*/React.createElement(Nav, {
justified: true
})),
container = _render.container;
expect(container).toContainHTML('<ul class="nav nav-justified"></ul>');
});
it('should handle fill prop', function () {
var _render2 = render( /*#__PURE__*/React.createElement(Nav, {
fill: true
})),
container = _render2.container;
expect(container).toContainHTML('<ul class="nav nav-fill"></ul>');
});
it('should handle pills prop', function () {
var _render3 = render( /*#__PURE__*/React.createElement(Nav, {
pills: true
})),
container = _render3.container;
expect(container).toContainHTML('<ul class="nav nav-pills"></ul>');
});
it('should handle pills prop with card prop', function () {
var _render4 = render( /*#__PURE__*/React.createElement(Nav, {
pills: true,
card: true
})),
container = _render4.container;
expect(container).toContainHTML('<ul class="nav nav-pills card-header-pills"></ul>');
});
it('should handle tabs prop', function () {
var _render5 = render( /*#__PURE__*/React.createElement(Nav, {
tabs: true
})),
container = _render5.container;
expect(container).toContainHTML('<ul class="nav nav-tabs"></ul>');
});
it('should handle tabs prop with card prop', function () {
var _render6 = render( /*#__PURE__*/React.createElement(Nav, {
tabs: true,
card: true
})),
container = _render6.container;
expect(container).toContainHTML('<ul class="nav nav-tabs card-header-tabs"></ul>');
});
it('should handle vertical prop', function () {
var _render7 = render( /*#__PURE__*/React.createElement(Nav, {
vertical: true
})),
container = _render7.container;
expect(container).toContainHTML('<ul class="nav flex-column"></ul>');
});
it('should handle vertical prop with string', function () {
var _render8 = render( /*#__PURE__*/React.createElement(Nav, {
vertical: "sm"
})),
container = _render8.container;
expect(container).toContainHTML('<ul class="nav flex-sm-column"></ul>');
});
it('should handle horizontal prop with string', function () {
var _render9 = render( /*#__PURE__*/React.createElement(Nav, {
horizontal: "end"
})),
container = _render9.container;
expect(container).toContainHTML('<ul class="nav justify-content-end"></ul>');
});
it('should pass additional classNames', function () {
testForCustomClass(Nav);
});
it('should render .navbar-nav class only', function () {
var _render10 = render( /*#__PURE__*/React.createElement(Nav, {
navbar: true
}, "Children")),
container = _render10.container;
expect(container).toContainHTML('<ul class="navbar-nav">Children</ul>');
});
});

18
node_modules/reactstrap/esm/__tests__/NavBrand.spec.js generated vendored Normal file
View File

@@ -0,0 +1,18 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { NavbarBrand } from '..';
import { testForChildrenInComponent, testForCustomClass, testForDefaultClass, testForDefaultTag } from '../testUtils';
describe('NavbarBrand', function () {
it('should render .navbar-brand markup', function () {
testForDefaultClass(NavbarBrand, 'navbar-brand');
});
it('should render custom tag', function () {
testForDefaultTag(NavbarBrand, 'a');
});
it('sholid render children', function () {
testForChildrenInComponent(NavbarBrand);
});
it('should pass additional classNames', function () {
testForCustomClass(NavbarBrand);
});
});

25
node_modules/reactstrap/esm/__tests__/NavItem.spec.js generated vendored Normal file
View File

@@ -0,0 +1,25 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { NavItem } from '..';
import { testForChildrenInComponent, testForCustomClass, testForCustomTag, testForDefaultClass } from '../testUtils';
describe('NavItem', function () {
it('should render .nav-item class', function () {
testForDefaultClass(NavItem, 'nav-item');
});
it('should render custom tag', function () {
testForCustomTag(NavItem);
});
it('should render children', function () {
testForChildrenInComponent(NavItem);
});
it('should pass additional classNames', function () {
testForCustomClass(NavItem);
});
it('should render active class', function () {
render( /*#__PURE__*/React.createElement(NavItem, {
active: true,
"data-testid": "test"
}));
expect(screen.getByTestId('test')).toHaveClass('active');
});
});

64
node_modules/reactstrap/esm/__tests__/NavLink.spec.js generated vendored Normal file
View File

@@ -0,0 +1,64 @@
import React from 'react';
import { createEvent, fireEvent, render, screen } from '@testing-library/react';
import user from '@testing-library/user-event';
import { NavLink } from '..';
import { testForChildrenInComponent, testForCustomClass, testForCustomTag, testForDefaultClass } from '../testUtils';
describe('NavLink', function () {
it('should render .nav-link markup', function () {
testForDefaultClass(NavLink, 'nav-link');
});
it('should render custom tag', function () {
testForCustomTag(NavLink);
});
it('should render children', function () {
testForChildrenInComponent(NavLink);
});
it('should pass additional classNames', function () {
testForCustomClass(NavLink);
});
it('should render active class', function () {
render( /*#__PURE__*/React.createElement(NavLink, {
active: true
}, "Yo!"));
expect(screen.getByText('Yo!')).toHaveClass('active');
});
it('should render disabled markup', function () {
render( /*#__PURE__*/React.createElement(NavLink, {
disabled: true
}, "Yo!"));
expect(screen.getByText('Yo!')).toHaveAttribute('disabled');
});
it('handles onClick prop', function () {
var onClick = jest.fn();
render( /*#__PURE__*/React.createElement(NavLink, {
onClick: onClick
}, "testing click"));
user.click(screen.getByText(/testing click/i));
expect(onClick).toHaveBeenCalled();
});
it('handles onClick events', function () {
render( /*#__PURE__*/React.createElement(NavLink, null, "hello"));
var node = screen.getByText(/hello/i);
var click = createEvent.click(node);
fireEvent(node, click);
expect(click.defaultPrevented).toBeFalsy();
});
it('prevents link clicks via onClick for dropdown nav-items', function () {
render( /*#__PURE__*/React.createElement(NavLink, {
href: "#"
}, "hello"));
var node = screen.getByText(/hello/i);
var click = createEvent.click(node);
fireEvent(node, click);
expect(click.defaultPrevented).toBeTruthy();
});
it('is not called when disabled', function () {
var onClick = jest.fn();
render( /*#__PURE__*/React.createElement(NavLink, {
onClick: onClick,
disabled: true
}, "testing click"));
user.click(screen.getByText(/testing click/i));
expect(onClick).not.toHaveBeenCalled();
});
});

101
node_modules/reactstrap/esm/__tests__/Navbar.spec.js generated vendored Normal file
View File

@@ -0,0 +1,101 @@
import React from 'react';
import { screen, render } from '@testing-library/react';
import '@testing-library/jest-dom';
import { Navbar } from '..';
import { testForCustomTag } from '../testUtils';
describe('Navbar', function () {
it('should render .navbar markup', function () {
var _render = render( /*#__PURE__*/React.createElement(Navbar, null)),
container = _render.container;
expect(container).toContainHTML('<nav class="navbar" ><div class="container-fluid" /></nav>');
});
it('should render default .navbar-expand class', function () {
render( /*#__PURE__*/React.createElement(Navbar, {
"data-testid": "navBar",
expand: true
}));
expect(screen.getByTestId('navBar')).toHaveClass('navbar-expand');
});
it('should render size based .navbar-expand-* classes', function () {
render( /*#__PURE__*/React.createElement(Navbar, {
"data-testid": "navBar",
expand: "md"
}));
expect(screen.getByTestId('navBar')).toHaveClass('navbar-expand-md');
});
it('should render custom tag', function () {
testForCustomTag(Navbar, {}, 'div');
});
it('should render role', function () {
var _render2 = render( /*#__PURE__*/React.createElement(Navbar, {
role: "navigation"
})),
container = _render2.container;
expect(container).toContainHTML('<nav role="navigation" class="navbar"><div class="container-fluid"></div></nav>');
});
it('should support container options', function () {
var _render3 = render( /*#__PURE__*/React.createElement(Navbar, {
container: false
})),
rerender = _render3.rerender,
container = _render3.container;
expect(container).toContainHTML('<nav class="navbar"></nav>');
rerender( /*#__PURE__*/React.createElement(Navbar, {
container: true
}));
expect(container).toContainHTML('<nav class="navbar"><div class="container"></div></nav>');
rerender( /*#__PURE__*/React.createElement(Navbar, {
container: "xs"
}));
expect(container).toContainHTML('<nav class="navbar"><div class="container-xs"></div></nav>');
rerender( /*#__PURE__*/React.createElement(Navbar, {
container: "sm"
}));
expect(container).toContainHTML('<nav class="navbar"><div class="container-sm"></div></nav>');
rerender( /*#__PURE__*/React.createElement(Navbar, {
container: "md"
}));
expect(container).toContainHTML('<nav class="navbar"><div class="container-md"></div></nav>');
rerender( /*#__PURE__*/React.createElement("div", {
"data-testid": "navBarLg"
}, /*#__PURE__*/React.createElement(Navbar, {
container: "lg"
})));
expect(container).toContainHTML('<nav class="navbar"><div class="container-lg"></div></nav>');
rerender( /*#__PURE__*/React.createElement(Navbar, {
container: "xl"
}));
expect(container).toContainHTML('<nav class="navbar"><div class="container-xl"></div></nav>');
});
it('should render children', function () {
var _render4 = render( /*#__PURE__*/React.createElement(Navbar, null, "Children")),
container = _render4.container;
expect(container).toContainHTML('<nav class="navbar"><div class="container-fluid">Children</div></nav>');
});
it('should pass additional classNames', function () {
render( /*#__PURE__*/React.createElement(Navbar, {
"data-testid": "navBar",
className: "extra"
}));
expect(screen.getByTestId('navBar')).toHaveClass('extra navbar');
});
it('should render prop based classes', function () {
render( /*#__PURE__*/React.createElement(Navbar, {
"data-testid": "navBar",
light: true,
dark: true,
expand: "sm",
color: "success",
sticky: "top",
fixed: "top"
}));
var node = screen.getByTestId('navBar');
expect(node).toHaveClass('bg-success');
expect(node).toHaveClass('navbar');
expect(node).toHaveClass('navbar-expand-sm');
expect(node).toHaveClass('navbar-light');
expect(node).toHaveClass('navbar-dark');
expect(node).toHaveClass('fixed-top');
expect(node).toHaveClass('sticky-top');
});
});

View File

@@ -0,0 +1,16 @@
import { NavbarText } from '..';
import { testForDefaultClass, testForCustomTag, testForChildrenInComponent, testForCustomClass } from '../testUtils';
describe('NavbarText', function () {
it('should render .navbar-text markup', function () {
testForDefaultClass(NavbarText, 'navbar-text');
});
it('should render custom tag', function () {
testForCustomTag(NavbarText);
});
it('should render children', function () {
testForChildrenInComponent(NavbarText);
});
it('should pass additional classNames', function () {
testForCustomClass(NavbarText);
});
});

View File

@@ -0,0 +1,16 @@
import { NavbarToggler } from '..';
import { testForChildrenInComponent, testForCustomClass, testForCustomTag, testForDefaultClass } from '../testUtils';
describe('NavbarToggler', function () {
it('should have .navbar-toggler class', function () {
testForDefaultClass(NavbarToggler, 'navbar-toggler');
});
it('should render custom tag', function () {
testForCustomTag(NavbarToggler);
});
it('should render children instead of navbar-toggler-icon ', function () {
testForChildrenInComponent(NavbarToggler);
});
it('should pass additional classNames', function () {
testForCustomClass(NavbarToggler);
});
});

619
node_modules/reactstrap/esm/__tests__/Offcanvas.spec.js generated vendored Normal file
View File

@@ -0,0 +1,619 @@
/* eslint-disable jsx-a11y/no-noninteractive-tabindex */
import React from 'react';
import { render, screen } from '@testing-library/react';
import user from '@testing-library/user-event';
import '@testing-library/jest-dom';
import { Offcanvas, OffcanvasBody, OffcanvasHeader, Button } from '..';
import { testForCustomClass } from '../testUtils';
describe('Offcanvas', function () {
var toggle;
beforeEach(function () {
toggle = function toggle() {};
jest.useFakeTimers();
});
afterEach(function () {
jest.clearAllTimers();
document.body.removeAttribute('style');
});
it('should render offcanvas portal into DOM', function () {
render( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true,
toggle: toggle
}, "Yo!"));
jest.advanceTimersByTime(300);
expect(screen.getByText(/yo/i)).toBeInTheDocument();
});
it('should render with the class "offcanvas"', function () {
render( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true,
toggle: toggle
}, "Yo!"));
expect(screen.getByText(/yo/i)).toHaveClass('offcanvas');
});
it('should render with the backdrop with the class "offcanvas-backdrop" by default', function () {
render( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true,
toggle: toggle
}, "Yo!"));
expect(document.getElementsByClassName('offcanvas-backdrop')).toHaveLength(1);
});
it('should not render with the backdrop with the class "offcanvas-backdrop" when backdrop is "false"', function () {
render( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true,
toggle: toggle,
backdrop: false
}, "Yo!"));
expect(document.getElementsByClassName('offcanvas').length).toBe(1);
expect(document.getElementsByClassName('offcanvas-backdrop').length).toBe(0);
});
it('should have custom class name if provided', function () {
testForCustomClass(Offcanvas, {
isOpen: true,
toggle: toggle
});
});
it('should render with additional props if provided', function () {
render( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true,
toggle: toggle,
style: {
maxWidth: '95%'
}
}, "Yo!"));
expect(document.getElementsByClassName('offcanvas')[0].style.maxWidth).toBe('95%');
});
it('should render without fade transition if provided with fade={false}', function () {
render( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true,
toggle: toggle,
fade: false,
className: "fadeless-offcanvas"
}, "Howdy!"));
expect(document.getElementsByClassName('fadeless-offcanvas')[0]).not.toHaveClass('fade');
});
it('should render when expected when passed offcanvasTransition and backdropTransition props', function () {
render( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true,
toggle: toggle,
offcanvasTransition: {
timeout: 2
},
backdropTransition: {
timeout: 10
},
className: "custom-timeout-offcanvas"
}, "Hello, world!"));
expect(document.getElementsByClassName('custom-timeout-offcanvas')[0]).toHaveClass('fade');
expect(document.getElementsByClassName('custom-timeout-offcanvas')[0]).not.toHaveClass('show');
expect(document.getElementsByClassName('offcanvas-backdrop')[0]).not.toHaveClass('show');
jest.advanceTimersByTime(20);
expect(document.getElementsByClassName('custom-timeout-offcanvas')[0]).toHaveClass('show');
expect(document.getElementsByClassName('offcanvas-backdrop')[0]).toHaveClass('show');
});
it('should render with class "offcanvas-backdrop" and have custom class name if provided with backdropClassName', function () {
render( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true,
toggle: toggle,
backdropClassName: "my-custom-offcanvas"
}, "Yo!"));
expect(document.getElementsByClassName('offcanvas-backdrop my-custom-offcanvas')[0]).toBeInTheDocument();
});
it('should render with the class "offcanvas-${direction}" when direction is passed', function () {
render( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true,
toggle: toggle,
direction: "top"
}, "Yo!"));
expect(screen.getByText(/yo/i)).toHaveClass('offcanvas-top');
});
it('should render offcanvas when isOpen is true', function () {
render( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true,
toggle: toggle
}, "Yo!"));
expect(screen.getByText(/yo/i)).toHaveClass('offcanvas');
expect(document.getElementsByClassName('offcanvas-backdrop').length).toBe(1);
});
it('should render offcanvas with default role of "dialog"', function () {
render( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true,
toggle: toggle
}, "Yo!"));
expect(screen.getByText(/yo/i).getAttribute('role')).toBe('dialog');
});
it('should render offcanvas with provided role', function () {
render( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true,
toggle: toggle,
role: "alert"
}, "Yo!"));
expect(screen.getByText(/yo/i).getAttribute('role')).toBe('alert');
});
it('should render offcanvas with aria-labelledby provided labelledBy', function () {
render( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true,
toggle: toggle,
labelledBy: "myOffcanvasTitle"
}, "Yo!"));
expect(screen.getByText(/yo/i).getAttribute('aria-labelledby')).toBe('myOffcanvasTitle');
});
it('should not render offcanvas when isOpen is false', function () {
render( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: false,
toggle: toggle
}, "Yo!"));
expect(screen.queryByText(/yo/i)).not.toBeInTheDocument();
});
it('should toggle offcanvas', function () {
var _render = render( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: false,
toggle: toggle
}, "Yo!")),
rerender = _render.rerender;
expect(screen.queryByText(/yo/i)).not.toBeInTheDocument();
rerender( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true,
toggle: toggle
}, "Yo!"));
expect(screen.queryByText(/yo/i)).toBeInTheDocument();
rerender( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true,
toggle: toggle
}, "Yo!"));
expect(screen.queryByText(/yo/i)).toBeInTheDocument();
});
it('should call onClosed & onOpened', function () {
var onOpened = jest.fn();
var onClosed = jest.fn();
var _render2 = render( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: false,
onOpened: onOpened,
onClosed: onClosed,
toggle: toggle
}, "Yo!")),
rerender = _render2.rerender;
expect(onOpened).not.toHaveBeenCalled();
expect(onClosed).not.toHaveBeenCalled();
rerender( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true,
onOpened: onOpened,
onClosed: onClosed,
toggle: toggle
}, "Yo!"));
jest.advanceTimersByTime(300);
expect(onOpened).toHaveBeenCalledTimes(1);
expect(onClosed).not.toHaveBeenCalled();
onOpened.mockClear();
onClosed.mockClear();
rerender( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: false,
onOpened: onOpened,
onClosed: onClosed,
toggle: toggle
}, "Yo!"));
jest.advanceTimersByTime(300);
expect(onClosed).toHaveBeenCalledTimes(1);
expect(onOpened).not.toHaveBeenCalled();
});
it('should call onClosed & onOpened when fade={false}', function () {
var onOpened = jest.fn();
var onClosed = jest.fn();
var _render3 = render( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: false,
onOpened: onOpened,
onClosed: onClosed,
toggle: toggle,
fade: false
}, "Yo!")),
rerender = _render3.rerender;
expect(onOpened).not.toHaveBeenCalled();
expect(onClosed).not.toHaveBeenCalled();
rerender( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true,
onOpened: onOpened,
onClosed: onClosed,
toggle: toggle,
fade: false
}, "Yo!"));
jest.advanceTimersByTime(300);
expect(onOpened).toHaveBeenCalledTimes(1);
expect(onClosed).not.toHaveBeenCalled();
onOpened.mockClear();
onClosed.mockClear();
rerender( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: false,
onOpened: onOpened,
onClosed: onClosed,
toggle: toggle,
fade: false
}, "Yo!"));
jest.advanceTimersByTime(300);
expect(onClosed).toHaveBeenCalledTimes(1);
expect(onOpened).not.toHaveBeenCalled();
});
it('should call toggle when escape key pressed', function () {
var toggle = jest.fn();
render( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true,
toggle: toggle
}, "Yo!"));
user.keyboard('{esc}');
expect(toggle).toHaveBeenCalled();
});
it('should not call toggle when escape key pressed when keyboard is false', function () {
var toggle = jest.fn();
render( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true,
toggle: toggle,
keyboard: false
}, "Yo!"));
user.keyboard('{esc}');
expect(toggle).not.toHaveBeenCalled();
});
it('should call toggle when clicking backdrop', function () {
var toggle = jest.fn();
render( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true,
toggle: toggle
}, /*#__PURE__*/React.createElement("button", {
id: "clicker"
}, "Does Nothing")));
user.click(screen.getByText(/does nothing/i));
expect(toggle).not.toHaveBeenCalled();
user.click(document.getElementsByClassName('offcanvas-backdrop')[0]);
expect(toggle).toHaveBeenCalled();
});
it('should call toggle when clicking backdrop when fade is false', function () {
var toggle = jest.fn();
render( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true,
toggle: toggle,
fade: false
}, /*#__PURE__*/React.createElement("button", {
id: "clicker"
}, "Does Nothing")));
user.click(screen.getByText(/does nothing/i));
expect(toggle).not.toHaveBeenCalled();
user.click(document.getElementsByClassName('offcanvas-backdrop')[0]);
expect(toggle).toHaveBeenCalled();
});
it('should destroy this._element', function () {
var _render4 = render( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true,
toggle: toggle
}, "thor and dr.johns")),
rerender = _render4.rerender;
var element = screen.getByText(/thor and dr.johns/i);
expect(element).toBeInTheDocument();
rerender( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: false,
toggle: toggle
}, "thor and dr.johns"));
jest.advanceTimersByTime(300);
expect(element).not.toBeInTheDocument();
});
it('should destroy this._element when unmountOnClose prop set to true', function () {
var _render5 = render( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true,
toggle: toggle,
unmountOnClose: true
}, "thor and dr.johns")),
rerender = _render5.rerender;
var element = screen.getByText(/thor and dr.johns/i);
expect(element).toBeInTheDocument();
rerender( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: false,
toggle: toggle,
unmountOnClose: true
}, "thor and dr.johns"));
jest.advanceTimersByTime(300);
expect(element).not.toBeInTheDocument();
});
it('should not destroy this._element when unmountOnClose prop set to false', function () {
var _render6 = render( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true,
toggle: toggle,
unmountOnClose: false
}, "thor and dr.johns")),
rerender = _render6.rerender;
var element = screen.getByText(/thor and dr.johns/i);
expect(element).toBeInTheDocument();
rerender( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: false,
toggle: toggle,
unmountOnClose: false
}, "thor and dr.johns"));
jest.advanceTimersByTime(300);
expect(element).toBeInTheDocument();
});
it('should destroy this._element on unmount', function () {
var _render7 = render( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true,
toggle: toggle
}, "thor and dr.johns")),
unmount = _render7.unmount;
var element = screen.getByText(/thor and dr.johns/i);
expect(element).toBeInTheDocument();
unmount();
jest.advanceTimersByTime(300);
expect(element).not.toBeInTheDocument();
});
it('should remove exactly visibility styles from body', function () {
// set a body class which includes offcanvas-open
document.body.style.background = 'blue';
var _render8 = render( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: false,
toggle: toggle
}, "Yo!")),
rerender = _render8.rerender;
// assert that the offcanvas is closed and the body class is what was set initially
jest.advanceTimersByTime(300);
expect(document.body.style.background).toBe('blue');
expect(document.body.style.overflow).toBe('');
rerender( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true,
toggle: toggle
}, "Yo!"));
// assert that the offcanvas is open and the body class is what was set initially + offcanvas-open
jest.advanceTimersByTime(300);
expect(document.body.style.background).toBe('blue');
expect(document.body.style.overflow).toBe('hidden');
// append another body class which includes offcanvas-open
// using this to test if replace will leave a space when removing offcanvas-open
document.body.style.color = 'red';
expect(document.body.style.background).toBe('blue');
expect(document.body.style.color).toBe('red');
expect(document.body.style.overflow).toBe('hidden');
rerender( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: false,
toggle: toggle
}, "Yo!"));
// assert that the offcanvas is closed and the body class is what was set initially
jest.advanceTimersByTime(301);
expect(document.body.style.background).toBe('blue');
expect(document.body.style.color).toBe('red');
expect(document.body.style.overflow).toBe('');
});
it('should call onEnter & onExit props if provided', function () {
var onEnter = jest.fn();
var onExit = jest.fn();
var _render9 = render( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: false,
onEnter: onEnter,
onExit: onExit,
toggle: toggle
}, "Yo!")),
rerender = _render9.rerender,
unmount = _render9.unmount;
expect(onEnter).toHaveBeenCalled();
expect(onExit).not.toHaveBeenCalled();
onEnter.mockReset();
onExit.mockReset();
rerender( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true,
onEnter: onEnter,
onExit: onExit,
toggle: toggle
}, "Yo!"));
jest.advanceTimersByTime(300);
expect(onEnter).not.toHaveBeenCalled();
expect(onExit).not.toHaveBeenCalled();
onEnter.mockReset();
onExit.mockReset();
unmount();
expect(onEnter).not.toHaveBeenCalled();
expect(onExit).toHaveBeenCalled();
});
it('should update element z index when prop changes', function () {
var _render10 = render( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true,
zIndex: 0
}, "Yo!")),
rerender = _render10.rerender;
expect(screen.getByText(/yo/i).parentElement).toHaveStyle('z-index: 0');
rerender( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true,
zIndex: 1
}, "Yo!"));
expect(screen.getByText(/yo/i).parentElement).toHaveStyle('z-index: 1');
});
it('should allow focus on only focusable elements', function () {
render( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true,
toggle: toggle
}, /*#__PURE__*/React.createElement(OffcanvasHeader, {
toggle: toggle
}, "Offcanvas title"), /*#__PURE__*/React.createElement(OffcanvasBody, null, /*#__PURE__*/React.createElement("a", {
alt: "test",
href: "/"
}, "First Test"), /*#__PURE__*/React.createElement("map", {
name: "test"
}, /*#__PURE__*/React.createElement("area", {
alt: "test",
href: "/",
coords: "200,5,200,30"
})), /*#__PURE__*/React.createElement("input", {
type: "text",
"aria-label": "test text input"
}), /*#__PURE__*/React.createElement("input", {
type: "hidden"
}), /*#__PURE__*/React.createElement("input", {
type: "text",
disabled: true,
value: "Test"
}), /*#__PURE__*/React.createElement("select", {
name: "test",
id: "select_test"
}, /*#__PURE__*/React.createElement("option", null, "Second item")), /*#__PURE__*/React.createElement("select", {
name: "test",
id: "select_test_disabled",
disabled: true
}, /*#__PURE__*/React.createElement("option", null, "Third item")), /*#__PURE__*/React.createElement("textarea", {
name: "textarea_test",
id: "textarea_test",
cols: "30",
rows: "10",
"aria-label": "test text area"
}), /*#__PURE__*/React.createElement("textarea", {
name: "textarea_test_disabled",
id: "textarea_test_disabled",
cols: "30",
rows: "10",
disabled: true
}), /*#__PURE__*/React.createElement("object", null, "Test"), /*#__PURE__*/React.createElement("span", {
tabIndex: "0"
}, "test tab index"))));
user.tab();
expect(screen.getByLabelText(/close/i)).toHaveFocus();
user.tab();
expect(screen.getByText(/first test/i)).toHaveFocus();
user.tab();
expect(screen.getByLabelText(/test text input/i)).toHaveFocus();
user.tab();
expect(screen.getByText(/second item/i).parentElement).toHaveFocus();
user.tab();
expect(screen.getByLabelText(/test text area/i)).toHaveFocus();
user.tab();
expect(screen.getByText(/test tab index/i)).toHaveFocus();
user.tab();
expect(screen.getByLabelText(/close/i)).toHaveFocus();
});
it('should return the focus to the last focused element before the offcanvas has opened', function () {
var _render11 = render( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
className: "focus"
}, "Focused"), /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: false
}, /*#__PURE__*/React.createElement(OffcanvasBody, null, "Whatever")))),
rerender = _render11.rerender;
user.tab();
expect(screen.getByText(/focused/i)).toHaveFocus();
rerender( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
className: "focus"
}, "Focused"), /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true
}, /*#__PURE__*/React.createElement(OffcanvasBody, null, "Whatever"))));
expect(screen.getByText(/focused/i)).not.toHaveFocus();
rerender( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
className: "focus"
}, "Focused"), /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: false
}, /*#__PURE__*/React.createElement(OffcanvasBody, null, "Whatever"))));
jest.runAllTimers();
expect(screen.getByText(/focused/i)).toHaveFocus();
});
it('should not return the focus to the last focused element before the offcanvas has opened when "returnFocusAfterClose" is false', function () {
var _render12 = render( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
className: "focus"
}, "Focused"), /*#__PURE__*/React.createElement(Offcanvas, {
returnFocusAfterClose: false,
isOpen: false
}, /*#__PURE__*/React.createElement(OffcanvasBody, null, "Whatever")))),
rerender = _render12.rerender;
user.tab();
expect(screen.getByText(/focused/i)).toHaveFocus();
rerender( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
className: "focus"
}, "Focused"), /*#__PURE__*/React.createElement(Offcanvas, {
returnFocusAfterClose: false,
isOpen: true
}, /*#__PURE__*/React.createElement(OffcanvasBody, null, "Whatever"))));
expect(screen.getByText(/focused/i)).not.toHaveFocus();
rerender( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
className: "focus"
}, "Focused"), /*#__PURE__*/React.createElement(Offcanvas, {
returnFocusAfterClose: false,
isOpen: false
}, /*#__PURE__*/React.createElement(OffcanvasBody, null, "Whatever"))));
jest.runAllTimers();
expect(screen.getByText(/focused/i)).not.toHaveFocus();
});
it('should return the focus to the last focused element before the offcanvas has opened when "unmountOnClose" is false', function () {
var _render13 = render( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
className: "focus"
}, "Focused"), /*#__PURE__*/React.createElement(Offcanvas, {
unmountOnClose: false,
isOpen: false
}, /*#__PURE__*/React.createElement(OffcanvasBody, null, "Whatever")))),
rerender = _render13.rerender;
user.tab();
expect(screen.getByText(/focused/i)).toHaveFocus();
rerender( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
className: "focus"
}, "Focused"), /*#__PURE__*/React.createElement(Offcanvas, {
unmountOnClose: false,
isOpen: true
}, /*#__PURE__*/React.createElement(OffcanvasBody, null, "Whatever"))));
expect(screen.getByText(/focused/i)).not.toHaveFocus();
rerender( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
className: "focus"
}, "Focused"), /*#__PURE__*/React.createElement(Offcanvas, {
unmountOnClose: false,
isOpen: false
}, /*#__PURE__*/React.createElement(OffcanvasBody, null, "Whatever"))));
jest.runAllTimers();
expect(screen.getByText(/focused/i)).toHaveFocus();
});
it('should not return the focus to the last focused element before the offcanvas has opened when "returnFocusAfterClose" is false and "unmountOnClose" is false', function () {
var _render14 = render( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
className: "focus"
}, "Focused"), /*#__PURE__*/React.createElement(Offcanvas, {
returnFocusAfterClose: false,
unmountOnClose: false,
isOpen: false
}, /*#__PURE__*/React.createElement(OffcanvasBody, null, "Whatever")))),
rerender = _render14.rerender;
user.tab();
expect(screen.getByText(/focused/i)).toHaveFocus();
rerender( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
className: "focus"
}, "Focused"), /*#__PURE__*/React.createElement(Offcanvas, {
returnFocusAfterClose: false,
unmountOnClose: false,
isOpen: true
}, /*#__PURE__*/React.createElement(OffcanvasBody, null, "Whatever"))));
expect(screen.getByText(/focused/i)).not.toHaveFocus();
rerender( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement("button", {
className: "focus"
}, "Focused"), /*#__PURE__*/React.createElement(Offcanvas, {
returnFocusAfterClose: false,
unmountOnClose: false,
isOpen: false
}, /*#__PURE__*/React.createElement(OffcanvasBody, null, "Whatever"))));
jest.runAllTimers();
expect(screen.getByText(/focused/i)).not.toHaveFocus();
});
it('should attach/detach trapFocus for dialogs', function () {
var addEventListener = jest.spyOn(document, 'addEventListener');
var removeEventListener = jest.spyOn(document, 'removeEventListener');
var _render15 = render( /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true,
toggle: toggle
}, "Yo!")),
unmount = _render15.unmount;
expect(addEventListener).toHaveBeenCalledTimes(1);
expect(addEventListener).toHaveBeenCalledWith('focus', expect.any(Function), true);
unmount();
expect(removeEventListener).toHaveBeenCalledTimes(1);
expect(removeEventListener).toHaveBeenCalledWith('focus', expect.any(Function), true);
addEventListener.mockRestore();
removeEventListener.mockRestore();
});
it('should trap focus inside the open dialog', function () {
render( /*#__PURE__*/React.createElement(React.Fragment, null, /*#__PURE__*/React.createElement(Button, {
className: "first"
}, "Focused"), /*#__PURE__*/React.createElement(Offcanvas, {
isOpen: true,
trapFocus: true
}, /*#__PURE__*/React.createElement(OffcanvasBody, null, "Something else to see", /*#__PURE__*/React.createElement(Button, {
className: "focus"
}, "focusable element")))));
user.tab();
expect(screen.getByText(/focusable element/i)).toHaveFocus();
user.tab();
expect(screen.getByText(/focusable element/i)).toHaveFocus();
});
});

View File

@@ -0,0 +1,13 @@
import { OffcanvasBody } from '..';
import { testForCustomClass, testForCustomTag, testForDefaultClass } from '../testUtils';
describe('OffcanvasBody', function () {
it('should render with "offcanvas-body" class', function () {
testForDefaultClass(OffcanvasBody, 'offcanvas-body ');
});
it('should render additional classes', function () {
testForCustomClass(OffcanvasBody);
});
it('should render custom tag', function () {
testForCustomTag(OffcanvasBody);
});
});

View File

@@ -0,0 +1,34 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { OffcanvasHeader } from '..';
import { testForCustomClass, testForDefaultClass } from '../testUtils';
describe('OffcanvasHeader', function () {
it('should render with "offcanvas-header" class', function () {
testForDefaultClass(OffcanvasHeader, 'offcanvas-header');
});
it('should render additional classes', function () {
testForCustomClass(OffcanvasHeader);
});
it('should render close button', function () {
render( /*#__PURE__*/React.createElement(OffcanvasHeader, {
toggle: function toggle() {},
"data-testid": "test",
className: "other"
}, "Yo!"));
var node = screen.getByTestId('test').querySelector('button');
expect(node.tagName.toLowerCase()).toBe('button');
expect(node).toHaveClass('btn-close');
});
it('should render custom tag', function () {
render( /*#__PURE__*/React.createElement(OffcanvasHeader, {
tag: "h1"
}, "Yo!"));
expect(screen.getByText(/yo!/i).tagName.toLowerCase()).toMatch('h1');
});
it('should render custom wrapping tag', function () {
render( /*#__PURE__*/React.createElement(OffcanvasHeader, {
wrapTag: "main"
}, "Yo!"));
expect(screen.getByText(/yo/i).parentElement.tagName).toMatch(/main/i);
});
});

View File

@@ -0,0 +1,48 @@
import React from 'react';
import { screen, render } from '@testing-library/react';
import { Pagination } from '..';
import { testForChildrenInComponent } from '../testUtils';
describe('Pagination', function () {
it('should render "nav" tag by default', function () {
render( /*#__PURE__*/React.createElement(Pagination, {
"data-testid": "test"
}));
var node = screen.getByLabelText('pagination');
expect(node.tagName.toLowerCase()).toMatch('nav');
});
it('should render default list tag', function () {
render( /*#__PURE__*/React.createElement(Pagination, null));
expect(screen.getByLabelText('pagination').querySelector('ul')).toBeInTheDocument();
});
it('should render custom tag', function () {
render( /*#__PURE__*/React.createElement(Pagination, {
tag: "main"
}));
expect(screen.getByLabelText('pagination').tagName.toLowerCase()).toBe('main');
});
it('should render with "pagination" class', function () {
render( /*#__PURE__*/React.createElement(Pagination, {
"data-testid": "pagination"
}));
expect(screen.getByTestId('pagination')).toHaveClass('pagination');
});
it('should render children', function () {
testForChildrenInComponent(Pagination);
});
describe('should render pagination at different sizes', function () {
it('should render with sm', function () {
render( /*#__PURE__*/React.createElement(Pagination, {
size: "sm",
"data-testid": "pagination"
}));
expect(screen.getByTestId('pagination')).toHaveClass('pagination-sm');
});
it('should render lg', function () {
render( /*#__PURE__*/React.createElement(Pagination, {
size: "lg",
"data-testid": "pagination"
}));
expect(screen.getByTestId('pagination')).toHaveClass('pagination-lg');
});
});
});

View File

@@ -0,0 +1,27 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { PaginationItem } from '..';
import { testForCustomTag, testForDefaultClass, testForDefaultTag } from '../testUtils';
describe('PaginationItem', function () {
it('should render default tag', function () {
testForDefaultTag(PaginationItem, 'li');
});
it('should render custom tag', function () {
testForCustomTag(PaginationItem);
});
it('should render with "page-item" class', function () {
testForDefaultClass(PaginationItem, 'page-item');
});
it('should render active state', function () {
render( /*#__PURE__*/React.createElement(PaginationItem, {
active: true
}, "hello"));
expect(screen.getByText('hello')).toHaveClass('active');
});
it('should render disabled state', function () {
render( /*#__PURE__*/React.createElement(PaginationItem, {
disabled: true
}, "hello"));
expect(screen.getByText('hello')).toHaveClass('disabled');
});
});

View File

@@ -0,0 +1,111 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { PaginationLink } from '..';
import { testForCustomTag, testForDefaultClass, testForDefaultTag } from '../testUtils';
describe('PaginationLink', function () {
it('should render default `a` tag when `href` is present', function () {
render( /*#__PURE__*/React.createElement(PaginationLink, {
href: "#",
"data-testid": "endless"
}));
expect(screen.getByTestId('endless').tagName).toBe('A');
});
it('should render default `button` tag when no `href` is present', function () {
testForDefaultTag(PaginationLink, 'button');
});
it('should render custom tag', function () {
testForCustomTag(PaginationLink, {}, 'span');
});
it('should render with "page-link" class', function () {
testForDefaultClass(PaginationLink, 'page-link');
});
it('should render previous', function () {
render( /*#__PURE__*/React.createElement(PaginationLink, {
previous: true
}));
expect(screen.getByLabelText('Previous')).toBeInTheDocument();
expect(screen.getByText('Previous')).toHaveClass('visually-hidden');
expect(screen.getByText("\u2039")).toHaveAttribute('aria-hidden', 'true');
});
it('should render next', function () {
render( /*#__PURE__*/React.createElement(PaginationLink, {
next: true
}));
expect(screen.getByLabelText('Next')).toBeInTheDocument();
expect(screen.getByText('Next')).toHaveClass('visually-hidden');
expect(screen.getByText("\u203A")).toHaveAttribute('aria-hidden', 'true');
});
it('should render default previous caret with children as an empty array', function () {
render( /*#__PURE__*/React.createElement(PaginationLink, {
previous: true,
children: []
}));
expect(screen.getByLabelText('Previous')).toBeInTheDocument();
expect(screen.getByText('Previous')).toHaveClass('visually-hidden');
expect(screen.getByText("\u2039")).toHaveAttribute('aria-hidden', 'true');
});
it('should render default next caret with children as an empty array', function () {
render( /*#__PURE__*/React.createElement(PaginationLink, {
next: true,
children: []
}));
expect(screen.getByLabelText('Next')).toBeInTheDocument();
expect(screen.getByText('Next')).toHaveClass('visually-hidden');
expect(screen.getByText("\u203A")).toHaveAttribute('aria-hidden', 'true');
});
it('should render custom aria label', function () {
render( /*#__PURE__*/React.createElement(PaginationLink, {
next: true,
"aria-label": "Yo"
}));
expect(screen.getByLabelText('Yo')).toBeInTheDocument();
expect(screen.getByText('Yo')).toHaveClass('visually-hidden');
});
it('should render custom caret specified as a string', function () {
render( /*#__PURE__*/React.createElement(PaginationLink, {
next: true
}, "Yo"));
expect(screen.getByText('Yo')).toBeInTheDocument();
});
it('should render custom caret specified as a component', function () {
render( /*#__PURE__*/React.createElement(PaginationLink, {
next: true
}, /*#__PURE__*/React.createElement("span", null, "Yo")));
expect(screen.getByText('Yo')).toBeInTheDocument();
expect(screen.getByText('Yo').tagName).toBe('SPAN');
});
it('should render first', function () {
render( /*#__PURE__*/React.createElement(PaginationLink, {
first: true
}));
expect(screen.getByLabelText('First')).toBeInTheDocument();
expect(screen.getByText('First')).toHaveClass('visually-hidden');
expect(screen.getByText("\xAB")).toHaveAttribute('aria-hidden', 'true');
});
it('should render last', function () {
render( /*#__PURE__*/React.createElement(PaginationLink, {
last: true
}));
expect(screen.getByLabelText('Last')).toBeInTheDocument();
expect(screen.getByText('Last')).toHaveClass('visually-hidden');
expect(screen.getByText("\xBB")).toHaveAttribute('aria-hidden', 'true');
});
it('should render default first caret with children as an empty array', function () {
render( /*#__PURE__*/React.createElement(PaginationLink, {
first: true,
children: []
}));
expect(screen.getByLabelText('First')).toBeInTheDocument();
expect(screen.getByText('First')).toHaveClass('visually-hidden');
expect(screen.getByText("\xAB")).toHaveAttribute('aria-hidden', 'true');
});
it('should render default last caret with children as an empty array', function () {
render( /*#__PURE__*/React.createElement(PaginationLink, {
last: true,
children: []
}));
expect(screen.getByLabelText('Last')).toBeInTheDocument();
expect(screen.getByText('Last')).toHaveClass('visually-hidden');
expect(screen.getByText("\xBB")).toHaveAttribute('aria-hidden', 'true');
});
});

View File

@@ -0,0 +1,79 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { Placeholder } from '..';
import { testForDefaultClass } from '../testUtils';
describe('Placeholder', function () {
it('should render with "placeholder" class', function () {
testForDefaultClass(Placeholder, 'placeholder');
});
it('should render column size', function () {
render( /*#__PURE__*/React.createElement(Placeholder, {
"data-testid": "test",
xs: 7
}));
expect(screen.getByTestId('test')).toHaveClass('col-7');
});
it('should render animation', function () {
render( /*#__PURE__*/React.createElement(Placeholder, {
"data-testid": "test",
tag: "p",
animation: "glow"
}));
expect(screen.getByTestId('test')).toHaveClass('placeholder-glow');
});
it('should render color', function () {
render( /*#__PURE__*/React.createElement(Placeholder, {
"data-testid": "test",
xs: 12,
color: "primary"
}));
expect(screen.getByTestId('test')).toHaveClass('bg-primary');
});
it('should render size', function () {
render( /*#__PURE__*/React.createElement(Placeholder, {
"data-testid": "test",
size: "lg",
xs: 12
}));
expect(screen.getByTestId('test')).toHaveClass('placeholder-lg');
});
it('should render different widths for different breakpoints', function () {
render( /*#__PURE__*/React.createElement(Placeholder, {
"data-testid": "test",
size: "lg",
xs: 12,
lg: 8
}));
var node = screen.getByTestId('test');
expect(node).toHaveClass('col-lg-8');
expect(node).toHaveClass('col-12');
});
it('should allow custom columns to be defined', function () {
render( /*#__PURE__*/React.createElement(Placeholder, {
"data-testid": "test",
widths: ['base', 'jumbo'],
base: "4",
jumbo: "6"
}));
var node = screen.getByTestId('test');
expect(node).toHaveClass('col-4');
expect(node).toHaveClass('col-jumbo-6');
});
it('should allow custom columns to be defined with objects', function () {
render( /*#__PURE__*/React.createElement(Placeholder, {
"data-testid": "test",
widths: ['base', 'jumbo', 'custom'],
custom: {
size: 1,
order: 2,
offset: 4
}
}));
var node = screen.getByTestId('test');
expect(node).toHaveClass('col-custom-1');
expect(node).toHaveClass('order-custom-2');
expect(node).toHaveClass('offset-custom-4');
expect(node).not.toHaveClass('col');
});
});

View File

@@ -0,0 +1,19 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { PlaceholderButton } from '..';
import '@testing-library/jest-dom';
describe('PlaceholderButton', function () {
it('should render a placeholder', function () {
render( /*#__PURE__*/React.createElement(PlaceholderButton, {
"data-testid": "endless"
}));
expect(screen.getByTestId('endless')).toBeInTheDocument();
});
it('should render size', function () {
render( /*#__PURE__*/React.createElement(PlaceholderButton, {
"data-testid": "endless",
xs: 6
}));
expect(screen.getByTestId('endless')).toHaveClass('col-6');
});
});

32
node_modules/reactstrap/esm/__tests__/Popover.spec.js generated vendored Normal file
View File

@@ -0,0 +1,32 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import Popover from '../Popover';
describe('Popover', function () {
var element;
beforeEach(function () {
element = document.createElement('div');
element.setAttribute('id', 'popover-target');
document.body.appendChild(element);
});
afterEach(function () {
document.body.removeChild(element);
});
it('should apply popperClassName to popper component', function () {
var _screen$queryByText;
render( /*#__PURE__*/React.createElement(Popover, {
target: "popover-target",
popperClassName: "boba-was-here",
isOpen: true
}, "Bo-Katan Kryze"));
expect((_screen$queryByText = screen.queryByText('Bo-Katan Kryze')) === null || _screen$queryByText === void 0 ? void 0 : _screen$queryByText.parentElement).toHaveClass('popover show boba-was-here');
});
it('should apply arrowClassName to arrow', function () {
render( /*#__PURE__*/React.createElement(Popover, {
target: "popover-target",
arrowClassName: "boba-was-here",
isOpen: true
}, "Bo-Katan Kryze"));
expect(document.querySelector('.arrow')).toHaveClass('boba-was-here');
});
});

View File

@@ -0,0 +1,8 @@
import React from 'react';
import { testForChildrenInComponent } from '../testUtils';
import { PopoverBody } from '..';
describe('PopoverBody', function () {
it('should render children', function () {
testForChildrenInComponent(PopoverBody);
});
});

View File

@@ -0,0 +1,8 @@
import React from 'react';
import { testForChildrenInComponent } from '../testUtils';
import { PopoverHeader } from '..';
describe('PopoverHeader', function () {
it('should render children', function () {
testForChildrenInComponent(PopoverHeader);
});
});

View File

@@ -0,0 +1,172 @@
import React from 'react';
import { Popper } from 'react-popper';
import '@testing-library/jest-dom';
import { render, screen } from '@testing-library/react';
import { PopperContent } from '..';
describe('PopperContent', function () {
var element;
beforeEach(function () {
element = document.createElement('div');
element.innerHTML = '<p id="outerTarget">This is the popover <span id="target">target</span>.</p>';
document.body.appendChild(element);
jest.useFakeTimers();
});
afterEach(function () {
jest.clearAllTimers();
document.body.removeChild(element);
element = null;
});
it('should NOT render children when isOpen is false', function () {
render( /*#__PURE__*/React.createElement(PopperContent, {
target: "target"
}, "Yo!"));
expect(screen.queryByText('Yo!')).not.toBeInTheDocument();
});
it('should render children when isOpen is true and container is inline', function () {
render( /*#__PURE__*/React.createElement(PopperContent, {
target: "target",
isOpen: true
}, "Yo!"));
expect(screen.queryByText('Yo!')).toBeInTheDocument();
});
it('should render children when isOpen is true and container is inline and DOM node passed directly for target', function () {
var targetElement = element.querySelector('#target');
render( /*#__PURE__*/React.createElement(PopperContent, {
target: targetElement,
isOpen: true,
container: "inline"
}, "Yo!"));
expect(screen.queryByText('Yo!')).toBeInTheDocument();
});
it('should render an Arrow in the Popper when isOpen is true and container is inline', function () {
var _render = render( /*#__PURE__*/React.createElement(PopperContent, {
target: "target",
isOpen: true,
container: "inline",
arrowClassName: "custom-arrow"
}, "Yo!")),
container = _render.container;
expect(container.querySelector('.arrow.custom-arrow')).toBeInTheDocument();
});
it('should NOT render an Arrow in the Popper when "hideArrow" is truthy', function () {
var _render2 = render( /*#__PURE__*/React.createElement(PopperContent, {
target: "target",
isOpen: true,
container: "inline",
arrowClassName: "custom-arrow",
hideArrow: true
}, "Yo!")),
container = _render2.container;
expect(container.querySelector('.arrow.custom-arrow')).not.toBeInTheDocument();
});
it('should pass additional classNames to the popper', function () {
render( /*#__PURE__*/React.createElement(PopperContent, {
className: "extra",
target: "target",
isOpen: true,
container: "inline",
"data-testid": "rick"
}, "Yo!"));
expect(screen.getByTestId('rick')).toHaveClass('extra');
});
it('should allow custom modifiers and even allow overriding of default modifiers', function () {
render( /*#__PURE__*/React.createElement(PopperContent, {
className: "extra",
target: "target",
isOpen: true,
container: "inline",
modifiers: [{
name: 'offset',
options: {
offset: [2, 2]
}
}, {
name: 'preventOverflow',
options: {
boundary: 'viewport'
}
}]
}, "Yo!"));
expect(Popper).toHaveBeenCalledWith(expect.objectContaining({
modifiers: expect.arrayContaining([expect.objectContaining({
name: 'offset',
options: {
offset: [2, 2]
}
}), expect.objectContaining({
name: 'preventOverflow',
options: {
boundary: 'viewport'
}
})])
}), {});
});
it('should have data-popper-placement of auto by default', function () {
var _render3 = render( /*#__PURE__*/React.createElement(PopperContent, {
target: "target",
isOpen: true,
container: "inline"
}, "Yo!")),
container = _render3.container;
expect(container.querySelector('div[data-popper-placement="auto"]')).toBeInTheDocument();
});
it('should override data-popper-placement', function () {
var _render4 = render( /*#__PURE__*/React.createElement(PopperContent, {
placement: "top",
target: "target",
isOpen: true,
container: "inline"
}, "Yo!")),
container = _render4.container;
expect(container.querySelector('div[data-popper-placement="auto"]')).not.toBeInTheDocument();
expect(container.querySelector('div[data-popper-placement="top"]')).toBeInTheDocument();
});
it('should allow for a placement prefix', function () {
render( /*#__PURE__*/React.createElement(PopperContent, {
placementPrefix: "dropdown",
target: "target",
isOpen: true,
container: "inline"
}, "Yo!"));
expect(screen.getByText('Yo!')).toHaveClass('dropdown-auto');
});
it('should allow for a placement prefix with custom placement', function () {
var _render5 = render( /*#__PURE__*/React.createElement(PopperContent, {
placementPrefix: "dropdown",
placement: "top",
target: "target",
isOpen: true,
container: "inline"
}, "Yo!")),
container = _render5.container;
expect(screen.getByText('Yo!')).toHaveClass('dropdown-auto');
expect(container.querySelector('div[data-popper-placement="top"]')).toBeInTheDocument();
});
it('should render custom tag for the popper', function () {
render( /*#__PURE__*/React.createElement(PopperContent, {
tag: "main",
target: "target",
isOpen: true,
container: "inline",
"data-testid": "morty"
}, "Yo!"));
expect(screen.getByTestId('morty').tagName.toLowerCase()).toBe('main');
});
it('should allow a function to be used as children', function () {
var renderChildren = jest.fn();
render( /*#__PURE__*/React.createElement(PopperContent, {
target: "target",
isOpen: true
}, renderChildren));
expect(renderChildren).toHaveBeenCalled();
});
it('should render children properly when children is a function', function () {
render( /*#__PURE__*/React.createElement(PopperContent, {
target: "target",
isOpen: true
}, function () {
return 'Yo!';
}));
expect(screen.queryByText('Yo!')).toBeInTheDocument();
});
});

221
node_modules/reactstrap/esm/__tests__/Progress.spec.js generated vendored Normal file
View File

@@ -0,0 +1,221 @@
import React from 'react';
import '@testing-library/jest-dom';
import { render, screen } from '@testing-library/react';
import { testForCustomTag, testForDefaultClass, testForDefaultTag } from '../testUtils';
import { Progress } from '..';
describe('Progress', function () {
it('should render with "div" tag by default', function () {
testForDefaultTag(Progress, 'div');
});
it('should render with "progress" class', function () {
testForDefaultClass(Progress, 'progress');
});
it('should render with "value" 0 by default', function () {
render( /*#__PURE__*/React.createElement(Progress, null));
expect(screen.getByRole('progressbar')).toHaveAttribute('aria-valuenow', '0');
});
it('should render with "max" 100 by default', function () {
render( /*#__PURE__*/React.createElement(Progress, null));
expect(screen.getByRole('progressbar')).toHaveAttribute('aria-valuemax', '100');
});
it('should render with "style" on the parent element', function () {
render( /*#__PURE__*/React.createElement(Progress, {
style: {
height: '20px'
},
"data-testid": "sandman"
}));
expect(getComputedStyle(screen.getByTestId('sandman')).getPropertyValue('height')).toBe('20px');
});
it('should render with "style" on the progress bar element if bar=true', function () {
render( /*#__PURE__*/React.createElement(Progress, {
bar: true,
style: {
height: '20px'
}
}));
expect(getComputedStyle(screen.getByRole('progressbar')).getPropertyValue('height')).toBe('20px');
});
it('should render "barStyle" on the progress bar element', function () {
render( /*#__PURE__*/React.createElement(Progress, {
style: {
height: '20px'
},
barStyle: {
height: '10px'
}
}));
expect(getComputedStyle(screen.getByRole('progressbar')).getPropertyValue('height')).toBe('10px');
});
it('should render with the given "value" when passed as string prop', function () {
render( /*#__PURE__*/React.createElement(Progress, {
value: "10"
}));
expect(screen.getByRole('progressbar')).toHaveAttribute('aria-valuenow', '10');
});
it('should render with the given "value" when passed as number prop', function () {
render( /*#__PURE__*/React.createElement(Progress, {
value: 10
}));
expect(screen.getByRole('progressbar')).toHaveAttribute('aria-valuenow', '10');
});
it('should render with the given "max" when passed as string prop', function () {
render( /*#__PURE__*/React.createElement(Progress, {
max: "10"
}));
expect(screen.getByRole('progressbar')).toHaveAttribute('aria-valuemax', '10');
});
it('should render with the given "max" when passed as number prop', function () {
render( /*#__PURE__*/React.createElement(Progress, {
max: 10
}));
expect(screen.getByRole('progressbar')).toHaveAttribute('aria-valuemax', '10');
});
it('should render with "progress-bar-striped" class when striped prop is truthy', function () {
render( /*#__PURE__*/React.createElement(Progress, {
striped: true
}));
expect(screen.getByRole('progressbar')).toHaveClass('progress-bar-striped');
});
it('should render with "progress-bar-striped" and "progress-bar-animated" classes when animated prop is truthy', function () {
render( /*#__PURE__*/React.createElement(Progress, {
animated: true
}));
expect(screen.getByRole('progressbar')).toHaveClass('progress-bar-striped');
expect(screen.getByRole('progressbar')).toHaveClass('progress-bar-animated');
});
it('should render with "bg-${color}" class when color prop is defined', function () {
render( /*#__PURE__*/React.createElement(Progress, {
color: "yo"
}));
expect(screen.getByRole('progressbar')).toHaveClass('bg-yo');
});
it('should render additional classes', function () {
render( /*#__PURE__*/React.createElement(Progress, {
className: "other",
"data-testid": "sandman"
}));
expect(screen.getByTestId('sandman')).toHaveClass('other');
expect(screen.getByTestId('sandman')).toHaveClass('progress');
});
it('should render additional classes on the inner progress bar', function () {
render( /*#__PURE__*/React.createElement(Progress, {
barClassName: "other",
"data-testid": "sandman"
}));
expect(screen.getByTestId('sandman')).toHaveClass('progress');
expect(screen.getByTestId('sandman')).not.toHaveClass('other');
expect(screen.getByRole('progressbar')).toHaveClass('other');
});
it('should render custom tag', function () {
testForCustomTag(Progress);
});
it('should render only the .progress when "multi" is passed', function () {
render( /*#__PURE__*/React.createElement(Progress, {
multi: true,
"data-testid": "sandman"
}));
expect(screen.getByTestId('sandman')).toHaveClass('progress');
expect(screen.getByTestId('sandman')).not.toHaveClass('progress-bar');
});
it('should render only the .progress-bar when "bar" is passed', function () {
render( /*#__PURE__*/React.createElement(Progress, {
bar: true
}));
expect(screen.getByRole('progressbar')).toHaveClass('progress-bar');
expect(screen.getByRole('progressbar')).not.toHaveClass('progress');
});
it('should render additional classes', function () {
render( /*#__PURE__*/React.createElement(Progress, {
bar: true,
className: "yo",
"data-testid": "sandman"
}));
expect(screen.getByTestId('sandman')).toHaveClass('progress-bar');
expect(screen.getByTestId('sandman')).toHaveClass('yo');
expect(screen.getByTestId('sandman')).not.toHaveClass('progress');
});
it('should render additional classes using the barClassName', function () {
render( /*#__PURE__*/React.createElement(Progress, {
bar: true,
barClassName: "yo",
"data-testid": "sandman"
}));
expect(screen.getByTestId('sandman')).toHaveClass('progress-bar');
expect(screen.getByTestId('sandman')).toHaveClass('yo');
expect(screen.getByTestId('sandman')).not.toHaveClass('progress');
});
it('should render the children (label)', function () {
render( /*#__PURE__*/React.createElement(Progress, null, "0%"));
expect(screen.getByText('0%')).toBeInTheDocument();
// expect(wrapper.text()).toBe('0%');
});
it('should render the children (label) (multi)', function () {
render( /*#__PURE__*/React.createElement(Progress, {
multi: true
}, /*#__PURE__*/React.createElement(Progress, {
bar: true,
value: "15"
}, "15%"), /*#__PURE__*/React.createElement(Progress, {
bar: true,
color: "success",
value: "30"
}, "30%"), /*#__PURE__*/React.createElement(Progress, {
bar: true,
color: "info",
value: "25"
}, "25%"), /*#__PURE__*/React.createElement(Progress, {
bar: true,
color: "warning",
value: "20"
}, "20%"), /*#__PURE__*/React.createElement(Progress, {
bar: true,
color: "danger",
value: "5"
}, "5%")));
expect(screen.getByText('15%')).toBeInTheDocument();
expect(screen.getByText('30%')).toBeInTheDocument();
expect(screen.getByText('25%')).toBeInTheDocument();
expect(screen.getByText('20%')).toBeInTheDocument();
expect(screen.getByText('5%')).toBeInTheDocument();
});
it('should render nested progress bars', function () {
render( /*#__PURE__*/React.createElement(Progress, {
multi: true,
"data-testid": "sandman"
}, /*#__PURE__*/React.createElement(Progress, {
bar: true,
value: "15"
}), /*#__PURE__*/React.createElement(Progress, {
bar: true,
color: "success",
value: "30"
}), /*#__PURE__*/React.createElement(Progress, {
bar: true,
color: "info",
value: "25"
}), /*#__PURE__*/React.createElement(Progress, {
bar: true,
color: "warning",
value: "20"
}), /*#__PURE__*/React.createElement(Progress, {
bar: true,
color: "danger",
value: "5"
})));
expect(screen.getByTestId('sandman')).toHaveClass('progress');
expect(screen.getAllByRole('progressbar').length).toBe(5);
});
it('should render nested progress bars and id attribute', function () {
render( /*#__PURE__*/React.createElement(Progress, {
multi: true,
"data-testid": "sandman"
}, /*#__PURE__*/React.createElement(Progress, {
bar: true,
id: "ruh-roh"
})));
expect(screen.getByRole('progressbar')).toHaveAttribute('id', 'ruh-roh');
expect(screen.getByTestId('sandman')).toHaveClass('progress');
});
});

37
node_modules/reactstrap/esm/__tests__/Row.spec.js generated vendored Normal file
View File

@@ -0,0 +1,37 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { Row } from '..';
import { testForChildrenInComponent, testForCustomClass, testForDefaultClass } from '../testUtils';
describe('Row', function () {
it('should render .row markup', function () {
testForDefaultClass(Row, 'row');
});
it('should render children', function () {
testForChildrenInComponent(Row);
});
it('should pass additional classNames', function () {
testForCustomClass(Row);
});
it('show render noGutters class as gx-0', function () {
render( /*#__PURE__*/React.createElement(Row, {
noGutters: true,
"data-testid": "row"
}));
expect(screen.getByTestId('row')).toHaveClass('gx-0 row');
});
it('should pass row col size specific classes as strings', function () {
render( /*#__PURE__*/React.createElement(Row, {
sm: "6",
"data-testid": "row"
}));
expect(screen.getByTestId('row')).toHaveClass('row-cols-sm-6');
});
it('should pass row col size specific classes as numbers', function () {
render( /*#__PURE__*/React.createElement(Row, {
sm: 6,
"data-testid": "row"
}));
expect(screen.getByTestId('row')).toHaveClass('row-cols-sm-6');
});
});

48
node_modules/reactstrap/esm/__tests__/Spinner.spec.js generated vendored Normal file
View File

@@ -0,0 +1,48 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { Spinner } from '..';
import { testForChildrenInComponent, testForCustomTag } from '../testUtils';
describe('Spinner', function () {
it('should render a span by default', function () {
render( /*#__PURE__*/React.createElement(Spinner, null));
expect(screen.getByText('Loading...').tagName.toLowerCase()).toMatch('span');
});
it('should render a custom tag when provided', function () {
testForCustomTag(Spinner, {}, 'main');
});
it('should default render "Loading..." children', function () {
render( /*#__PURE__*/React.createElement(Spinner, null));
expect(screen.getByText('Loading...')).toBeInTheDocument();
});
it('should render children', function () {
testForChildrenInComponent(Spinner);
});
it('should render visually-hidden children', function () {
render( /*#__PURE__*/React.createElement(Spinner, null, "Yo!"));
expect(screen.getByText('Yo!')).toHaveClass('visually-hidden');
});
it('should render default type of border', function () {
render( /*#__PURE__*/React.createElement(Spinner, null));
expect(screen.getByRole('status')).toHaveClass('spinner-border');
});
it('should render type if specified', function () {
render( /*#__PURE__*/React.createElement(Spinner, {
type: "grow"
}));
expect(screen.getByRole('status')).toHaveClass('spinner-grow');
});
it('should render size if specified', function () {
render( /*#__PURE__*/React.createElement(Spinner, {
size: "sm"
}));
expect(screen.getByRole('status')).toHaveClass('spinner-border-sm');
expect(screen.getByRole('status')).toHaveClass('spinner-border');
});
it('should render color if specified', function () {
render( /*#__PURE__*/React.createElement(Spinner, {
color: "primary"
}));
expect(screen.getByRole('status')).toHaveClass('text-primary');
});
});

70
node_modules/reactstrap/esm/__tests__/Table.spec.js generated vendored Normal file
View File

@@ -0,0 +1,70 @@
import React from 'react';
import '@testing-library/jest-dom';
import { screen, render } from '@testing-library/react';
import { Table } from '..';
import { testForCustomClass, testForCustomTag, testForDefaultClass } from '../testUtils';
describe('Table', function () {
it('should render with "table" class', function () {
testForDefaultClass(Table, 'table');
});
it('should render additional classes', function () {
testForCustomClass(Table);
});
it('should render custom tag', function () {
testForCustomTag(Table);
});
it('should render modifier classes', function () {
render( /*#__PURE__*/React.createElement(Table, {
"data-testid": "table",
size: "sm",
bordered: true,
striped: true,
dark: true,
hover: true
}));
var node = screen.getByTestId('table');
expect(node).toHaveClass('table');
expect(node).toHaveClass('table-sm');
expect(node).toHaveClass('table-bordered');
expect(node).toHaveClass('table-striped');
expect(node).toHaveClass('table-hover');
expect(node).toHaveClass('table-dark');
});
it('should render a borderless table', function () {
render( /*#__PURE__*/React.createElement(Table, {
"data-testid": "table",
borderless: true
}));
expect(screen.getByTestId('table')).toHaveClass('table');
expect(screen.getByTestId('table')).toHaveClass('table-borderless');
});
it('should render responsive wrapper class', function () {
render( /*#__PURE__*/React.createElement(Table, {
"data-testid": "table",
responsive: true
}));
expect(screen.getByTestId('table')).toHaveClass('table');
expect(screen.getByTestId('table').parentNode).toHaveClass('table-responsive');
});
it('should render responsive wrapper class for md', function () {
render( /*#__PURE__*/React.createElement(Table, {
"data-testid": "table",
responsive: "md"
}));
expect(screen.getByTestId('table')).toHaveClass('table');
expect(screen.getByTestId('table').parentNode).toHaveClass('table-responsive-md');
});
it('should render responsive wrapper cssModule', function () {
var cssModule = {
table: 'scopedTable',
'table-responsive': 'scopedResponsive'
};
render( /*#__PURE__*/React.createElement(Table, {
"data-testid": "table",
responsive: true,
cssModule: cssModule
}));
expect(screen.getByTestId('table')).toHaveClass('scopedTable');
expect(screen.getByTestId('table').parentNode).toHaveClass('scopedResponsive');
});
});

76
node_modules/reactstrap/esm/__tests__/Tabs.spec.js generated vendored Normal file
View File

@@ -0,0 +1,76 @@
import React from 'react';
import { screen, render } from '@testing-library/react';
import { TabContent, TabPane } from '..';
import '@testing-library/jest-dom';
var activeTab = '1';
describe('Tabs', function () {
it('should render', function () {
render( /*#__PURE__*/React.createElement(TabContent, {
activeTab: "1"
}, /*#__PURE__*/React.createElement(TabPane, {
tabId: "1"
}, "Destiny"), /*#__PURE__*/React.createElement(TabPane, {
tabId: "2"
}, "Death")));
expect(screen.getByText('Destiny')).toBeInTheDocument();
expect(screen.getByText('Death')).toBeInTheDocument();
});
it('should have tab1 as active', function () {
render( /*#__PURE__*/React.createElement(TabContent, {
activeTab: "1"
}, /*#__PURE__*/React.createElement(TabPane, {
tabId: "1"
}, "Dream"), /*#__PURE__*/React.createElement(TabPane, {
tabId: "2"
}, "Destruction")));
expect(screen.getByText('Dream')).toHaveClass('active');
expect(screen.getByText('Destruction')).not.toHaveClass('active');
});
it('should switch to tab2 as active', function () {
render( /*#__PURE__*/React.createElement(TabContent, {
activeTab: "2"
}, /*#__PURE__*/React.createElement(TabPane, {
tabId: "1"
}, "Desire"), /*#__PURE__*/React.createElement(TabPane, {
tabId: "2"
}, "Despair")));
expect(screen.getByText('Desire')).not.toHaveClass('active');
expect(screen.getByText('Despair')).toHaveClass('active');
});
it('should show no active tabs if active tab id is unknown', function () {
render( /*#__PURE__*/React.createElement(TabContent, {
activeTab: "3"
}, /*#__PURE__*/React.createElement(TabPane, {
tabId: "1"
}, "Delirium"), /*#__PURE__*/React.createElement(TabPane, {
tabId: "2"
}, "Delight")));
expect(screen.getByText('Delirium')).not.toHaveClass('active');
expect(screen.getByText('Delight')).not.toHaveClass('active');
/* Not sure if this is what we want. Toggling to an unknown tab id should
render all tabs as inactive and should show no content.
This could be a warning during development that the user is not having a proper tab ids.
NOTE: Should this be different?
*/
});
it('should render custom TabContent tag', function () {
render( /*#__PURE__*/React.createElement(TabContent, {
tag: "main",
activeTab: activeTab,
"data-testid": "endless"
}, /*#__PURE__*/React.createElement(TabPane, {
tabId: "1"
}, "Tab Content 1"), /*#__PURE__*/React.createElement(TabPane, {
tabId: "2"
}, "TabContent 2")));
expect(screen.getByTestId('endless').tagName).toBe('MAIN');
});
it('should render custom TabPane tag', function () {
render( /*#__PURE__*/React.createElement(TabPane, {
tag: "main",
tabId: "1"
}, "Tab Content 1"));
expect(screen.getByText('Tab Content 1').tagName).toBe('MAIN');
});
});

43
node_modules/reactstrap/esm/__tests__/Toast.spec.js generated vendored Normal file
View File

@@ -0,0 +1,43 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import { Toast } from '..';
import { testForChildrenInComponent, testForCustomAttribute, testForCustomClass, testForCustomTag, testForDefaultTag } from '../testUtils';
describe('Toast', function () {
it('should render children', function () {
testForChildrenInComponent(Toast);
});
it('should pass className down', function () {
testForCustomClass(Toast);
});
it('should pass other props down', function () {
testForCustomAttribute(Toast);
});
it('should have support configurable transitionTimeouts', function () {
var transitionProps = /*#__PURE__*/React.createElement(Toast, {
transition: {
timeout: 0,
appear: false,
enter: false,
exit: false
}
}, "Yo!").props.transition;
expect(transitionProps.timeout).toEqual(0);
expect(transitionProps.appear).toBe(false);
expect(transitionProps.enter).toBe(false);
expect(transitionProps.exit).toBe(false);
});
it('should use a div tag by default', function () {
testForDefaultTag(Toast, 'div');
});
it('should support custom tag', function () {
testForCustomTag(Toast, 'p');
});
it('should be empty if not isOpen', function () {
var _render = render( /*#__PURE__*/React.createElement(Toast, {
isOpen: false
}, "Yo!")),
container = _render.container;
expect(container.children).toHaveLength(0);
});
});

View File

@@ -0,0 +1,13 @@
import { ToastBody } from '..';
import { testForCustomClass, testForCustomTag, testForDefaultClass } from '../testUtils';
describe('ToastBody', function () {
it('should render with "toast-body" class', function () {
testForDefaultClass(ToastBody, 'toast-body');
});
it('should render additional classes', function () {
testForCustomClass(ToastBody);
});
it('should render custom tag', function () {
testForCustomTag(ToastBody);
});
});

View File

@@ -0,0 +1,30 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import { ToastHeader } from '..';
import { testForCustomClass, testForDefaultClass } from '../testUtils';
describe('ToastHeader', function () {
it('should render with "toast-header" class', function () {
testForDefaultClass(ToastHeader, 'toast-header');
});
it('should render additional classes', function () {
testForCustomClass(ToastHeader);
});
it('should render close button', function () {
render( /*#__PURE__*/React.createElement(ToastHeader, {
toggle: function toggle() {}
}, "Yo!"));
expect(screen.getByLabelText(/close/i)).toBeInTheDocument();
});
it('should render custom tag', function () {
render( /*#__PURE__*/React.createElement(ToastHeader, {
tag: "p"
}, "Yo!"));
expect(screen.getByText(/yo!/i).tagName.toLowerCase()).toMatch('p');
});
it('should render custom wrapping tag', function () {
render( /*#__PURE__*/React.createElement(ToastHeader, {
wrapTag: "main"
}, "Yo!"));
expect(screen.getByText(/yo/i).parentElement.tagName).toMatch(/main/i);
});
});

32
node_modules/reactstrap/esm/__tests__/Tooltip.spec.js generated vendored Normal file
View File

@@ -0,0 +1,32 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import Tooltip from '../Tooltip';
describe('Tooltip', function () {
var element;
beforeEach(function () {
element = document.createElement('div');
element.setAttribute('id', 'tooltip-target');
document.body.appendChild(element);
});
afterEach(function () {
document.body.removeChild(element);
});
it('should apply popperClassName to popper component', function () {
var _screen$queryByText;
render( /*#__PURE__*/React.createElement(Tooltip, {
target: "tooltip-target",
popperClassName: "boba-was-here",
isOpen: true
}, "Bo-Katan Kryze"));
expect((_screen$queryByText = screen.queryByText('Bo-Katan Kryze')) === null || _screen$queryByText === void 0 ? void 0 : _screen$queryByText.parentElement).toHaveClass('tooltip show boba-was-here');
});
it('should apply arrowClassName to arrow', function () {
render( /*#__PURE__*/React.createElement(Tooltip, {
target: "tooltip-target",
arrowClassName: "boba-was-here",
isOpen: true
}, "Bo-Katan Kryze"));
expect(document.querySelector('.arrow')).toHaveClass('boba-was-here');
});
});

View File

@@ -0,0 +1,573 @@
import React from 'react';
import { Popper } from 'react-popper';
import user from '@testing-library/user-event';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import TooltipPopoverWrapper from '../TooltipPopoverWrapper';
describe('Tooltip', function () {
var element;
var container;
beforeEach(function () {
element = document.createElement('div');
container = document.createElement('div');
element.innerHTML = '<p id="target">This is the Tooltip <span id="innerTarget">target</span>.</p>';
element.setAttribute('id', 'testContainer');
container.setAttribute('id', 'container');
container.setAttribute('data-testid', 'container');
element.appendChild(container);
document.body.appendChild(element);
jest.useFakeTimers();
jest.resetModules();
Popper.mockClear();
});
afterEach(function () {
jest.clearAllTimers();
document.body.removeChild(element);
element = null;
container = null;
});
it('should render arrow by default', function () {
render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: "target",
isOpen: true
}, "Tooltip Content"));
expect(document.querySelector('.arrow')).toBeInTheDocument();
});
it('should render not render arrow if hiderArrow is true', function () {
render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: "target",
isOpen: true,
hideArrow: true
}, "Tooltip Content"));
expect(document.querySelector('.arrow')).not.toBeInTheDocument();
});
it('should not render children if isOpen is false', function () {
render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: "target",
isOpen: false
}, "Tooltip Content"));
expect(screen.queryByText(/tooltip content/i)).not.toBeInTheDocument();
});
it('should render if isOpen is true', function () {
render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: "target",
isOpen: true,
className: "tooltip show",
trigger: "hover"
}, "Tooltip Content"));
expect(screen.queryByText(/tooltip content/i)).toBeInTheDocument();
expect(document.querySelector('.tooltip.show')).toBeInTheDocument();
});
it('should render with target object', function () {
render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: document.getElementById('target'),
isOpen: true,
className: "tooltip show"
}, "Tooltip Content"));
expect(document.getElementsByClassName('tooltip show')).toHaveLength(1);
expect(screen.queryByText(/tooltip content/i)).toBeInTheDocument();
});
it('should toggle isOpen', function () {
var _render = render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: "target",
isOpen: false,
className: "tooltip show"
}, "Tooltip Content")),
rerender = _render.rerender;
expect(screen.queryByText(/tooltip content/i)).not.toBeInTheDocument();
rerender( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: "target",
isOpen: true,
className: "tooltip show"
}, "Tooltip Content"));
expect(screen.queryByText(/tooltip content/i)).toBeInTheDocument();
rerender( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: "target",
isOpen: false,
className: "tooltip show"
}, "Tooltip Content"));
jest.advanceTimersByTime(150);
expect(screen.queryByText(/tooltip content/i)).not.toBeInTheDocument();
});
it('should handle target clicks', function () {
var toggle = jest.fn();
var _render2 = render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: "target",
isOpen: false,
toggle: toggle
}, "Tooltip Content")),
rerender = _render2.rerender;
user.click(screen.getByText(/this is the Tooltip/i));
jest.advanceTimersByTime(150);
expect(toggle).toBeCalled();
toggle.mockClear();
rerender( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: "target",
isOpen: true,
toggle: toggle
}, "Tooltip Content"));
user.click(screen.getByText(/this is the Tooltip/i));
jest.advanceTimersByTime(150);
expect(toggle).toBeCalled();
});
it('should handle inner target clicks', function () {
var toggle = jest.fn();
render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: "target",
isOpen: false,
toggle: toggle
}, "Tooltip Content"));
user.click(screen.getByText(/target/i));
jest.advanceTimersByTime(150);
expect(toggle).toBeCalled();
});
it('should not do anything when document click outside of target', function () {
var toggle = jest.fn();
render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: "target",
isOpen: false,
toggle: toggle
}, "Tooltip Content"));
user.click(screen.getByTestId('container'));
expect(toggle).not.toBeCalled();
});
it('should open after receiving single touchstart and single click', function () {
var toggle = jest.fn();
render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: "target",
isOpen: false,
toggle: toggle,
trigger: "click"
}, "Tooltip Content"));
user.click(screen.getByText(/target/i));
jest.advanceTimersByTime(200);
expect(toggle).toHaveBeenCalled();
// TODO: RTL currently doesn't support touch events
});
it('should close after receiving single touchstart and single click', function () {
var toggle = jest.fn();
render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: "target",
isOpen: true,
toggle: toggle,
trigger: "click"
}, "Tooltip Content"));
user.click(screen.getByText(/target/i));
jest.advanceTimersByTime(200);
expect(toggle).toHaveBeenCalled();
// TODO: RTL currently doesn't support touch events
});
it('should pass down custom modifiers', function () {
render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
isOpen: true,
target: "target",
modifiers: [{
name: 'offset',
options: {
offset: [2, 2]
}
}, {
name: 'preventOverflow',
options: {
boundary: 'viewport'
}
}]
}, "Tooltip Content"));
expect(Popper.mock.calls[0][0].modifiers).toEqual(expect.arrayContaining([expect.objectContaining({
name: 'offset',
options: {
offset: [2, 2]
}
})]));
expect(Popper.mock.calls[0][0].modifiers).toEqual(expect.arrayContaining([expect.objectContaining({
name: 'preventOverflow',
options: {
boundary: 'viewport'
}
})]));
});
describe('PopperContent', function () {
beforeEach(function () {
jest.doMock('../PopperContent', function () {
return jest.fn(function (props) {
return props.children({
update: function update() {},
ref: function ref() {},
style: {},
placement: props.placement,
arrowProps: {
ref: function ref() {},
style: {}
},
isReferenceHidden: false
});
});
});
});
it('should pass down cssModule', function () {
// eslint-disable-next-line global-require
var PopperContent = require('../PopperContent');
// eslint-disable-next-line global-require
var TooltipPopoverWrapper = require('../TooltipPopoverWrapper')["default"];
var cssModule = {
a: 'b'
};
render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
isOpen: true,
target: "target",
cssModule: cssModule
}, "Tooltip Content"));
expect(PopperContent).toBeCalledTimes(1);
expect(PopperContent.mock.calls[0][0]).toEqual(expect.objectContaining({
cssModule: expect.objectContaining({
a: 'b'
})
}));
});
it('should pass down offset', function () {
// eslint-disable-next-line global-require
var PopperContent = require('../PopperContent');
// eslint-disable-next-line global-require
var TooltipPopoverWrapper = require('../TooltipPopoverWrapper')["default"];
render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
isOpen: true,
target: "target",
offset: [0, 12]
}, "Tooltip content"));
expect(PopperContent).toBeCalledTimes(1);
expect(PopperContent.mock.calls[0][0].offset).toEqual(expect.arrayContaining([0, 12]));
});
it('should pass down flip', function () {
// eslint-disable-next-line global-require
var PopperContent = require('../PopperContent');
// eslint-disable-next-line global-require
var TooltipPopoverWrapper = require('../TooltipPopoverWrapper')["default"];
render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
isOpen: true,
target: "target",
flip: false
}, "Tooltip Content"));
expect(PopperContent).toBeCalledTimes(1);
expect(PopperContent.mock.calls[0][0].flip).toBe(false);
});
it('should handle inner target click and correct placement', function () {
var toggle = jest.fn();
// eslint-disable-next-line global-require
var PopperContent = require('../PopperContent');
// eslint-disable-next-line global-require
var TooltipPopoverWrapper = require('../TooltipPopoverWrapper')["default"];
var _render3 = render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: "target",
isOpen: false,
toggle: toggle
}, "Tooltip Content")),
rerender = _render3.rerender;
user.click(screen.getByText(/target/i));
jest.advanceTimersByTime(200);
expect(toggle).toBeCalled();
rerender( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: "target",
isOpen: true,
toggle: toggle
}, "Tooltip Content"));
expect(PopperContent.mock.calls[0][0].target.id).toBe('target');
});
});
it('should not call props.toggle when disabled ', function () {
var toggle = jest.fn();
render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: "target",
disabled: true,
isOpen: true,
toggle: toggle
}, "Tooltip Content"));
user.click(screen.getByText(/target/i));
expect(toggle).not.toHaveBeenCalled();
});
it('should not throw when props.toggle is not provided ', function () {
render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: "target",
disabled: true,
isOpen: true
}, "Tooltip Content"));
user.click(screen.getByText(/target/i));
});
it('should not throw when passed a ref object as the target', function () {
var targetObj = /*#__PURE__*/React.createRef();
targetObj.current = {
addEventListener: jest.fn(),
removeEventListener: jest.fn()
};
var _render4 = render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
isOpen: false,
target: targetObj
}, "Yo!")),
unmount = _render4.unmount;
unmount();
expect(targetObj.current.addEventListener).toHaveBeenCalled();
expect(targetObj.current.removeEventListener).toHaveBeenCalled();
});
describe('multi target', function () {
var targets;
var targetContainer;
beforeEach(function () {
targetContainer = document.createElement('div');
targetContainer.innerHTML = "<span class='example first'>Target 1</span><span class='example second'>Target 2<span class='inner_example'>Inner target</span></span>";
element.appendChild(targetContainer);
targets = targetContainer.querySelectorAll('.example');
});
afterEach(function () {
element.removeChild(targetContainer);
targets = null;
});
it('should attach tooltip on multiple target when a target selector matches multiple elements', function () {
var toggle = jest.fn();
render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: ".example",
isOpen: false,
toggle: toggle,
delay: 0
}, "Yo!"));
user.click(targets[0]);
jest.advanceTimersByTime(200);
expect(toggle).toHaveBeenCalledTimes(1);
user.click(targets[1]);
jest.advanceTimersByTime(200);
expect(toggle).toHaveBeenCalledTimes(2);
});
it('should attach tooltip on second target with correct placement, when inner element is clicked', function () {
var toggle = jest.fn();
render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: ".example",
isOpen: false,
toggle: toggle,
delay: 0
}, "Yo!"));
user.click(targets[0]);
jest.advanceTimersByTime(200);
expect(toggle).toHaveBeenCalledTimes(1);
});
});
describe('delay', function () {
it('should accept a number', function () {
var toggle = jest.fn();
render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: "target",
isOpen: true,
toggle: toggle,
delay: 200
}, "Tooltip Content"));
user.click(screen.getByText(/target/i));
jest.advanceTimersByTime(100);
expect(toggle).not.toBeCalled();
jest.advanceTimersByTime(100);
expect(toggle).toBeCalled();
});
it('should accept an object', function () {
var toggle = jest.fn();
render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: "target",
isOpen: true,
toggle: toggle,
delay: {
show: 400,
hide: 400
}
}, "Tooltip Content"));
user.click(screen.getByText(/target/i));
jest.advanceTimersByTime(200);
expect(toggle).not.toBeCalled();
jest.advanceTimersByTime(200);
expect(toggle).toBeCalled();
});
it('should use default value if value is missing from object', function () {
var toggle = jest.fn();
render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: "target",
isOpen: true,
toggle: toggle,
delay: {
show: 0
}
}, "Tooltip Content"));
user.click(screen.getByText(/target/i));
jest.advanceTimersByTime(10);
expect(toggle).not.toBeCalled();
jest.advanceTimersByTime(40); // default hide value is 50
expect(toggle).toBeCalled();
});
});
describe('hide', function () {
it('should call toggle when isOpen', function () {
var toggle = jest.fn();
render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: "target",
isOpen: true,
toggle: toggle
}, "Tooltip Content"));
user.click(screen.getByText(/target/i));
jest.advanceTimersByTime(200);
expect(toggle).toHaveBeenCalled();
});
});
describe('show', function () {
it('should call toggle when isOpen', function () {
var toggle = jest.fn();
render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: "target",
isOpen: false,
toggle: toggle
}, "Tooltip Content"));
user.click(screen.getByText(/target/i));
jest.advanceTimersByTime(200);
expect(toggle).toHaveBeenCalled();
});
});
describe('onMouseOverTooltip', function () {
it('should clear timeout if it exists on target click', function () {
var toggle = jest.fn();
var _render5 = render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: "target",
isOpen: false,
toggle: toggle,
delay: 200,
trigger: "hover"
}, "Tooltip Content")),
rerender = _render5.rerender;
user.hover(screen.getByText(/target/i));
rerender( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: "target",
isOpen: true,
toggle: toggle,
delay: 200,
trigger: "hover"
}, "Tooltip Content"));
user.unhover(screen.getByText(/target/i));
jest.advanceTimersByTime(200);
expect(toggle).toHaveBeenCalledTimes(1);
});
it('should not call .toggle if isOpen', function () {
var toggle = jest.fn();
render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: "target",
isOpen: true,
toggle: toggle,
delay: 200,
trigger: "hover"
}, "Tooltip Content"));
user.hover(screen.getByText(/target/i));
jest.advanceTimersByTime(200);
expect(toggle).not.toHaveBeenCalled();
});
});
describe('onMouseLeaveTooltip', function () {
it('should clear timeout if it exists on target click', function () {
var toggle = jest.fn();
var _render6 = render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: "target",
isOpen: true,
toggle: toggle,
delay: 200,
trigger: "hover"
}, "Tooltip Content")),
rerender = _render6.rerender;
user.unhover(screen.getByText(/target/i));
rerender( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: "target",
isOpen: false,
toggle: toggle,
delay: 200,
trigger: "hover"
}, "Tooltip Content"));
user.hover(screen.getByText(/target/i));
jest.advanceTimersByTime(200);
expect(toggle).toHaveBeenCalledTimes(1);
});
it('should not call .toggle if isOpen is false', function () {
var toggle = jest.fn();
render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: "target",
isOpen: false,
toggle: toggle,
delay: 200,
trigger: "hover"
}, "Tooltip Content"));
user.unhover(screen.getByText(/target/i));
jest.advanceTimersByTime(200);
expect(toggle).not.toHaveBeenCalled();
});
});
describe('autohide', function () {
it('should keep Tooltip around when false and onmouseleave from Tooltip content', function () {
var toggle = jest.fn();
render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
trigger: "hover",
target: "target",
autohide: false,
isOpen: true,
toggle: toggle,
delay: 200
}, "Tooltip Content"));
user.hover(screen.getByText(/tooltip content/i));
jest.advanceTimersByTime(200);
expect(toggle).not.toHaveBeenCalled();
user.unhover(screen.getByText(/tooltip content/i));
jest.advanceTimersByTime(200);
expect(toggle).toHaveBeenCalled();
});
it('clears showTimeout and hideTimeout in onMouseLeaveTooltipContent', function () {
var toggle = jest.fn();
render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
trigger: "hover",
target: "target",
autohide: false,
isOpen: true,
toggle: toggle,
delay: 200
}, "Tooltip Content"));
user.unhover(screen.getByText(/tooltip content/i));
user.hover(screen.getByText(/tooltip content/i));
user.unhover(screen.getByText(/tooltip content/i));
jest.advanceTimersByTime(200);
expect(toggle).toBeCalledTimes(1);
});
it('should not keep Tooltip around when autohide is true and Tooltip content is hovered over', function () {
var toggle = jest.fn();
render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: "target",
autohide: true,
isOpen: true,
toggle: toggle,
delay: 200,
trigger: "click hover focus"
}, "Tooltip Content"));
user.unhover(screen.getByText(/target/i));
user.hover(screen.getByText(/tooltip content/i));
jest.advanceTimersByTime(200);
expect(toggle).toHaveBeenCalled();
});
it('should allow a function to be used as children', function () {
var renderChildren = jest.fn();
render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: "target",
isOpen: true
}, renderChildren));
expect(renderChildren).toHaveBeenCalled();
});
it('should render children properly when children is a function', function () {
render( /*#__PURE__*/React.createElement(TooltipPopoverWrapper, {
target: "target",
isOpen: true,
className: "tooltip show",
trigger: "hover"
}, function () {
return 'Tooltip Content';
}));
expect(screen.getByText(/tooltip content/i)).toBeInTheDocument();
});
});
});

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

View File

@@ -0,0 +1,119 @@
import React from 'react';
import { render, screen } from '@testing-library/react';
import '@testing-library/jest-dom';
import user from '@testing-library/user-event';
import { Carousel, UncontrolledCarousel } from '..';
var items = [{
src: '',
altText: 'a',
caption: 'caption 1',
key: '1'
}, {
src: '',
altText: 'b',
caption: 'caption 2',
key: '2'
}, {
src: '',
altText: 'c',
caption: 'caption 3',
key: '3'
}];
describe('UncontrolledCarousel', function () {
beforeEach(function () {
jest.useFakeTimers();
});
afterEach(function () {
jest.clearAllTimers();
});
it('should have active element default to 0', function () {
render( /*#__PURE__*/React.createElement(UncontrolledCarousel, {
items: items
}));
expect(screen.getByAltText('a').parentElement).toHaveClass('active');
});
it('should autoplay by default', function () {
render( /*#__PURE__*/React.createElement(UncontrolledCarousel, {
items: items
}));
expect(screen.getByAltText('a').parentElement).toHaveClass('active');
jest.advanceTimersByTime(5000);
expect(screen.getByAltText('b').parentElement).toHaveClass('carousel-item carousel-item-start carousel-item-next');
jest.advanceTimersByTime(600);
expect(screen.getByAltText('b').parentElement).toHaveClass('active');
});
it('should not play automatically when autoPlay is false', function () {
render( /*#__PURE__*/React.createElement(UncontrolledCarousel, {
items: items,
autoPlay: false
}));
expect(screen.getByAltText('a').parentElement).toHaveClass('active');
jest.advanceTimersByTime(5000);
expect(screen.getByAltText('b').parentElement).not.toHaveClass('carousel-item carousel-item-start carousel-item-next');
jest.advanceTimersByTime(600);
expect(screen.getByAltText('b').parentElement).not.toHaveClass('active');
});
it('should move to next slide when next button is clicked', function () {
render( /*#__PURE__*/React.createElement(UncontrolledCarousel, {
items: items,
autoPlay: false
}));
user.click(screen.getByText(/next/i));
jest.advanceTimersByTime(600);
expect(screen.getByAltText('b').parentElement).toHaveClass('carousel-item active');
});
it('should not move to next slide while animating', function () {
render( /*#__PURE__*/React.createElement(UncontrolledCarousel, {
items: items
}));
user.click(screen.getByText(/next/i));
expect(screen.getByAltText('b').parentElement).toHaveClass('carousel-item carousel-item-start carousel-item-next');
user.click(screen.getByText(/next/i));
expect(screen.getByAltText('c').parentElement).not.toHaveClass('carousel-item carousel-item-start carousel-item-next');
});
it('should wrap to first slide on reaching the end', function () {
render( /*#__PURE__*/React.createElement(UncontrolledCarousel, {
items: items,
autoPlay: false
}));
user.click(screen.getByText(/next/i));
jest.advanceTimersByTime(600);
expect(screen.getByAltText('b').parentElement).toHaveClass('active');
user.click(screen.getByText(/next/i));
jest.advanceTimersByTime(600);
expect(screen.getByAltText('c').parentElement).toHaveClass('active');
user.click(screen.getByText(/next/i));
jest.advanceTimersByTime(600);
expect(screen.getByAltText('a').parentElement).toHaveClass('active');
});
it('should move to previous slide when previous button is clicked', function () {
render( /*#__PURE__*/React.createElement(UncontrolledCarousel, {
items: items,
autoPlay: false
}));
user.click(screen.getByText(/next/i));
jest.advanceTimersByTime(600);
expect(screen.getByAltText('b').parentElement).toHaveClass('carousel-item active');
user.click(screen.getByText(/previous/i));
jest.advanceTimersByTime(600);
expect(screen.getByAltText('a').parentElement).toHaveClass('carousel-item active');
});
it('should not move to previous slide while animating', function () {
render( /*#__PURE__*/React.createElement(UncontrolledCarousel, {
items: items
}));
user.click(screen.getByText(/next/i));
expect(screen.getByAltText('b').parentElement).toHaveClass('carousel-item carousel-item-start carousel-item-next');
user.click(screen.getByText(/previous/i));
expect(screen.getByAltText('a').parentElement).not.toHaveClass('carousel-item carousel-item-start carousel-item-next');
});
it('should wrap to last slide on reaching the beginning', function () {
render( /*#__PURE__*/React.createElement(UncontrolledCarousel, {
items: items,
autoPlay: false
}));
user.click(screen.getByText(/previous/i));
jest.advanceTimersByTime(600);
expect(screen.getByAltText('c').parentElement).toHaveClass('active');
});
});

File diff suppressed because one or more lines are too long

381
node_modules/reactstrap/esm/__tests__/utils.spec.js generated vendored Normal file

File diff suppressed because one or more lines are too long