diff --git a/.github/codecov.yml b/.github/codecov.yml index b9fb8f7989..1b17e7816b 100644 --- a/.github/codecov.yml +++ b/.github/codecov.yml @@ -28,3 +28,24 @@ component_management: name: ibm-products-web-components paths: - ../packages/ibm-products-web-components/** + +flag_management: + default_rules: # the rules that will be followed for any flag added, generally + carryforward: true + statuses: + - type: project + target: auto + threshold: 1% + - type: patch + target: 80% + individual_flags: + - name: exclude_deprecated #custom flag name to view the project coverage without deprecated components + paths: + - '../packages/ibm-products/src/components/**/*.deprecated.test.js' #fill in your own path. Note, accepts globs, not regexes + - '../packages/ibm-products/src/components/**/*.deprecated.test.ts' #fill in your own path. Note, accepts globs, not regexes + carryforward: true + statuses: + - type: project + target: 20% + - type: patch + target: 100% diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 51aa7c1f42..12d0d8621f 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -117,6 +117,12 @@ jobs: uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0 env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} + - name: CI tests for c4p excluding deprecated components + run: yarn test:c4p-exclude-deprecated --collectCoverage + - name: Upload coverage reports to Codecov with GitHub Action + uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} - name: CI snapshot tests for c4p run: yarn ci-check:test:c4p:snapshot test-c4p-wc: @@ -139,6 +145,10 @@ jobs: run: yarn - name: CI tests for products web components run: yarn ci-check:test:c4p-wc + - name: Upload coverage reports to Codecov with GitHub Action + uses: codecov/codecov-action@e28ff129e5465c2c0dcc6f003fc735cb6ae0c673 # v4.5.0 + env: + CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} avt-runner: strategy: diff --git a/package.json b/package.json index b24f23168c..b46006699c 100644 --- a/package.json +++ b/package.json @@ -52,6 +52,7 @@ "test:c4p:snapshot": "yarn test:c4p-styles styles -u", "test:c4p-styles": "lerna run --stream --scope @carbon/ibm-products-styles test --", "test:c4p-wc": "yarn playwright install && lerna run --stream --scope @carbon/ibm-products-web-components test --", + "test:c4p-exclude-deprecated": "yarn test:c4p --testPathIgnorePatterns='\\.deprecated\\.test\\.js$' --", "spellcheck": "cspell '**' -e './examples' --gitignore --quiet --no-must-find-files", "storybook": "yarn storybook:start", "storybook:build": "run-s -s 'storybook:build:*'", diff --git a/packages/ibm-products/src/components/Datagrid/Datagrid.deprecated.test.js b/packages/ibm-products/src/components/Datagrid/Datagrid.deprecated.test.js new file mode 100644 index 0000000000..aa18a8c878 --- /dev/null +++ b/packages/ibm-products/src/components/Datagrid/Datagrid.deprecated.test.js @@ -0,0 +1,2933 @@ +/** + * Copyright IBM Corp. 2022, 2024 + * + * This source code is licensed under the Apache-2.0 license found in the + * LICENSE file in the root directory of this source tree. + */ + +/* eslint-disable react/prop-types */ + +import React, { useState, useEffect, forwardRef } from 'react'; +import { render, screen, fireEvent } from '@testing-library/react'; // https://testing-library.com/docs/react-testing-library/intro +import { within } from '@testing-library/dom'; +import uuidv4 from '../../global/js/utils/uuidv4'; +import { makeData } from './utils/makeData'; + +import { + checkLogging, + expectWarn, + mockHTMLElement, +} from '../../global/js/utils/test-helper'; +import { Datagrid, useFilterContext } from '.'; + +import { + useDatagrid, + useInfiniteScroll, + useSelectRows, + useDisableSelectRows, + useExpandedRow, + useNestedRows, + useSortableColumns, + useOnRowClick, + useCustomizeColumns, + useSelectAllWithToggle, + useRowIsMouseOver, + useStickyColumn, + useActionsColumn, + useColumnOrder, + useColumnRightAlign, + useColumnCenterAlign, + useEditableCell, +} from '.'; + +import { + TableToolbarContent, + TableToolbarSearch, + Button, + Pagination, + TableBatchActions, + TableBatchAction, +} from '@carbon/react'; +import { + Download, + Restart, + Filter, + Activity, + Add, + Edit, +} from '@carbon/react/icons'; +import { carbon, pkg } from '../../settings'; + +const blockClass = `${pkg.prefix}--datagrid`; + +import namor from 'namor'; + +import userEvent from '@testing-library/user-event'; +import { getInlineEditColumns } from './utils/getInlineEditColumns'; +import { FilteringUsage } from './utils/FilteringUsage'; + +import { + generateDummyCheckboxes, + filterProps as testFilterProps, + flyoutFilterProps as flyoutProps, +} from './utils/filterPropsForTesting'; + +const { click, hover, unhover } = userEvent.setup({ + // delay: null, // prev version + advanceTimers: jest.advanceTimersByTime, +}); + +const dataTestId = uuidv4(); + +const componentName = Datagrid.displayName; + +const defaultHeader = [ + { + Header: 'Row Index', + accessor: (row, i) => i, + sticky: 'left', + id: 'rowIndex', // id is required when accessor is a function. + }, + { + Header: 'First Name', + accessor: 'firstName', + sticky: 'left', + }, + { + Header: 'Last Name', + accessor: 'lastName', + }, + { + Header: 'Age', + accessor: 'age', + width: 50, + }, + { + Header: 'Visits', + accessor: 'visits', + width: 60, + }, + { + Header: 'Someone 1', + accessor: 'someone1', + }, + { + Header: 'Someone 2', + accessor: 'someone2', + }, + { + Header: 'Someone 3', + accessor: 'someone3', + }, + { + Header: 'Someone 4', + accessor: 'someone4', + }, + { + Header: 'Someone 5', + accessor: 'someone5', + }, + { + Header: 'Someone 6', + accessor: 'someone6', + }, + { + Header: 'Someone 7', + accessor: 'someone7', + }, + { + Header: 'Someone 8', + accessor: 'someone8', + }, + { + Header: 'Someone 9', + accessor: 'someone9', + }, + { + Header: 'Someone 10', + accessor: 'someone10', + }, +]; + +const DatagridBatchActions = (datagridState) => { + const { selectedFlatRows, toggleAllRowsSelected } = datagridState; + const totalSelected = selectedFlatRows && selectedFlatRows.length; + const onBatchAction = () => alert('Batch action'); + const actionName = 'Action'; + return ( + 0} + totalSelected={totalSelected} + onCancel={() => toggleAllRowsSelected(false)} + > + } + onClick={onBatchAction} + > + {actionName} + + + ); +}; + +const BasicUsage = ({ ...rest } = {}) => { + const columns = React.useMemo(() => defaultHeader, []); + const [data] = useState(makeData(10)); + const datagridState = useDatagrid({ + columns, + data, + resizerAriaLabel: 'Custom column resizer label', + }); + + return ; +}; + +const SpacerColumn = ({ ...rest } = {}) => { + const [data] = useState(makeData(10)); + const columns = React.useMemo( + () => [ + { + Header: 'First Name', + accessor: 'firstName', + rightAlignedColumn: true, + }, + { + Header: 'Last Name', + accessor: 'lastName', + rightAlignedColumn: true, + }, + ], + [] + ); + const datagridState = useDatagrid( + { + columns, + data, + enableSpacerColumn: true, + }, + useColumnRightAlign + ); + + return ; +}; + +const DatagridActions = (datagridState) => { + const { + selectedFlatRows, + setGlobalFilter, + CustomizeColumnsButton, + RowSizeDropdown, + rowSizeDropdownProps, + } = datagridState; + const downloadCsv = () => { + alert('Downloading...'); + }; + + const refreshColumns = () => { + alert('refreshing...'); + }; + const leftPanelClick = () => { + alert('open/close left panel...'); + }; + const searchForAColumn = 'Search'; + const isNothingSelected = selectedFlatRows.length === 0; + const style = { + 'button:nth-child(1) > span:nth-child(1)': { + bottom: '-37px', + }, + }; + return ( + isNothingSelected && ( + +