@bitrise/bitkit 10.11.1 → 10.11.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
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@bitrise/bitkit",
3
3
  "description": "Bitrise React component library",
4
- "version": "10.11.1",
4
+ "version": "10.11.2",
5
5
  "repository": "git@github.com:bitrise-io/bitkit.git",
6
6
  "main": "src/index.ts",
7
7
  "license": "UNLICENSED",
@@ -0,0 +1,34 @@
1
+ import { render, screen } from '@testing-library/react';
2
+ import userEvent from '@testing-library/user-event';
3
+ import Accordion from './Accordion';
4
+ import AccordionItem from './AccordionItem';
5
+
6
+ describe('Accordion', () => {
7
+ it('calls the onChange handler with the proper id if Accordion has a conditionally not rendered item', async () => {
8
+ const thirdId = 'third-item';
9
+ const thirdTitle = 'Third item';
10
+
11
+ const handleChange = jest.fn();
12
+
13
+ render(
14
+ <Accordion onChange={handleChange}>
15
+ <AccordionItem id="first" buttonContent="First item">
16
+ First content
17
+ </AccordionItem>
18
+ {false && (
19
+ <AccordionItem id="second" buttonContent="Second item">
20
+ Second content
21
+ </AccordionItem>
22
+ )}
23
+ <AccordionItem id={thirdId} buttonContent={thirdTitle}>
24
+ Third content
25
+ </AccordionItem>
26
+ </Accordion>,
27
+ );
28
+
29
+ const thirdTab = await screen.findByText(thirdTitle);
30
+ await userEvent.click(thirdTab);
31
+
32
+ expect(handleChange).toHaveBeenCalledWith(['third-item'], [1]);
33
+ });
34
+ });
@@ -0,0 +1,36 @@
1
+ import { render, screen } from '@testing-library/react';
2
+ import userEvent from '@testing-library/user-event';
3
+ import Tabs from './Tabs';
4
+ import TabList from './TabList';
5
+ import Tab from './Tab';
6
+ import TabPanels from './TabPanels';
7
+ import TabPanel from './TabPanel';
8
+
9
+ describe('Tabs', () => {
10
+ it('calls the onChange handler with the proper id if TabList has a conditionally not rendered item', async () => {
11
+ const thirdTabId = 'third-tab';
12
+ const thirdTabTitle = 'Third tab';
13
+
14
+ const handleChange = jest.fn();
15
+
16
+ render(
17
+ <Tabs onChange={handleChange}>
18
+ <TabList>
19
+ <Tab id="first-tab">First tab</Tab>
20
+ {false && <Tab id="second-tab">Second tab</Tab>}
21
+ <Tab id={thirdTabId}>{thirdTabTitle}</Tab>
22
+ </TabList>
23
+ <TabPanels>
24
+ <TabPanel>First content</TabPanel>
25
+ {false && <TabPanel>Second content</TabPanel>}
26
+ <TabPanel>Third content</TabPanel>
27
+ </TabPanels>
28
+ </Tabs>,
29
+ );
30
+
31
+ const thirdTab = await screen.findByText(thirdTabTitle);
32
+ await userEvent.click(thirdTab);
33
+
34
+ expect(handleChange).toHaveBeenCalledWith(1, thirdTabId);
35
+ });
36
+ });
@@ -1,4 +1,4 @@
1
- import React, { useEffect, useState } from 'react';
1
+ import React, { isValidElement, ReactElement, useEffect, useState } from 'react';
2
2
  import { Tabs as ChakraTabs, TabsProps as ChakraTabsProps, forwardRef } from '@chakra-ui/react';
3
3
  import { useHistory } from '../../hooks';
4
4
 
@@ -8,13 +8,11 @@ export interface TabsProps extends ChakraTabsProps {
8
8
  withHistory?: boolean;
9
9
  }
10
10
 
11
- const getTabIds = (props: TabsProps) => {
12
- const ids: string[] = [];
13
- const tabs = React.Children.toArray(props.children)[0] as any;
14
- React.Children.forEach(tabs.props.children, (c, index) => {
15
- ids[index] = c?.props?.id;
16
- });
17
- return ids;
11
+ const getTabIds = (props: TabsProps): string[] => {
12
+ const tabList = React.Children.toArray(props.children)[0] as ReactElement;
13
+ const tabs = React.Children.toArray(tabList.props.children) as ReactElement[];
14
+
15
+ return tabs.filter((item) => isValidElement(item)).map((item) => item.props.id);
18
16
  };
19
17
 
20
18
  /**