-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1358 from openedx/eahmadjaved/ENT-9782
feat: added dismissable warning banner on analytics v2
- Loading branch information
Showing
4 changed files
with
69 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
import React, { useState } from 'react'; | ||
import Cookies from 'universal-cookie'; | ||
import { | ||
PageBanner, | ||
} from '@openedx/paragon'; | ||
import { ANALYTICS_WARNING_BANNER_COOKIE } from './data/constants'; | ||
|
||
const WarningBanner = () => { | ||
const [showBanner, setShowBanner] = useState(true); | ||
const cookies = new Cookies(); | ||
|
||
const onDismiss = () => { | ||
setShowBanner(false); | ||
cookies.set(ANALYTICS_WARNING_BANNER_COOKIE, true, { sameSite: 'strict' }); | ||
}; | ||
return ( | ||
<PageBanner | ||
variant="warning" | ||
dismissible | ||
show={showBanner} | ||
onDismiss={onDismiss} | ||
> | ||
🚀 Analytics Just Got Better! We've updated charts, improved performance, | ||
and now include audit enrollments for a more complete view of your data. | ||
</PageBanner> | ||
); | ||
}; | ||
|
||
export default WarningBanner; |
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
32 changes: 32 additions & 0 deletions
32
src/components/AdvanceAnalyticsV2/tests/WarningBanner.test.jsx
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,32 @@ | ||
import React from 'react'; | ||
import { render, screen, fireEvent } from '@testing-library/react'; | ||
import Cookies from 'universal-cookie'; | ||
import WarningBanner from '../WarningBanner'; | ||
import '@testing-library/jest-dom'; | ||
|
||
// jest.mock('universal-cookie'); | ||
jest.mock('universal-cookie', () => jest.fn().mockImplementation(() => ({ | ||
set: jest.fn(), | ||
}))); | ||
|
||
describe('WarningBanner', () => { | ||
let cookies; | ||
|
||
beforeEach(() => { | ||
cookies = new Cookies(); | ||
cookies.set = jest.fn(); | ||
}); | ||
|
||
test('should trigger onDismiss and set cookie in warning banner', () => { | ||
render(<WarningBanner />); | ||
|
||
// Check that the banner is initially shown | ||
expect(screen.getByText(/Analytics Just Got Better!/i)).toBeInTheDocument(); | ||
|
||
// Trigger the onDismiss function | ||
fireEvent.click(screen.getByRole('button', { name: /Dismiss/i })); | ||
|
||
// Check that the banner is no longer shown | ||
expect(screen.queryByText(/Analytics Just Got Better!/i)).not.toBeInTheDocument(); | ||
}); | ||
}); |