-
Notifications
You must be signed in to change notification settings - Fork 18
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
1 parent
9421556
commit c0f3325
Showing
7 changed files
with
394 additions
and
6 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
199 changes: 199 additions & 0 deletions
199
packages/messenger-widget/src/components/AddConversation/AddConversation.cy.tsx
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,199 @@ | ||
import { Conversation } from '@dm3-org/dm3-lib-storage'; | ||
import { AuthContext, AuthContextType } from '../../context/AuthContext'; | ||
import { ConversationContext } from '../../context/ConversationContext'; | ||
import { ModalContext } from '../../context/ModalContext'; | ||
import { | ||
StorageContext, | ||
StorageContextType, | ||
} from '../../context/StorageContext'; | ||
import { getMockedAuthContext } from '../../context/testHelper/getMockedAuthContext'; | ||
import { getMockedStorageContext } from '../../context/testHelper/getMockedStorageContext'; | ||
import { UiViewContext } from '../../context/UiViewContext'; | ||
import { DM3 } from '../../widget'; | ||
import AddConversation from './AddConversation'; | ||
import { | ||
DeliveryServiceContext, | ||
DeliveryServiceContextType, | ||
} from '../../context/DeliveryServiceContext'; | ||
import { getMockedDeliveryServiceContext } from '../../context/testHelper/getMockedDeliveryServiceContext'; | ||
import { getMockedTldContext } from '../../context/testHelper/getMockedTldContext'; | ||
import { TLDContext } from '../../context/TLDContext'; | ||
import { getMockedConversationContext } from '../../context/testHelper/getMockedConversationContext'; | ||
import { getEmptyContact } from '../../interfaces/utils'; | ||
import { getMockedDm3Configuration } from '../../context/testHelper/getMockedDm3Configuration'; | ||
import { DM3ConfigurationContext } from '../../context/DM3ConfigurationContext'; | ||
import { getMockedUiViewContext } from '../../context/testHelper/getMockedUiViewContext'; | ||
import { getMockedModalContext } from '../../context/testHelper/getMockedModalContext'; | ||
import { getMockedMainnetProviderContext } from '../../context/testHelper/getMockedMainnetProviderContext'; | ||
import { MainnetProviderContext } from '../../context/ProviderContext'; | ||
import { | ||
MessageContext, | ||
MessageContextType, | ||
} from '../../context/MessageContext'; | ||
import { getMockedMessageContext } from '../../context/testHelper/getMockedMessageContext'; | ||
|
||
// AddConversation component tests | ||
describe('<AddConversation />', () => { | ||
const dm3Config = { | ||
userEnsSubdomain: process.env.REACT_APP_USER_ENS_SUBDOMAIN as string, | ||
addressEnsSubdomain: process.env.REACT_APP_ADDR_ENS_SUBDOMAIN as string, | ||
resolverBackendUrl: process.env.REACT_APP_RESOLVER_BACKEND as string, | ||
profileBaseUrl: process.env.REACT_APP_PROFILE_BASE_URL as string, | ||
defaultDeliveryService: process.env | ||
.REACT_APP_DEFAULT_DELIVERY_SERVICE as string, | ||
backendUrl: process.env.REACT_APP_BACKEND as string, | ||
chainId: process.env.REACT_APP_CHAIN_ID as string, | ||
defaultServiceUrl: process.env.REACT_APP_DEFAULT_SERVICE as string, | ||
ethereumProvider: process.env.REACT_APP_MAINNET_PROVIDER_RPC as string, | ||
walletConnectProjectId: process.env | ||
.REACT_APP_WALLET_CONNECT_PROJECT_ID as string, | ||
publicVapidKey: process.env.REACT_APP_PUBLIC_VAPID_KEY as string, | ||
defaultContact: 'defaultcontact.eth', | ||
nonce: process.env.REACT_APP_NONCE as string, | ||
showAlways: true, | ||
showContacts: true, | ||
}; | ||
|
||
// Mount the Widget component before every test | ||
beforeEach(() => { | ||
// should mount DM3 component and render it | ||
cy.mount(<DM3 {...dm3Config} />); | ||
}); | ||
|
||
// test for render AddConversation component | ||
it('Renders <AddConversation> component', () => { | ||
// should mount AddConversation component and render it | ||
cy.mount(<AddConversation />); | ||
}); | ||
|
||
// test for change in conversation name | ||
it('Should change conversation name', () => { | ||
// should mount AddConversation component and render it | ||
cy.mount(<AddConversation />); | ||
// should change conversation name input field | ||
cy.get('.conversation-name') | ||
.clear() | ||
.type('bob.eth') | ||
.should('have.value', 'bob.eth'); | ||
}); | ||
|
||
// test for invalid conversation name | ||
it('Should display error for invalid conversation name', () => { | ||
// should mount AddConversation component and render it | ||
cy.mount(<AddConversation />); | ||
// should change conversation name input field | ||
cy.get('.conversation-name').clear().type('abc-xyz#.eth'); | ||
// should show error for invalid conversation name | ||
cy.get('.conversation-error').should( | ||
'have.text', | ||
'Invalid address or ENS name', | ||
); | ||
}); | ||
|
||
// test to add conversation name successfully | ||
it('Should change conversation name', () => { | ||
const CONTACT_NAME = 'user.dm3.eth'; | ||
|
||
const authContext: AuthContextType = getMockedAuthContext({ | ||
account: { | ||
ensName: 'alice.eth', | ||
profile: { | ||
deliveryServices: ['ds.eth'], | ||
publicEncryptionKey: '', | ||
publicSigningKey: '', | ||
}, | ||
}, | ||
}); | ||
|
||
const storageContext: StorageContextType = getMockedStorageContext({ | ||
getConversations: function (page: number): Promise<Conversation[]> { | ||
return Promise.resolve([]); | ||
}, | ||
initialized: true, | ||
}); | ||
|
||
const deliveryServiceContext: DeliveryServiceContextType = | ||
getMockedDeliveryServiceContext({ | ||
fetchIncomingMessages: function (ensName: string) { | ||
return Promise.resolve([]); | ||
}, | ||
getDeliveryServiceProperties: function (): Promise<any[]> { | ||
return Promise.resolve([{ sizeLimit: 0 }]); | ||
}, | ||
isInitialized: true, | ||
}); | ||
|
||
const tldContext = getMockedTldContext({ | ||
resolveTLDtoAlias: async (alias: string) => { | ||
return CONTACT_NAME; | ||
}, | ||
}); | ||
|
||
const conversationContext = getMockedConversationContext({ | ||
selectedContact: getEmptyContact( | ||
'max.eth', | ||
undefined, | ||
false, | ||
0, | ||
[], | ||
), | ||
}); | ||
|
||
const uiViewContext = getMockedUiViewContext(); | ||
|
||
const dm3ConfigurationContext = getMockedDm3Configuration(); | ||
|
||
const modalContext = getMockedModalContext({ | ||
showAddConversationModal: true, | ||
setLoaderContent: (loader: string) => { | ||
console.log('loader active...'); | ||
}, | ||
}); | ||
|
||
const mainnetContext = getMockedMainnetProviderContext(); | ||
|
||
const messageContext = getMockedMessageContext() as MessageContextType; | ||
|
||
// should mount AddConversation component and render it | ||
cy.mount( | ||
<> | ||
<DM3ConfigurationContext.Provider | ||
value={dm3ConfigurationContext} | ||
> | ||
<UiViewContext.Provider value={uiViewContext}> | ||
<ModalContext.Provider value={modalContext}> | ||
<MainnetProviderContext.Provider | ||
value={mainnetContext} | ||
> | ||
<TLDContext.Provider value={tldContext}> | ||
<AuthContext.Provider value={authContext}> | ||
<DeliveryServiceContext.Provider | ||
value={deliveryServiceContext} | ||
> | ||
<StorageContext.Provider | ||
value={storageContext} | ||
> | ||
<ConversationContext.Provider | ||
value={conversationContext} | ||
> | ||
<MessageContext.Provider | ||
value={messageContext} | ||
> | ||
<AddConversation /> | ||
</MessageContext.Provider> | ||
</ConversationContext.Provider> | ||
</StorageContext.Provider> | ||
</DeliveryServiceContext.Provider> | ||
</AuthContext.Provider> | ||
</TLDContext.Provider> | ||
</MainnetProviderContext.Provider> | ||
</ModalContext.Provider> | ||
</UiViewContext.Provider> | ||
</DM3ConfigurationContext.Provider> | ||
</>, | ||
); | ||
|
||
// should change conversation name input field | ||
cy.get('.conversation-name').clear().type('bob.eth'); | ||
}); | ||
}); |
35 changes: 30 additions & 5 deletions
35
packages/messenger-widget/src/context/testHelper/getMockedDm3Configuration.ts
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
24 changes: 24 additions & 0 deletions
24
packages/messenger-widget/src/context/testHelper/getMockedMessageContext.ts
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,24 @@ | ||
import { MessageContextType } from '../MessageContext'; | ||
|
||
//Provide a mocked Message context | ||
//Override the default values with the provided values | ||
export const getMockedMessageContext = ( | ||
override?: Partial<MessageContextType>, | ||
) => { | ||
const defaultValues = { | ||
getMessages: (contact: string) => [], | ||
getUnreadMessageCount: (contact: string) => 0, | ||
addMessage: (contact: string, message: any) => | ||
new Promise(() => { | ||
isSuccess: true; | ||
}), | ||
loadMoreMessages: (contact: string) => | ||
new Promise(() => { | ||
return 0; | ||
}), | ||
contactIsLoading: (contact: string) => false, | ||
messages: {}, | ||
}; | ||
|
||
return { ...defaultValues, ...override }; | ||
}; |
103 changes: 103 additions & 0 deletions
103
packages/messenger-widget/src/context/testHelper/getMockedModalContext.ts
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,103 @@ | ||
import { ModalContextType } from '../ModalContext'; | ||
import { NewContact } from './../../interfaces/utils'; | ||
import { | ||
MessageActionType, | ||
ProfileScreenType, | ||
ProfileType, | ||
} from './../../utils/enum-type-utils'; | ||
import { | ||
IConfigureProfileModal, | ||
IOpenEmojiPopup, | ||
PreferencesOptionType, | ||
} from './../../hooks/modals/useModal'; | ||
import { PREFERENCES_ITEMS } from './../../components/Preferences/bl'; | ||
|
||
//Provide a mocked Modal context | ||
//Override the default values with the provided values | ||
export const getMockedModalContext = (override?: Partial<ModalContextType>) => { | ||
const defaultValues = { | ||
loaderContent: '', | ||
setLoaderContent: (content: string) => { | ||
throw new Error('Function not implemented.'); | ||
}, | ||
contactToHide: undefined, | ||
setContactToHide: (action: string | undefined) => { | ||
throw new Error('Function not implemented.'); | ||
}, | ||
addConversation: { | ||
active: false, | ||
ensName: undefined, | ||
processed: false, | ||
}, | ||
setAddConversation: (contact: NewContact) => { | ||
throw new Error('Function not implemented.'); | ||
}, | ||
openEmojiPopup: { action: false, data: undefined }, | ||
setOpenEmojiPopup: (action: IOpenEmojiPopup) => { | ||
throw new Error('Function not implemented.'); | ||
}, | ||
lastMessageAction: MessageActionType.NONE, | ||
setLastMessageAction: (action: MessageActionType) => { | ||
throw new Error('Function not implemented.'); | ||
}, | ||
showProfileConfigurationModal: false, | ||
setShowProfileConfigurationModal: (show: boolean) => { | ||
throw new Error('Function not implemented.'); | ||
}, | ||
showPreferencesModal: false, | ||
setShowPreferencesModal: (show: boolean) => { | ||
throw new Error('Function not implemented.'); | ||
}, | ||
showAboutModal: false, | ||
setShowAboutModal: (show: boolean) => { | ||
throw new Error('Function not implemented.'); | ||
}, | ||
showAddConversationModal: false, | ||
setShowAddConversationModal: (show: boolean) => { | ||
throw new Error('Function not implemented.'); | ||
}, | ||
configureProfileModal: { | ||
profileOptionSelected: ProfileType.DM3_NAME, | ||
onScreen: ProfileScreenType.NONE, | ||
}, | ||
setConfigureProfileModal: (modal: IConfigureProfileModal) => { | ||
throw new Error('Function not implemented.'); | ||
}, | ||
resetConfigureProfileModal: () => { | ||
throw new Error('Function not implemented.'); | ||
}, | ||
resetModalStates: () => { | ||
throw new Error('Function not implemented.'); | ||
}, | ||
preferencesOptionSelected: null, | ||
setPreferencesOptionSelected: (item: PreferencesOptionType | null) => { | ||
throw new Error('Function not implemented.'); | ||
}, | ||
preferencesOptions: [], | ||
updatePreferenceSelected: (ticker: PREFERENCES_ITEMS | null) => { | ||
throw new Error('Function not implemented.'); | ||
}, | ||
disabledOptions: { | ||
notification: { | ||
email: false, | ||
push: false, | ||
}, | ||
profile: { | ||
dm3: [ | ||
{ key: 'dm3', value: false }, | ||
{ key: 'optimism', value: false }, | ||
], | ||
own: [ | ||
{ key: 'ens', value: false }, | ||
{ key: 'gnosis', value: false }, | ||
], | ||
}, | ||
settings: { | ||
messageView: false, | ||
}, | ||
}, | ||
isProfileDialogDisabled: () => false, | ||
}; | ||
|
||
return { ...defaultValues, ...override }; | ||
}; |
Oops, something went wrong.