-
Notifications
You must be signed in to change notification settings - Fork 6
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
7 changed files
with
195 additions
and
1 deletion.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
import { DEFAULT_FOLDER_ITEM } from './items'; | ||
import { CURRENT_USER, MEMBERS } from './members'; | ||
|
||
export const ITEM_WITH_CHATBOX_MESSAGES = { | ||
...DEFAULT_FOLDER_ITEM, | ||
id: 'adf09f5a-5688-11eb-ae93-0242ac130004', | ||
path: 'adf09f5a_5688_11eb_ae93_0242ac130004', | ||
name: 'item with chatbox messages', | ||
chat: [ | ||
{ | ||
body: 'message1', | ||
chatId: 'adf09f5a-5688-11eb-ae93-0242ac130004', | ||
createdAt: '2021-08-11T12:56:36.834Z', | ||
creator: CURRENT_USER.id, | ||
}, | ||
{ | ||
body: 'message2', | ||
chatId: 'adf09f5a-5688-11eb-ae93-0242ac130004', | ||
createdAt: '2021-09-11T12:56:36.834Z', | ||
creator: MEMBERS.BOB.id, | ||
}, | ||
], | ||
}; | ||
|
||
export const ITEM_WITHOUT_CHATBOX_MESSAGES = { | ||
...DEFAULT_FOLDER_ITEM, | ||
id: 'bdf09f5a-5688-11eb-ae93-0242ac130001', | ||
path: 'bdf09f5a_5688_11eb_ae93_0242ac130001', | ||
name: 'item without chatbox messages', | ||
chat: [], | ||
}; |
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,98 @@ | ||
import { WebSocket } from '@graasp/websockets/test/mock-client'; | ||
import { buildItemPath } from '../../../../src/config/paths'; | ||
import { | ||
CHATBOX_ID, | ||
CHATBOX_INPUT_BOX_ID, | ||
ITEM_CHATBOX_BUTTON_ID, | ||
} from '../../../../src/config/selectors'; | ||
import { | ||
ITEM_WITHOUT_CHATBOX_MESSAGES, | ||
ITEM_WITH_CHATBOX_MESSAGES, | ||
} from '../../../fixtures/chatbox'; | ||
import { CURRENT_USER, MEMBERS } from '../../../fixtures/members'; | ||
import { WEBSOCKETS_DELAY_TIME } from '../../../support/constants'; | ||
|
||
const openChatbox = () => { | ||
cy.get(`#${ITEM_CHATBOX_BUTTON_ID}`).click(); | ||
cy.wait('@getItemChat'); | ||
}; | ||
|
||
describe('Chatbox Scenarios', () => { | ||
let client; | ||
|
||
beforeEach(() => { | ||
client = new WebSocket(); | ||
}); | ||
|
||
it('Send messages in chatbox', () => { | ||
const item = ITEM_WITH_CHATBOX_MESSAGES; | ||
cy.visitAndMockWs(buildItemPath(item.id), { items: [item] }, client); | ||
|
||
// open chatbox | ||
openChatbox(); | ||
// check the chatbox displays the already saved messages | ||
for (const msg of item.chat) { | ||
cy.get(`#${CHATBOX_ID}`).should('contain', msg.body); | ||
} | ||
|
||
// send message | ||
const message = 'a new message'; | ||
cy.get(`#${CHATBOX_ID} #${CHATBOX_INPUT_BOX_ID} input`).type(message); | ||
cy.get(`#${CHATBOX_ID} #${CHATBOX_INPUT_BOX_ID} button`).click(); | ||
cy.wait('@postItemChatMessage').then(({ request: { body } }) => { | ||
expect(body.body).to.equal(message); | ||
|
||
// mock websocket response | ||
client.receive({ | ||
realm: 'notif', | ||
type: 'update', | ||
topic: 'chat/item', | ||
channel: item.id, | ||
body: { | ||
kind: 'item', | ||
op: 'publish', | ||
message: { | ||
creator: CURRENT_USER.id, | ||
chatId: item.id, | ||
body: message, | ||
}, | ||
}, | ||
}); | ||
cy.wait(WEBSOCKETS_DELAY_TIME); | ||
|
||
// check the new message is visible | ||
cy.get(`#${CHATBOX_ID}`).should('contain', message); | ||
}); | ||
}); | ||
|
||
it('Receive messages in chatbox from websockets', () => { | ||
const item = ITEM_WITHOUT_CHATBOX_MESSAGES; | ||
cy.visitAndMockWs(buildItemPath(item.id), { items: [item] }, client); | ||
|
||
openChatbox(); | ||
|
||
// check websocket: the chatbox displays someone else's message | ||
const bobMessage = 'a message from bob'; | ||
cy.get(`#${CHATBOX_ID}`).then(() => { | ||
client.receive({ | ||
realm: 'notif', | ||
type: 'update', | ||
topic: 'chat/item', | ||
channel: item.id, | ||
body: { | ||
kind: 'item', | ||
op: 'publish', | ||
message: { | ||
creator: MEMBERS.BOB.id, | ||
chatId: item.id, | ||
body: bobMessage, | ||
}, | ||
}, | ||
}); | ||
cy.wait(WEBSOCKETS_DELAY_TIME); | ||
|
||
// check the new message is visible | ||
cy.get(`#${CHATBOX_ID}`).should('contain', bobMessage); | ||
}); | ||
}); | ||
}); |
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
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