-
Notifications
You must be signed in to change notification settings - Fork 155
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
fix: Prevent Flashbar from delaying render when not using animations #1656
Merged
Merged
Changes from 20 commits
Commits
Show all changes
22 commits
Select commit
Hold shift + click to select a range
8f206b3
fix: Prevent Flashbar from delaying render when not using animations
jperals 699d6f0
Remove unnecessary statement in test
jperals c85eb92
Increase coverage for collapsible flashbar with animations
jperals 1e090d4
Use disableMotion to disable motion in tests instead of mocking
jperals dca93ac
Fix import
jperals 8b2b52e
Remove some code duplication
jperals 6af9665
Fix async state update issues in interactive flashbar page
jperals 315370a
Replace ? with ! in test
jperals a46df27
Merge branch 'main' into fix/flashbar-delayed-render
jperals de6a191
Replace usePrevious with useEffectOnUpdate
jperals 06f9be3
Refactor test suite to sue describe.each
jperals b30f6b9
Replace beforeAll and afterAll with beforeEach and afterEach
jperals d009b6c
Revert "Replace usePrevious with useEffectOnUpdate"
jperals acbdb5c
Do not animate flash items in collapsible flashbar in Classic
jperals 55b65a7
Compare HTML output of collapsible flashbar with and without motion
jperals 96acd62
Fix non-collapsible flashbar test not covering version with motion
jperals d959459
Revert "Revert "Replace usePrevious with useEffectOnUpdate""
jperals 4238618
Use findToggleButton to find button in scroll test
jperals 240e352
Use custom list wrapper instead of duplicating code
jperals a7bb8f7
Add missing attributes back
jperals ba5c348
Remove leftover .only
jperals 44c41ba
Revert "Compare HTML output of collapsible flashbar with and without …
jperals File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
import React, { useState } from 'react'; | ||
import createWrapper, { FlashbarWrapper } from '../../../lib/components/test-utils/dom'; | ||
import { render } from '@testing-library/react'; | ||
import { FlashbarProps } from '../interfaces'; | ||
import Button from '../../../lib/components/button'; | ||
import Flashbar from '../../../lib/components/flashbar'; | ||
|
||
export function createFlashbarWrapper(element: React.ReactElement) { | ||
return createWrapper(render(element).container).findFlashbar()!; | ||
} | ||
|
||
export function findList(flashbar: FlashbarWrapper) { | ||
return flashbar.find('ul'); | ||
} | ||
|
||
export function testFlashDismissal({ stackItems }: { stackItems: boolean }) { | ||
const App = () => { | ||
const [items, setItems] = useState<ReadonlyArray<FlashbarProps.MessageDefinition>>([]); | ||
const onDismiss = () => setItems([]); | ||
const onAdd = () => setItems([{ content: 'The content', id: '1', dismissible: true, onDismiss }]); | ||
return ( | ||
<> | ||
<Button onClick={onAdd}>Add an item</Button> | ||
<Flashbar stackItems={stackItems} items={items} /> | ||
</> | ||
); | ||
}; | ||
const appWrapper = createWrapper(render(<App />).container); | ||
expect(appWrapper.findFlashbar()!.findItems()).toHaveLength(0); | ||
appWrapper.findButton()!.click(); | ||
const foundItems = appWrapper.findFlashbar()!.findItems(); | ||
expect(foundItems).toHaveLength(1); | ||
foundItems![0]!.findDismissButton()!.click(); | ||
expect(appWrapper.findFlashbar()!.findItems()).toHaveLength(0); | ||
} |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This makes sure that the new item has the correct id and not the next one. Since React batches state updates, the old logic could lead to two items having the same id.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Or you could just embed this logic inside
generateItem
, so it always produces items with unique ids