@lumx/react 3.18.2-alpha.1 → 3.18.2-alpha.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/package.json CHANGED
@@ -6,8 +6,8 @@
6
6
  "url": "https://github.com/lumapps/design-system/issues"
7
7
  },
8
8
  "dependencies": {
9
- "@lumx/core": "^3.18.2-alpha.1",
10
- "@lumx/icons": "^3.18.2-alpha.1",
9
+ "@lumx/core": "^3.18.2-alpha.2",
10
+ "@lumx/icons": "^3.18.2-alpha.2",
11
11
  "@popperjs/core": "^2.5.4",
12
12
  "body-scroll-lock": "^3.1.5",
13
13
  "classnames": "^2.3.2",
@@ -105,5 +105,5 @@
105
105
  "build:storybook": "storybook build"
106
106
  },
107
107
  "sideEffects": false,
108
- "version": "3.18.2-alpha.1"
108
+ "version": "3.18.2-alpha.2"
109
109
  }
@@ -0,0 +1,74 @@
1
+ import React from 'react';
2
+
3
+ import { fireEvent, render } from '@testing-library/react';
4
+ import { DisabledStateProvider } from './DisabledStateContext';
5
+ import { useDisableStateProps } from './useDisableStateProps';
6
+
7
+ describe(useDisableStateProps.name, () => {
8
+ const setup = (props: any, wrapper?: React.ComponentType) => {
9
+ const testId = 'test-container';
10
+ const Component = () => {
11
+ const { disabledStateProps, otherProps } = useDisableStateProps(props);
12
+ return <div data-testid={testId} {...otherProps} {...disabledStateProps} />;
13
+ };
14
+ const renderResult = render(wrapper ? React.createElement(wrapper, undefined, <Component />) : <Component />);
15
+ return { ...renderResult, element: renderResult.getByTestId(testId) };
16
+ };
17
+
18
+ it('should not be disabled by default', () => {
19
+ const { element } = setup({});
20
+ expect(element).not.toHaveAttribute('disabled');
21
+ expect(element).toHaveAttribute('aria-disabled', 'false');
22
+ });
23
+
24
+ it('should be disabled with `disabled` prop', () => {
25
+ const { element } = setup({ disabled: true });
26
+ expect(element).toHaveAttribute('disabled');
27
+ });
28
+
29
+ it('should be disabled with `isDisabled` prop', () => {
30
+ const { element } = setup({ isDisabled: true });
31
+ expect(element).toHaveAttribute('disabled');
32
+ });
33
+
34
+ it('should be disabled with `aria-disabled` prop', () => {
35
+ const { element } = setup({ 'aria-disabled': true });
36
+ expect(element).toHaveAttribute('aria-disabled', 'true');
37
+ });
38
+
39
+ it('should be disabled with `aria-disabled` string prop', () => {
40
+ const { element } = setup({ 'aria-disabled': 'true' });
41
+ expect(element).toHaveAttribute('aria-disabled', 'true');
42
+ });
43
+
44
+ it('should be disabled with context', () => {
45
+ const wrapper = ({ children }: any) => (
46
+ <DisabledStateProvider state="disabled">{children}</DisabledStateProvider>
47
+ );
48
+ const { element } = setup({}, wrapper);
49
+ expect(element).toHaveAttribute('disabled');
50
+ });
51
+
52
+ it('should prioritize context', () => {
53
+ const wrapper = ({ children }: any) => (
54
+ <DisabledStateProvider state="disabled">{children}</DisabledStateProvider>
55
+ );
56
+ const { element } = setup({ disabled: false }, wrapper);
57
+ expect(element).toHaveAttribute('disabled');
58
+ expect(element).toHaveAttribute('aria-disabled', 'false');
59
+ });
60
+
61
+ it('should forward onClick when not disabled', () => {
62
+ const onClick = jest.fn();
63
+ const { element } = setup({ onClick });
64
+ fireEvent.click(element);
65
+ expect(onClick).toHaveBeenCalled();
66
+ });
67
+
68
+ it('should not forward onClick when disabled', () => {
69
+ const onClick = jest.fn();
70
+ const { element } = setup({ disabled: true, onClick });
71
+ fireEvent.click(element);
72
+ expect(onClick).not.toHaveBeenCalled();
73
+ });
74
+ });