forked from yTakkar/React-Instagram-Clone-2.0
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
427 changed files
with
20,864 additions
and
1,162 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
Large diffs are not rendered by default.
Oops, something went wrong.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
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 |
---|---|---|
@@ -1,75 +1,80 @@ | ||
import { post } from 'axios' | ||
import { dispatchHelper } from '../utils/utils' | ||
|
||
export const getConversations = () => | ||
dispatchHelper('GET_CONVERSATIONS', 'get-conversations') | ||
|
||
export const conversationAdded = conversation => { | ||
return { | ||
type: 'CONVERSATION_ADDED', | ||
payload: conversation | ||
} | ||
} | ||
|
||
export const getConversationMessages = (con_id, when) => | ||
dispatchHelper('GET_CONVERSATION_MESSAGES', 'get-conversation-messages', { con_id, when }) | ||
|
||
export const messaged = message => { | ||
return { | ||
type: 'MESSAGE', | ||
payload: message | ||
} | ||
} | ||
|
||
export const changeLastMssg = lastMssg => { | ||
return { | ||
type: 'CHANGE_LAST_MSSG', | ||
payload: lastMssg | ||
} | ||
} | ||
|
||
export const deleteMssg = message_id => { | ||
return { | ||
type: 'DELETE_MESSAGE', | ||
payload: message_id | ||
} | ||
} | ||
|
||
export const unsendAllMessages = mssg_by => { | ||
return { | ||
type: 'UNSEND_ALL_MSSGS', | ||
payload: mssg_by | ||
} | ||
} | ||
|
||
export const deleteCon = con_id => { | ||
return { | ||
type: 'DELETE_CONVERSATION', | ||
payload: con_id | ||
} | ||
} | ||
|
||
export const getConAbout = (con_id, user) => | ||
dispatchHelper('GET_CONVERSATION_ABOUT', 'get-conversation-about', { con_id, user }) | ||
|
||
export const getUnreadMessages = () => | ||
dispatchHelper('GET_UNREAD_MESSAGES', 'get-unread-messages') | ||
|
||
export const readConversation = (con_id, unreadMssgs) => { | ||
return dispatch => { | ||
post('/api/read-conversation', { con_id }) | ||
.then(() => { | ||
dispatch({ type: 'READ_CONVERSATION', payload: con_id }) | ||
unreadMssgs != 0 ? | ||
dispatch({ type: 'UPDATE_UNREAD_CONVERSATIONS', payload: unreadMssgs }) | ||
: null | ||
}) | ||
.catch(e => console.log(e) ) | ||
} | ||
} | ||
|
||
export const getOnlineUsers = () => | ||
dispatchHelper('GET_ONLINE_USERS', 'get-online-users') | ||
|
||
export const getConDetails = con_id => | ||
dispatchHelper('GET_CON_DETAILS', 'get-conversation-details', { con_id }) | ||
import { post } from 'axios' | ||
import { dispatchHelper } from '../utils/utils' | ||
|
||
export const getConversations = () => | ||
dispatchHelper('GET_CONVERSATIONS', 'get-conversations') | ||
|
||
export const conversationAdded = conversation => { | ||
return { | ||
type: 'CONVERSATION_ADDED', | ||
payload: conversation | ||
} | ||
} | ||
|
||
export const getConversationMessages = (con_id, when) => | ||
dispatchHelper('GET_CONVERSATION_MESSAGES', 'get-conversation-messages', { con_id, when }) | ||
|
||
export const messaged = message => { | ||
return { | ||
type: 'MESSAGE', | ||
payload: message | ||
} | ||
} | ||
|
||
export const changeLastMssg = lastMssg => { | ||
return { | ||
type: 'CHANGE_LAST_MSSG', | ||
payload: lastMssg | ||
} | ||
} | ||
|
||
export const deleteMssg = message_id => { | ||
return { | ||
type: 'DELETE_MESSAGE', | ||
payload: message_id | ||
} | ||
} | ||
|
||
export const unsendAllMessages = mssg_by => { | ||
return { | ||
type: 'UNSEND_ALL_MSSGS', | ||
payload: mssg_by | ||
} | ||
} | ||
|
||
export const deleteCon = con_id => { | ||
return { | ||
type: 'DELETE_CONVERSATION', | ||
payload: con_id | ||
} | ||
} | ||
|
||
export const getConAbout = (con_id, user) => | ||
dispatchHelper('GET_CONVERSATION_ABOUT', 'get-conversation-about', { con_id, user }) | ||
|
||
export const getUnreadMessages = () => | ||
dispatchHelper('GET_UNREAD_MESSAGES', 'get-unread-messages') | ||
|
||
export const readConversation = (con_id, unreadMssgs) => { | ||
return dispatch => { | ||
post('/api/read-conversation', { con_id }) | ||
.then(() => { | ||
dispatch({ type: 'READ_CONVERSATION', payload: con_id }) | ||
|
||
unreadMssgs != 0 ? | ||
dispatch({ | ||
type: 'UPDATE_UNREAD_CONVERSATIONS', | ||
payload: unreadMssgs | ||
}) | ||
: null | ||
|
||
}) | ||
.catch(e => console.log(e) ) | ||
} | ||
} | ||
|
||
export const getOnlineUsers = () => | ||
dispatchHelper('GET_ONLINE_USERS', 'get-online-users') | ||
|
||
export const getConDetails = con_id => | ||
dispatchHelper('GET_CON_DETAILS', 'get-conversation-details', { con_id }) |
57 changes: 57 additions & 0 deletions
57
src/components/admin/__test__/__snapshots__/admin-login.test.js.snap
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,57 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`Admin-Login Component should match snapshot 1`] = ` | ||
<div> | ||
<div | ||
style={ | ||
Object { | ||
"animation": "bcCCNc 300ms ease 0s 1 normal none running", | ||
"backfaceVisibility": "visible", | ||
} | ||
} | ||
> | ||
<div | ||
className="cua are-you-admin" | ||
> | ||
<div | ||
className="display_text" | ||
> | ||
<span> | ||
Are you the admin? | ||
</span> | ||
</div> | ||
<form | ||
className="form_login" | ||
onSubmit={[Function]} | ||
> | ||
<input | ||
autoComplete="false" | ||
autoFocus={true} | ||
disabled={false} | ||
id="al_password" | ||
maxLength="255" | ||
onChange={[Function]} | ||
placeholder="Admin password" | ||
required={true} | ||
spellCheck="false" | ||
type="password" | ||
value="" | ||
/> | ||
<span | ||
className="show_psswrd s_p_l" | ||
onClick={[Function]} | ||
> | ||
<i | ||
className="fas fa-lock" | ||
/> | ||
</span> | ||
<input | ||
className="al_submit" | ||
type="submit" | ||
value="Continue as admin" | ||
/> | ||
</form> | ||
</div> | ||
</div> | ||
</div> | ||
`; |
22 changes: 22 additions & 0 deletions
22
src/components/admin/__test__/__snapshots__/is-admin.test.js.snap
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,22 @@ | ||
// Jest Snapshot v1, https://goo.gl/fbAQLP | ||
|
||
exports[`IsAdmin Component should match snapshot 1`] = ` | ||
<div> | ||
<div | ||
style={ | ||
Object { | ||
"animation": "bcCCNc 300ms ease 0s 1 normal none running", | ||
"backfaceVisibility": "visible", | ||
} | ||
} | ||
> | ||
<div | ||
className="registered email_verification" | ||
> | ||
<span> | ||
You can now remove and edit any post, comment, user, group, message, etc. as an admin | ||
</span> | ||
</div> | ||
</div> | ||
</div> | ||
`; |
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 React from 'react' | ||
import { create } from 'react-test-renderer' | ||
import AdminLogin from '../admin-login' | ||
import { Provider } from 'react-redux' | ||
import mockStore from '../../../store/mockStore/mockStore' | ||
import { mount } from 'enzyme' | ||
import { BrowserRouter as Router } from 'react-router-dom' | ||
import MockDataElement from '../../../utils/__test__/mock-dataElement' | ||
|
||
describe('Admin-Login Component', () => { | ||
let dataElement | ||
|
||
beforeAll(() => | ||
dataElement = MockDataElement() | ||
) | ||
|
||
afterAll(() => | ||
dataElement.remove() | ||
) | ||
|
||
const comp = ( | ||
<Provider store={mockStore} > | ||
<Router> | ||
<AdminLogin | ||
location={{ search: '/' }} | ||
/> | ||
</Router> | ||
</Provider> | ||
) | ||
|
||
it('should match snapshot', () => { | ||
const tree = create(comp).toJSON() | ||
expect(tree).toMatchSnapshot() | ||
}) | ||
|
||
it('should mock admin-login submit action', () => { | ||
const wrapper = mount(comp) | ||
wrapper.find('form').simulate( | ||
'submit', | ||
{ preventDefault() {} } | ||
) | ||
}) | ||
|
||
it('should redirect to /is-admin route when user is admin', () => { | ||
dataElement.setAttribute('data-isadmin', 'true') | ||
|
||
// To ignore warning: | ||
// 'You tried to redirect to the same route you're currently on: "/is-admin"' | ||
console.error = jest.fn() | ||
|
||
mount(comp) | ||
expect(location.pathname).toEqual('/is-admin') | ||
}) | ||
|
||
}) |
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,46 @@ | ||
import React from 'react' | ||
import { create } from 'react-test-renderer' | ||
import { Provider } from 'react-redux' | ||
import IsAdmin from '../is-admin' | ||
import mockStore from '../../../store/mockStore/mockStore' | ||
import { BrowserRouter as Router } from 'react-router-dom' | ||
import { mount } from 'enzyme' | ||
import MockDataElement from '../../../utils/__test__/mock-dataElement' | ||
|
||
describe('IsAdmin Component', () => { | ||
let dataElement | ||
|
||
beforeAll(() => { | ||
dataElement = MockDataElement() | ||
dataElement.setAttribute('data-isadmin', 'true') | ||
}) | ||
|
||
afterAll(() => | ||
dataElement.remove() | ||
) | ||
|
||
const comp = ( | ||
<Provider store={mockStore} > | ||
<Router> | ||
<IsAdmin/> | ||
</Router> | ||
</Provider> | ||
) | ||
|
||
it('should match snapshot', () => { | ||
const tree = create(comp).toJSON() | ||
expect(tree).toMatchSnapshot() | ||
}) | ||
|
||
it('should redirect to /admin-login route when user is not an admin', () => { | ||
dataElement.setAttribute('data-isadmin', 'false') | ||
|
||
// To ignore warning: | ||
// 'You tried to redirect to the same route you're currently on: "/is-admin"' | ||
console.error = jest.fn() | ||
|
||
mount(comp) | ||
expect(location.pathname).toEqual('/admin-login') | ||
}) | ||
|
||
}) |
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
Oops, something went wrong.