Skip to content

Commit

Permalink
add rtl test for mobile and desktop
Browse files Browse the repository at this point in the history
  • Loading branch information
Kacper-RF committed Oct 4, 2023
1 parent c6e15ab commit 9b9e7c9
Show file tree
Hide file tree
Showing 3 changed files with 195 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,15 +52,15 @@ const PossibleImpersonationAttackModalComponent: React.FC<PossibleImpersonationA
open,
}) => {
return (
<Modal
open={open}
handleClose={handleClose}
data-testid={'possible-impersonation-attack-modal-component'}
title={'Warning!'}
isBold
addBorder
>
<StyledGrid container item direction='column' justifyContent='flex-start' alignItems='center'>
<Modal open={open} handleClose={handleClose} title={'Warning!'} isBold addBorder>
<StyledGrid
container
item
direction='column'
justifyContent='flex-start'
alignItems='center'
data-testid={'possible-impersonation-attack-modal-component'}
>
<img className={classes.image} src={WarnIcon} />
<Typography variant='h4'>Possible impersonation attack</Typography>
<Typography className={classes.bodyText} variant='body2'>
Expand Down
105 changes: 105 additions & 0 deletions packages/desktop/src/rtl-tests/possibleImpersonationAttack.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
import React from 'react'
import '@testing-library/jest-dom/extend-expect'
import { act } from 'react-dom/test-utils'
import { screen } from '@testing-library/dom'
import { Task } from 'redux-saga'
import MockedSocket from 'socket.io-mock'
import { FactoryGirl } from 'factory-girl'
import { ioMock } from '../shared/setupTests'
import { renderComponent } from '../renderer/testUtils/renderComponent'
import { prepareStore } from '../renderer/testUtils/prepareStore'
import { getFactory, identity, communities, Community, Identity, Store, users } from '@quiet/state-manager'
import PossibleImpersonationAttackModalContainer from '../renderer/components/widgets/possibleImpersonationAttackModal/PossibleImpersonationAttackModal.container'

jest.setTimeout(20_000)

jest.mock('../renderer/index', () => ({
clearCommunity: () => {},
}))

jest.mock('electron', () => {
return {
ipcRenderer: { on: () => {}, send: jest.fn(), sendSync: jest.fn() },
remote: {
BrowserWindow: {
getAllWindows: () => {
return [
{
show: jest.fn(),
isFocused: jest.fn(),
},
]
},
},
},
}
})

describe('Possible Impersonation Attack', () => {
let socket: MockedSocket

let redux: {
store: Store
runSaga: (saga: any) => Task
}
let factory: FactoryGirl

let community: Community
let alice: Identity

beforeEach(async () => {
socket = new MockedSocket()
ioMock.mockImplementation(() => socket)
window.ResizeObserver = jest.fn().mockImplementation(() => ({
observe: jest.fn(),
unobserve: jest.fn(),
disconnect: jest.fn(),
}))

redux = await prepareStore({}, socket)
factory = await getFactory(redux.store)

community = await factory.create<ReturnType<typeof communities.actions.addNewCommunity>['payload']>('Community')

alice = await factory.create<ReturnType<typeof identity.actions.addNewIdentity>['payload']>('Identity', {
id: community.id,
nickname: 'alice',
})
})

it('Open modal when certifcates are duplicated', async () => {
window.HTMLElement.prototype.scrollTo = jest.fn()

renderComponent(
<>
<PossibleImpersonationAttackModalContainer />
</>,
redux.store
)

const cert1 =
'MIIDeDCCAx6gAwIBAgIGAYr6Jw3hMAoGCCqGSM49BAMCMA8xDTALBgNVBAMTBGZyZmQwHhcNMjMxMDA0MTAwNjE4WhcNMzAwMTMxMjMwMDAwWjBJMUcwRQYDVQQDEz5tenhydWhyNWJzdGt3dmp3eWJnZ2Y2M2Jma2dreWw0aWs0bG5lanN1YnFlaG9td3Vpbm43d3JxZC5vbmlvbjBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABGcKhXLUNjkS9+xd0hYfJBOA7bXB5LwZojhzgBQps3SW/CSR6ABiAuirdP0x/byxTXSkZY23lBkvc5CqMjWe3lWjggIqMIICJjAJBgNVHRMEAjAAMAsGA1UdDwQEAwIAgDAdBgNVHSUEFjAUBggrBgEFBQcDAgYIKwYBBQUHAwEwggFHBgkqhkiG9w0BCQwEggE4BIIBNAXhwXxmLy7Gg5uonlWXiqRUimGLj2cPbAoK9DnKHkcohqdLvEzyz6rM7KBewO068fag0d/PR0uh37Oyb7d/JAbBjhJmf8wOl2HfLTThPEEH8isy3bxHXx4Ir5prVVk1zx8UiXtPAu6gK41FY5Oin6SpV07MBewqQGcbCovcbBSwkp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hBpW/GWMnfNR5Wv0Uofzf+A51svouXtFUGEt8aELjqgHMnrwkRR5BHN3XhvVjcYpX9uLf9HcbBdMpgdcrFKLTblTlMcNGczZVAjTt5O6x6MjxlzSHlDnBt8owNPap9xwn0SFgNHfxfg4XXUml1U96G+Ayzgjmu5Hy+A+JZcqSWdK3xyBzf9g9JhSV5tit7W+xzHvD+FFc2434dbYKbJxthxXGQp3mfZz8ILaxtGEeXOewNTXTjvybv9da2ZXofj3ODAdeNZzhy4NQ2ptUU4hW8QFrpr44vJRXeT7JgTpIJaZecPD51UQ3mfqOffYzthM6zhiU5t7tiVo86a4nlVgNJLzGcVJ3aObAnT6M2dnQwGAYKKwYBBAGDjBsCAQQKEwh1c2VybmFtZTA9BgkrBgECAQ8DAQEEMBMuUW1RS0Rqd2tVTjZYRUZQaVA5V0tBaUZjUXNZQlhIWEtzcHhHNlZ1WU1ZVkFHRzBJBgNVHREEQjBAgj50b2lsMnRocGpjcHo1cTYzczZ2YnVweHh0ZG4ydzRsaWNseTV5c3JjeXJzcmp2YnhobmVuamR5ZC5vbmlvbjAKBggqhkjOPQQDAgNIADBFAiBFaaJYuacbj60wEU9uur7lMoWwhf+uavBnKdoKg93LIQIhAMrd3PN6rggZ4gRNNzhno5yrwTm3/B0ZHaG+zGuO7J8c'

redux.store.dispatch(
users.actions.storeUserCertificate({
certificate: cert1,
})
)

redux.store.dispatch(
users.actions.storeUserCertificate({
certificate: cert2,
})
)
await act(async () => {})

const modal = screen.getByTestId('possible-impersonation-attack-modal-component')
expect(modal).toBeVisible()

const button = screen.getByTestId('unregistered-button')
expect(button).toBeVisible()
})
})
81 changes: 81 additions & 0 deletions packages/mobile/src/tests/possibleImpersonationAttack.test.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
import React from 'react'
import '@testing-library/jest-native/extend-expect'
import { act } from '@testing-library/react-native'
import MockedSocket from 'socket.io-mock'
import { ioMock } from '../setupTests'
import { prepareStore } from './utils/prepareStore'
import { renderComponent } from './utils/renderComponent'
import { FactoryGirl } from 'factory-girl'
import { getFactory, communities, identity, users } from '@quiet/state-manager'
import { navigationActions } from '../store/navigation/navigation.slice'
import { PossibleImpersonationAttackScreen } from '../screens/PossibleImpersonationAttack/PossibleImpersonationAttack.screen'
import { ScreenNames } from '../const/ScreenNames.enum'
import { navigationSelectors } from '../store/navigation/navigation.selectors'

describe('Possible Impersonation Attack', () => {
let socket: MockedSocket

let factory: FactoryGirl

beforeEach(async () => {
socket = new MockedSocket()
ioMock.mockImplementation(() => socket)
})

it('Open modal when certifcates are duplicated', async () => {
const { store, root } = await prepareStore({}, socket)

factory = await getFactory(store)

const community = await factory.create<ReturnType<typeof communities.actions.addNewCommunity>['payload']>(
'Community'
)

await factory.create<ReturnType<typeof identity.actions.addNewIdentity>['payload']>('Identity', {
id: community.id,
nickname: 'alice',
})

const route: { key: string; name: ScreenNames.PossibleImpersonationAttackScreen; path?: string | undefined } = {
key: '',
name: ScreenNames.PossibleImpersonationAttackScreen,
}
renderComponent(
<>
<PossibleImpersonationAttackScreen route={route} />
</>,
store
)

const cert1 =
'MIIDeDCCAx6gAwIBAgIGAYr6Jw3hMAoGCCqGSM49BAMCMA8xDTALBgNVBAMTBGZyZmQwHhcNMjMxMDA0MTAwNjE4WhcNMzAwMTMxMjMwMDAwWjBJMUcwRQYDVQQDEz5tenhydWhyNWJzdGt3dmp3eWJnZ2Y2M2Jma2dreWw0aWs0bG5lanN1YnFlaG9td3Vpbm43d3JxZC5vbmlvbjBZMBMGByqGSM49AgEGCCqGSM49AwEHA0IABGcKhXLUNjkS9+xd0hYfJBOA7bXB5LwZojhzgBQps3SW/CSR6ABiAuirdP0x/byxTXSkZY23lBkvc5CqMjWe3lWjggIqMIICJjAJBgNVHRMEAjAAMAsGA1UdDwQEAwIAgDAdBgNVHSUEFjAUBggrBgEFBQcDAgYIKwYBBQUHAwEwggFHBgkqhkiG9w0BCQwEggE4BIIBNAXhwXxmLy7Gg5uonlWXiqRUimGLj2cPbAoK9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0PBAQDAgCAMB0GA1UdJQQWMBQGCCsGAQUFBwMCBggrBgEFBQcDATCCAUcGCSqGSIb3DQEJDASCATgEggE0B/mkyxZeflBGdsVcbR1hHYOhCv8Jlb6FDAmV1HFtHzEn3WNi96hBpW/GWMnfNR5Wv0Uofzf+A51svouXtFUGEt8aELjqgHMnrwkRR5BHN3XhvVjcYpX9uLf9HcbBdMpgdcrFKLTblTlMcNGczZVAjTt5O6x6MjxlzSHlDnBt8owNPap9xwn0SFgNHfxfg4XXUml1U96G+Ayzgjmu5Hy+A+JZcqSWdK3xyBzf9g9JhSV5tit7W+xzHvD+FFc2434dbYKbJxthxXGQp3mfZz8ILaxtGEeXOewNTXTjvybv9da2ZXofj3ODAdeNZzhy4NQ2ptUU4hW8QFrpr44vJRXeT7JgTpIJaZecPD51UQ3mfqOffYzthM6zhiU5t7tiVo86a4nlVgNJLzGcVJ3aObAnT6M2dnQwGAYKKwYBBAGDjBsCAQQKEwh1c2VybmFtZTA9BgkrBgECAQ8DAQEEMBMuUW1RS0Rqd2tVTjZYRUZQaVA5V0tBaUZjUXNZQlhIWEtzcHhHNlZ1WU1ZVkFHRzBJBgNVHREEQjBAgj50b2lsMnRocGpjcHo1cTYzczZ2YnVweHh0ZG4ydzRsaWNseTV5c3JjeXJzcmp2YnhobmVuamR5ZC5vbmlvbjAKBggqhkjOPQQDAgNIADBFAiBFaaJYuacbj60wEU9uur7lMoWwhf+uavBnKdoKg93LIQIhAMrd3PN6rggZ4gRNNzhno5yrwTm3/B0ZHaG+zGuO7J8c'

store.dispatch(
users.actions.storeUserCertificate({
certificate: cert1,
})
)

store.dispatch(
users.actions.storeUserCertificate({
certificate: cert2,
})
)

await act(async () => {})

store.dispatch(navigationActions.redirection())
await act(async () => {})

const duplicateCerts = users.selectors.duplicateCerts(store.getState())
const currentScreen = navigationSelectors.currentScreen(store.getState())

expect(currentScreen).toBe(ScreenNames.PossibleImpersonationAttackScreen)
expect(duplicateCerts).toBeTruthy()

root?.cancel()
})
})

0 comments on commit 9b9e7c9

Please sign in to comment.