File tree Expand file tree Collapse file tree 2 files changed +17
-3
lines changed
Expand file tree Collapse file tree 2 files changed +17
-3
lines changed Original file line number Diff line number Diff line change @@ -22,7 +22,7 @@ export const SecretLabels = ({
2222 ) : (
2323 < >
2424 { labels . map ( ( l , i ) => {
25- if ( expanded || i <= maxLabels ) {
25+ if ( expanded || i < maxLabels ) {
2626 return (
2727 < Label key = { l } className = "secret-label" >
2828 { l }
Original file line number Diff line number Diff line change 11import { render } from '@testing-library/react' ;
2+ import { SECRET_MAX_LABELS } from '~/consts/secrets' ;
23import { SecretLabels } from '../SecretsListView/SecretLabels' ;
34
45describe ( 'SecretLabels' , ( ) => {
@@ -25,10 +26,23 @@ describe('SecretLabels', () => {
2526 handleToggle = { ( ) => { } }
2627 /> ,
2728 ) ;
28- r . debug ( ) ;
2929 expect ( r . getByText ( 'label1' ) ) . toBeInTheDocument ( ) ;
3030 expect ( r . getByText ( 'label2' ) ) . toBeInTheDocument ( ) ;
31- expect ( r . queryByText ( 'label5' ) ) . not . toBeInTheDocument ( ) ;
31+ expect ( r . getByText ( 'label3' ) ) . toBeInTheDocument ( ) ;
32+ expect ( r . queryByText ( 'label4' ) ) . not . toBeInTheDocument ( ) ;
33+ expect ( r . getByText ( 'Show more' ) ) . toBeInTheDocument ( ) ;
34+ } ) ;
35+
36+ it ( 'should hide the label at maxLabels index when collapsed' , ( ) => {
37+ const labels = Array . from ( { length : SECRET_MAX_LABELS + 1 } , ( _ , i ) => `label${ i + 1 } ` ) ;
38+ const r = render (
39+ < SecretLabels labels = { labels } index = { 0 } expanded = { false } handleToggle = { ( ) => { } } /> ,
40+ ) ;
41+
42+ labels . slice ( 0 , SECRET_MAX_LABELS ) . forEach ( ( label ) => {
43+ expect ( r . getByText ( label ) ) . toBeInTheDocument ( ) ;
44+ } ) ;
45+ expect ( r . queryByText ( labels [ SECRET_MAX_LABELS ] ) ) . not . toBeInTheDocument ( ) ;
3246 expect ( r . getByText ( 'Show more' ) ) . toBeInTheDocument ( ) ;
3347 } ) ;
3448
You can’t perform that action at this time.
0 commit comments