-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
UIE-153 Environments Storybook and notifications decouple (#4741)
- Loading branch information
1 parent
083ec73
commit 01f55e3
Showing
41 changed files
with
1,099 additions
and
258 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
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 |
---|---|---|
@@ -1,3 +1,5 @@ | ||
import 'src/style.css'; | ||
|
||
import type { Preview } from '@storybook/react'; | ||
import React from 'react'; | ||
|
||
|
Binary file added
BIN
+20 KB
.yarn/cache/@storybook-addon-actions-npm-8.0.0-75a5805655-c24e07def8.zip
Binary file not shown.
Binary file added
BIN
+48.2 KB
.yarn/cache/@storybook-core-events-npm-8.0.0-da75541082-5c58add81b.zip
Binary file not shown.
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
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,6 @@ | ||
// ESLint thinks @terra-ui-packages/test-utils should be listed in dependencies instead of devDependencies. | ||
// TODO: Fix this in ESLint configuration. | ||
// eslint-disable-next-line import/no-extraneous-dependencies | ||
import { getJestConfig } from '@terra-ui-packages/test-utils'; | ||
|
||
export default getJestConfig(); |
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,49 @@ | ||
{ | ||
"name": "@terra-ui-packages/notifications", | ||
"version": "1.0.1", | ||
"scripts": { | ||
"build": "vite build --emptyOutDir", | ||
"dev": "vite build --mode=development --watch", | ||
"test": "jest" | ||
}, | ||
"type": "module", | ||
"module": "./lib/es/index.js", | ||
"main": "./lib/cjs/index.cjs", | ||
"types": "./lib/types/index.d.ts", | ||
"exports": { | ||
".": { | ||
"import": "./lib/es/index.js", | ||
"require": "./lib/cjs/index.cjs", | ||
"types": "./lib/types/index.d.ts" | ||
} | ||
}, | ||
"files": [ | ||
"lib/cjs/**", | ||
"lib/es/**", | ||
"lib/types/**/*.d.ts" | ||
], | ||
"dependencies": { | ||
"@terra-ui-packages/components": "^0.0.6", | ||
"lodash": "^4.17.21" | ||
}, | ||
"devDependencies": { | ||
"@terra-ui-packages/build-utils": "^1.0.0", | ||
"@terra-ui-packages/test-utils": "*", | ||
"@testing-library/dom": "^9.3.1", | ||
"@testing-library/react": "^14.0.0", | ||
"@testing-library/user-event": "^14.4.3", | ||
"@types/jest": "^28.1.8", | ||
"@types/lodash": "^4.14.184", | ||
"@types/react": "^18.2.15", | ||
"@types/testing-library__jest-dom": "^5.14.9", | ||
"jest": "^27.4.3", | ||
"react": "18.2.0", | ||
"react-dom": "18.2.0", | ||
"typescript": "~5.1.6", | ||
"vite": "^4.5.2" | ||
}, | ||
"peerDependencies": { | ||
"react": "18.2.0", | ||
"react-dom": "18.2.0" | ||
} | ||
} |
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 @@ | ||
export * from './useNotifications'; |
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,55 @@ | ||
import { ErrorBoundary } from '@terra-ui-packages/components'; | ||
import { render } from '@testing-library/react'; | ||
import React from 'react'; | ||
|
||
import { NotificationsContract, NotificationsProvider, text, useNotificationsFromContext } from './useNotifications'; | ||
|
||
describe('useNotificationsFromContext', () => { | ||
it('gets notifications provider from context', () => { | ||
// Arrange | ||
const onRenderWithReporter = jest.fn(); | ||
|
||
const TestComponent = () => { | ||
const reporter = useNotificationsFromContext(); | ||
onRenderWithReporter(reporter); | ||
return null; | ||
}; | ||
|
||
const reporter: NotificationsContract = { | ||
notify: jest.fn(), | ||
}; | ||
|
||
// Act | ||
render( | ||
<NotificationsProvider notifications={reporter}> | ||
<TestComponent /> | ||
</NotificationsProvider> | ||
); | ||
|
||
// Assert | ||
expect(onRenderWithReporter).toHaveBeenCalledWith(expect.objectContaining(reporter)); | ||
}); | ||
|
||
it('throw an error if no notifications provider is provided', () => { | ||
// Arrange | ||
const onRenderError = jest.fn(); | ||
|
||
const TestComponent = () => { | ||
useNotificationsFromContext(); | ||
return null; | ||
}; | ||
|
||
// Prevent React from logging the error. | ||
jest.spyOn(console, 'error').mockImplementation(() => {}); | ||
|
||
// Act | ||
render( | ||
<ErrorBoundary onError={onRenderError}> | ||
<TestComponent /> | ||
</ErrorBoundary> | ||
); | ||
|
||
// Assert | ||
expect(onRenderError).toHaveBeenCalledWith(new Error(text.error.noProvider)); | ||
}); | ||
}); |
Oops, something went wrong.