Skip to content

Commit

Permalink
test: add isJoiningCompleted
Browse files Browse the repository at this point in the history
  • Loading branch information
Kacper-RF committed Nov 30, 2023
1 parent e0a9bc1 commit 237fab3
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,23 @@ import { connectionSelectors } from './connection.selectors'
import { connectionActions } from './connection.slice'
import { type identityActions } from '../identity/identity.slice'
import { prepareStore } from '../../utils/tests/prepareStore'
import { getFactory } from '../../utils/tests/factories'

import { setupCrypto } from '@quiet/identity'
import { networkActions } from '../network/network.slice'
import { networkSelectors } from '../network/network.selectors'
import { ConnectionProcessInfo, type Identity } from '@quiet/types'
import { initializedCommunities, networkSelectors } from '../network/network.selectors'
import { Community, ConnectionProcessInfo, PublicChannel, type Identity, ChannelMessage } from '@quiet/types'
import { usersSelectors } from '../users/users.selectors'
import { communitiesSelectors } from '../communities/communities.selectors'
import { communitiesActions } from '../communities/communities.slice'
import { publicChannelsSelectors } from '../publicChannels/publicChannels.selectors'
import { generateMessageFactoryContentWithId, getFactory, publicChannels } from '../..'

describe('connectionReducer', () => {
let store: Store
let alice: Identity
let community: Community
let generalChannel: PublicChannel
let generalChannelId: string

beforeEach(async () => {
setupCrypto()
Expand All @@ -24,6 +31,20 @@ describe('connectionReducer', () => {
alice = await factory.create<ReturnType<typeof identityActions.addNewIdentity>['payload']>('Identity', {
nickname: 'alice',
})

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

const generalChannelState = publicChannelsSelectors.generalChannel(store.getState())
if (generalChannelState) generalChannel = generalChannelState
expect(generalChannel).not.toBeUndefined()
expect(generalChannel).toBeDefined()
generalChannelId = generalChannel?.id || ''

await factory.create<ReturnType<typeof publicChannels.actions.test_message>['payload']>('Message', {
identity: alice,
message: generateMessageFactoryContentWithId(generalChannelId),
verifyAutomatically: true,
})
})

it('add initialized communities should add correctly data into the store', () => {
Expand Down Expand Up @@ -98,4 +119,18 @@ describe('connectionReducer', () => {

expect(text).toEqual(ConnectionProcessInfo.BACKEND_MODULES)
})

it('isJoiningCompleted - false', async () => {
const isJoiningCompleted = connectionSelectors.isJoiningCompleted(store.getState())

expect(isJoiningCompleted).toBeFalsy()
})

it('isJoiningCompleted - true', async () => {
store.dispatch(networkActions.addInitializedCommunity('1'))

const isJoiningCompleted = connectionSelectors.isJoiningCompleted(store.getState())

expect(isJoiningCompleted).toBeFalsy()
})
})
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ export const initializedCommunities = createSelector(networkSlice, reducerState
export const isCurrentCommunityInitialized = createSelector(
initializedCommunities,
currentCommunity,
(initializedCommunities, currentCommunity) => {
return currentCommunity && initializedCommunities[currentCommunity.id]
}
(initializedCommunities, currentCommunity) => currentCommunity && initializedCommunities[currentCommunity.id]
)

export const connectedPeers = createSelector(networkSlice, reducerState => {
Expand Down

0 comments on commit 237fab3

Please sign in to comment.