-
Notifications
You must be signed in to change notification settings - Fork 1
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 #269 from dataswift/dev
Dev
- Loading branch information
Showing
14 changed files
with
1,369 additions
and
243 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
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 @@ | ||
@dataswift:registry=https://npm.pkg.github.com |
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 |
---|---|---|
|
@@ -4,15 +4,16 @@ | |
"private": true, | ||
"dependencies": { | ||
"@dataswift/hat-js": "^0.3.2", | ||
"@dataswift/shared": "v0.0.3", | ||
"@material-ui/core": "^4.11.3", | ||
"@reduxjs/toolkit": "^1.3.5", | ||
"@testing-library/jest-dom": "^5.11.6", | ||
"@testing-library/react": "^11.2.2", | ||
"date-fns": "^2.12.0", | ||
"hmi": "git+ssh://[email protected]:dataswift/hmi-react.git#v0.3.4", | ||
"js-cookie": "^2.2.1", | ||
"lodash": "^4.17.19", | ||
"lodash-es": "^4.17.20", | ||
"lodash": "^4.17.21", | ||
"lodash-es": "^4.17.21", | ||
"markdown-to-jsx": "^7.1.0", | ||
"query-string": "^6.14.1", | ||
"react": "^17.0.1", | ||
|
@@ -22,7 +23,7 @@ | |
"react-redux": "^7.2.2", | ||
"react-router": "^5.1.2", | ||
"react-router-dom": "^5.1.2", | ||
"react-scripts": "^4.0.1", | ||
"react-scripts": "^4.0.3", | ||
"redux": "^4.0.5", | ||
"redux-thunk": "^2.3.0", | ||
"typescript": "^4.2.3" | ||
|
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,17 +1,19 @@ | ||
import React from 'react'; | ||
import { Provider } from 'react-redux'; | ||
import { store } from './store'; | ||
import { LanguageParamHandler } from "./LanguageParamHandler"; | ||
import { LanguageParamHandler } from './LanguageParamHandler'; | ||
import { RibbonProvider } from '@dataswift/shared'; | ||
|
||
type Props = { | ||
children: React.ReactNode; | ||
}; | ||
|
||
const Root: React.FC<Props> = props => | ||
const Root: React.FC<Props> = (props) => ( | ||
<Provider store={store}> | ||
<LanguageParamHandler> | ||
{props.children} | ||
</LanguageParamHandler> | ||
</Provider>; | ||
<RibbonProvider> | ||
<LanguageParamHandler>{props.children}</LanguageParamHandler> | ||
</RibbonProvider> | ||
</Provider> | ||
); | ||
|
||
export default Root; |
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,85 @@ | ||
import React from 'react'; | ||
import { screen, render, waitFor, fireEvent } from '@testing-library/react'; | ||
import { Provider } from 'react-redux'; | ||
import { MemoryRouter as Router } from 'react-router-dom'; | ||
|
||
import { fetchNotification } from '../../services/NotificationService'; | ||
import { RibbonProvider } from '@dataswift/shared'; | ||
import { PublicProfile } from './PublicProfile'; | ||
import { configureStore } from '@reduxjs/toolkit'; | ||
import publicProfileSlice from './publicProfileSlice'; | ||
import authenticationSlice from '../authentication/authenticationSlice'; | ||
|
||
import TEST_PROFILE from '../../testData/Profile'; | ||
|
||
jest.mock('../../services/NotificationService'); | ||
const mockFetchNotification: jest.Mocked<any> = fetchNotification; | ||
|
||
const STUB_DATE = '2021-01-01T00:00:00Z'; | ||
|
||
const store = configureStore({ | ||
reducer: { | ||
authentication: authenticationSlice, | ||
publicProfile: publicProfileSlice, | ||
}, | ||
preloadedState: { | ||
publicProfile: { | ||
pending: false, | ||
profile: TEST_PROFILE, | ||
}, | ||
authentication: { | ||
isAuthenticated: true, | ||
}, | ||
}, | ||
}); | ||
|
||
const renderWithProviders = (ui: any) => { | ||
return { | ||
...render( | ||
<Provider store={store}> | ||
<RibbonProvider> | ||
<Router>{ui}</Router> | ||
</RibbonProvider> | ||
</Provider>, | ||
), | ||
}; | ||
}; | ||
|
||
beforeEach(() => { | ||
jest.resetAllMocks(); | ||
}); | ||
|
||
describe('Public Profile Page', () => { | ||
test('renders without error', () => { | ||
renderWithProviders(<PublicProfile />); | ||
|
||
expect(screen.getByText('Public profile of')).toBeInTheDocument(); | ||
}); | ||
|
||
test('notification appears when landing on the screen', async () => { | ||
window.open = jest.fn(); | ||
window.localStorage.clear(); | ||
mockFetchNotification.mockResolvedValueOnce({ | ||
title: 'ribbon notification', | ||
link: 'testLink', | ||
}); | ||
renderWithProviders(<PublicProfile />); | ||
|
||
await waitFor(() => expect(screen.queryByText('ribbon notification')).toBeInTheDocument()); | ||
fireEvent.click(screen.getByText('ribbon notification')); | ||
expect(window.open).toHaveBeenCalledTimes(1); | ||
expect(window.open).toHaveBeenCalledWith('testLink'); | ||
}); | ||
|
||
test('notification does not appear is the date is the same as the curent day.', async () => { | ||
jest.spyOn(global.Date, 'now').mockImplementation(() => new Date(STUB_DATE).valueOf()); | ||
window.localStorage.setItem('dataswift-notification', JSON.stringify(STUB_DATE)); | ||
mockFetchNotification.mockResolvedValueOnce({ | ||
title: 'ribbon notification', | ||
}); | ||
|
||
renderWithProviders(<PublicProfile />); | ||
|
||
await waitFor(() => expect(screen.queryByText('ribbon notification')).toBeNull()); | ||
}); | ||
}); |
Oops, something went wrong.