From 315b7fa81d15779804ed3c5862a11152cef2e333 Mon Sep 17 00:00:00 2001 From: siepra Date: Wed, 11 Oct 2023 14:59:10 +0200 Subject: [PATCH] test: duplicated username warning --- .../ChannelList/ChannelList.screen.tsx | 2 +- .../src/tests/duplicateUsername.test.tsx | 70 +++++++++++++++++++ 2 files changed, 71 insertions(+), 1 deletion(-) create mode 100644 packages/mobile/src/tests/duplicateUsername.test.tsx diff --git a/packages/mobile/src/screens/ChannelList/ChannelList.screen.tsx b/packages/mobile/src/screens/ChannelList/ChannelList.screen.tsx index cdf5885415..a82dee3c3a 100644 --- a/packages/mobile/src/screens/ChannelList/ChannelList.screen.tsx +++ b/packages/mobile/src/screens/ChannelList/ChannelList.screen.tsx @@ -36,7 +36,7 @@ export const ChannelListScreen: FC = () => { }) ) } - }, [dispatch, duplicateCerts]) + }, [dispatch, usernameTaken, duplicateCerts]) const redirect = useCallback( (id: string) => { diff --git a/packages/mobile/src/tests/duplicateUsername.test.tsx b/packages/mobile/src/tests/duplicateUsername.test.tsx new file mode 100644 index 0000000000..3662130bf1 --- /dev/null +++ b/packages/mobile/src/tests/duplicateUsername.test.tsx @@ -0,0 +1,70 @@ +import React from 'react' +import '@testing-library/jest-native/extend-expect' +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 { ScreenNames } from '../const/ScreenNames.enum' +import { initActions } from '../store/init/init.slice' +import { ChannelListScreen } from '../screens/ChannelList/ChannelList.screen' +import { navigationSelectors } from '../store/navigation/navigation.selectors' +import { navigationActions } from '../store/navigation/navigation.slice' + +describe('Duplicate username warning', () => { + let socket: MockedSocket + + let factory: FactoryGirl + + beforeEach(async () => { + socket = new MockedSocket() + ioMock.mockImplementation(() => socket) + }) + + it("Display prompt for username change if it's already taken", async () => { + const { store, root } = await prepareStore({}, socket) + + store.dispatch(initActions.setStoreReady()) + + factory = await getFactory(store) + + const community = await factory.create['payload']>( + 'Community' + ) + + const alice = ( + await factory.build('Identity', { + id: community.id, + nickname: 'alice', + }) + ).payload + + store.dispatch( + users.actions.storeUserCertificate({ + certificate: alice.userCertificate || 'certificate_alice', + }) + ) + + await factory.create['payload']>('Identity', { + id: community.id, + nickname: 'alice', + userCertificate: null, + }) + + store.dispatch(navigationActions.navigation({ screen: ScreenNames.ChannelListScreen })) + + renderComponent(, store) + + // Confirm there's duplication of usernames + const usernameTaken = identity.selectors.usernameTaken(store.getState()) + expect(usernameTaken).toBe(true) + + let currentScreen + + currentScreen = navigationSelectors.currentScreen(store.getState()) + expect(currentScreen).toBe(ScreenNames.UsernameTakenScreen) + + root?.cancel() + }) +})