-
-
Notifications
You must be signed in to change notification settings - Fork 734
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' of https://github.com/Unleash/unleash
- Loading branch information
Showing
50 changed files
with
1,417 additions
and
346 deletions.
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
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
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
30 changes: 30 additions & 0 deletions
30
frontend/src/component/banners/externalBanners/ExternalBanners.tsx
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,30 @@ | ||
import { Banner } from 'component/banners/Banner/Banner'; | ||
import useUiConfig from 'hooks/api/getters/useUiConfig/useUiConfig'; | ||
import { useVariant } from 'hooks/useVariant'; | ||
import { IBanner } from 'interfaces/banner'; | ||
|
||
export const ExternalBanners = () => { | ||
const { uiConfig } = useUiConfig(); | ||
|
||
const bannerVariantFromMessageBannerFlag = useVariant<IBanner | IBanner[]>( | ||
uiConfig.flags.messageBanner, | ||
); | ||
const bannerVariantFromBannerFlag = useVariant<IBanner | IBanner[]>( | ||
uiConfig.flags.banner, | ||
); | ||
|
||
const bannerVariant = | ||
bannerVariantFromMessageBannerFlag || bannerVariantFromBannerFlag || []; | ||
|
||
const banners: IBanner[] = Array.isArray(bannerVariant) | ||
? bannerVariant | ||
: [bannerVariant]; | ||
|
||
return ( | ||
<> | ||
{banners.map((banner) => ( | ||
<Banner key={banner.message} banner={banner} /> | ||
))} | ||
</> | ||
); | ||
}; |
14 changes: 14 additions & 0 deletions
14
frontend/src/component/banners/internalBanners/InternalBanners.tsx
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,14 @@ | ||
import { Banner } from 'component/banners/Banner/Banner'; | ||
import { useBanners } from 'hooks/api/getters/useBanners/useBanners'; | ||
|
||
export const InternalBanners = () => { | ||
const { banners } = useBanners(); | ||
|
||
return ( | ||
<> | ||
{banners.map((banner) => ( | ||
<Banner key={banner.id} banner={banner} /> | ||
))} | ||
</> | ||
); | ||
}; |
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
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
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,112 @@ | ||
import { render, screen, cleanup } from '@testing-library/react'; | ||
import { Sticky } from './Sticky'; | ||
import { IStickyContext, StickyContext } from './StickyContext'; | ||
import { vi, expect } from 'vitest'; | ||
|
||
describe('Sticky component', () => { | ||
let originalConsoleError: () => void; | ||
let mockRegisterStickyItem: () => void; | ||
let mockUnregisterStickyItem: () => void; | ||
let mockGetTopOffset: () => number; | ||
let mockContextValue: IStickyContext; | ||
|
||
beforeEach(() => { | ||
originalConsoleError = console.error; | ||
console.error = vi.fn(); | ||
|
||
mockRegisterStickyItem = vi.fn(); | ||
mockUnregisterStickyItem = vi.fn(); | ||
mockGetTopOffset = vi.fn(() => 10); | ||
|
||
mockContextValue = { | ||
registerStickyItem: mockRegisterStickyItem, | ||
unregisterStickyItem: mockUnregisterStickyItem, | ||
getTopOffset: mockGetTopOffset, | ||
stickyItems: [], | ||
}; | ||
}); | ||
|
||
afterEach(() => { | ||
cleanup(); | ||
console.error = originalConsoleError; | ||
}); | ||
|
||
it('renders correctly within StickyContext', () => { | ||
render( | ||
<StickyContext.Provider value={mockContextValue}> | ||
<Sticky>Content</Sticky> | ||
</StickyContext.Provider>, | ||
); | ||
|
||
expect(screen.getByText('Content')).toBeInTheDocument(); | ||
}); | ||
|
||
it('throws error when not wrapped in StickyContext', () => { | ||
console.error = vi.fn(); | ||
|
||
expect(() => render(<Sticky>Content</Sticky>)).toThrow( | ||
'Sticky component must be used within a StickyProvider', | ||
); | ||
}); | ||
|
||
it('applies sticky positioning', () => { | ||
render( | ||
<StickyContext.Provider value={mockContextValue}> | ||
<Sticky>Content</Sticky> | ||
</StickyContext.Provider>, | ||
); | ||
|
||
const stickyElement = screen.getByText('Content'); | ||
expect(stickyElement).toHaveStyle({ position: 'sticky' }); | ||
}); | ||
|
||
it('registers and unregisters sticky item on mount/unmount', () => { | ||
const { unmount } = render( | ||
<StickyContext.Provider value={mockContextValue}> | ||
<Sticky>Content</Sticky> | ||
</StickyContext.Provider>, | ||
); | ||
|
||
expect(mockRegisterStickyItem).toHaveBeenCalledTimes(1); | ||
|
||
unmount(); | ||
|
||
expect(mockUnregisterStickyItem).toHaveBeenCalledTimes(1); | ||
}); | ||
|
||
it('correctly sets the top value when mounted', async () => { | ||
render( | ||
<StickyContext.Provider value={mockContextValue}> | ||
<Sticky>Content</Sticky> | ||
</StickyContext.Provider>, | ||
); | ||
|
||
const stickyElement = await screen.findByText('Content'); | ||
expect(stickyElement).toHaveStyle({ top: '10px' }); | ||
}); | ||
|
||
it('updates top offset when stickyItems changes', async () => { | ||
const { rerender } = render( | ||
<StickyContext.Provider value={mockContextValue}> | ||
<Sticky>Content</Sticky> | ||
</StickyContext.Provider>, | ||
); | ||
|
||
let stickyElement = await screen.findByText('Content'); | ||
expect(stickyElement).toHaveStyle({ top: '10px' }); | ||
|
||
const updatedMockContextValue = { | ||
...mockContextValue, | ||
getTopOffset: vi.fn(() => 20), | ||
}; | ||
|
||
rerender( | ||
<StickyContext.Provider value={updatedMockContextValue}> | ||
<Sticky>Content</Sticky> | ||
</StickyContext.Provider>, | ||
); | ||
|
||
stickyElement = await screen.findByText('Content'); | ||
expect(stickyElement).toHaveStyle({ top: '20px' }); | ||
}); | ||
}); |
Oops, something went wrong.