-
Notifications
You must be signed in to change notification settings - Fork 294
runfix: show expand option for collections over limit [FS-1025] #13921
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 2 commits
93acde5
e26110a
96a70fd
b29da69
2871746
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
/* | ||
* Wire | ||
* Copyright (C) 2022 Wire Swiss GmbH | ||
* | ||
* This program is free software: you can redistribute it and/or modify | ||
* it under the terms of the GNU General Public License as published by | ||
* the Free Software Foundation, either version 3 of the License, or | ||
* (at your option) any later version. | ||
* | ||
* This program is distributed in the hope that it will be useful, | ||
* but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
* GNU General Public License for more details. | ||
* | ||
* You should have received a copy of the GNU General Public License | ||
* along with this program. If not, see http://www.gnu.org/licenses/. | ||
* | ||
*/ | ||
|
||
import {render, fireEvent} from '@testing-library/react'; | ||
|
||
import CollectionSection from './CollectionSection'; | ||
import {ContentMessage} from '../../../../entity/message/ContentMessage'; | ||
import {createRandomUuid} from 'Util/util'; | ||
|
||
const NUMBER_OF_ASSETS = 5; | ||
|
||
const messages = new Array(NUMBER_OF_ASSETS).fill(null).map(() => new ContentMessage(createRandomUuid())); | ||
|
||
const getDefaultProps = ({limit}: {limit: number}) => ({ | ||
PatrykBuniX marked this conversation as resolved.
Show resolved
Hide resolved
|
||
label: 'cool collection', | ||
limit, | ||
messages, | ||
onSelect: jest.fn(), | ||
uieName: 'cool-collection', | ||
}); | ||
|
||
describe('CollectionSection', () => { | ||
it('does not show show all button when under or equal a limit', async () => { | ||
const props = getDefaultProps({limit: NUMBER_OF_ASSETS + 1}); | ||
const {queryByText, rerender} = render( | ||
<CollectionSection {...props}> | ||
<span className={`collection-header-icon icon-library`}></span> | ||
</CollectionSection>, | ||
); | ||
|
||
props.limit = NUMBER_OF_ASSETS; | ||
expect(queryByText('collectionShowAll')).toBeNull(); | ||
|
||
rerender( | ||
<CollectionSection {...props}> | ||
<span className={`collection-header-icon icon-library`}></span> | ||
</CollectionSection>, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Please create mock for it, and pass eg. <Collection {...props} />, you have 3 same Collection sections, only have different limit prop :) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I've ended up using just empty There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. So if children not needed so use <CollectionSection {...props} /> :D There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I did not say it's not needed... It's required, but we can pass anything we want here (this test does not test what's inside) |
||
); | ||
|
||
expect(queryByText('collectionShowAll')).toBeNull(); | ||
}); | ||
|
||
it('does show show all button when over a limit', async () => { | ||
const {getByText} = render( | ||
<CollectionSection {...getDefaultProps({limit: NUMBER_OF_ASSETS - 1})}> | ||
<span className={`collection-header-icon icon-library`}></span> | ||
</CollectionSection>, | ||
); | ||
|
||
expect(getByText('collectionShowAll')).toBeDefined(); | ||
}); | ||
|
||
it('triggers onSelect callback on show all button click', async () => { | ||
const props = getDefaultProps({limit: NUMBER_OF_ASSETS - 1}); | ||
const {getByText} = render( | ||
<CollectionSection {...props}> | ||
<span className={`collection-header-icon icon-library`}></span> | ||
</CollectionSection>, | ||
); | ||
|
||
const button = getByText('collectionShowAll'); | ||
fireEvent.click(button); | ||
|
||
expect(props.onSelect).toHaveBeenCalled(); | ||
}); | ||
}); |
Uh oh!
There was an error while loading. Please reload this page.