Skip to content

Commit

Permalink
Added assertions
Browse files Browse the repository at this point in the history
  • Loading branch information
ogbeche77 committed Mar 25, 2021
1 parent 1456648 commit c1c19c5
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 35 deletions.
1 change: 1 addition & 0 deletions frontend/chat-plugin/handles/index.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const cyBubble = 'bubble';
export const cyInputbarTextarea = 'inputbarTextarea';
export const cyInputbarButton = 'inputbarButton';
export const cyChatPluginListChat = 'chatPluginListChat';
4 changes: 2 additions & 2 deletions frontend/chat-plugin/src/components/chat/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import {SourceMessage, CommandUnion} from 'render';
import {MessageInfoWrapper} from 'render/components/MessageInfoWrapper';
/* eslint-disable @typescript-eslint/no-var-requires */
const camelcaseKeys = require('camelcase-keys');
import {cyBubble} from 'chat-plugin-handles';
import {cyBubble, cyChatPluginListChat} from 'chat-plugin-handles';

let ws: WebSocket;

Expand Down Expand Up @@ -148,7 +148,7 @@ const Chat = (props: Props) => {
<HeaderBarProp render={headerBar} />
<div className={style.connectedContainer}>
<div className={style.chat}>
<div id="messages" className={style.messages}>
<div id="messages" className={style.messages} data-cy={cyChatPluginListChat}>
{messages.map((message, index: number) => {
const nextMessage = messages[index + 1];
const lastInGroup = nextMessage ? isFromContact(message) !== isFromContact(nextMessage) : true;
Expand Down
49 changes: 20 additions & 29 deletions integration/chat-plugin/websocket_test.spec.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {cyBubble, cyInputbarTextarea, cyInputbarButton} from 'chat-plugin-handles';
import {cyBubble, cyInputbarTextarea, cyInputbarButton, cyChatPluginListChat} from 'chat-plugin-handles';

import {
cyChannelsChatPluginAddButton,
Expand Down Expand Up @@ -29,24 +29,30 @@ describe('Create UI Conversation', () => {
// cy.get(`[data-cy=${cyChannelsChatPluginFormNameInput}]`).type(Cypress.env('chatPluginName'));
// cy.get(`[data-cy=${cyChannelsChatPluginFormSubmitButton}]`).click();

cy.visit('http://airy.core/chatplugin/ui/example?channel_id=' + Cypress.env('channelId'));
cy.visit('http://localhost:8080/chatplugin/ui/example?channel_id=' + Cypress.env('channelId'));
cy.get(`[data-cy=${cyBubble}]`).click();
cy.get(`[data-cy=${cyInputbarTextarea}]`).type(Cypress.env('messageChatplugin'));
cy.get(`[data-cy=${cyInputbarButton}]`).click();

cy.wait(500);

cy.get(`[data-cy=${cyChatPluginListChat}]`).children().its('length').should('eq', 2);

cy.wait(3500);

cy.request('POST', 'http://airy.core/users.login', {
email: 'kazeem@airy.co',
password: 'test1234',
email: 'grace@example.com',
password: 'the_answer_is_42',
}).then(response => {
const newToken = response.body['token'];
console.log('LoginToken', newToken);
const loginToken = response.body['token'];
console.log('LoginToken', loginToken);

cy.request({
method: 'POST',
url: 'http://airy.core/conversations.list',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${newToken}`,
Authorization: `Bearer ${loginToken}`,
},
body: {
cursor: null,
Expand All @@ -60,37 +66,22 @@ describe('Create UI Conversation', () => {
url: 'http://airy.core/messages.send',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${newToken}`,
Authorization: `Bearer ${loginToken}`,
},
body: {
conversation_id: `${conversationId}`,
message: {
text: 'Today is Wednesday',
text: 'Wonderful Day',
},
},
}).then(response => {
expect(response.body.content.text).to.contain('Today is Wednesday');

// cy.request('POST', 'http://airy.core/messages.send', {
// headers: {
// 'Content-Type': 'application/json',
// Authorization: `Bearer ${newToken}`,
// },
// conversation_id: `Bearer ${conversationId}`,
// message: {
// text: 'Hello World',
// },
// }).then(response => {
// expect(response).property('status').to.equal(200); // message sucessfully sent
// expect(response).property('body').to.contain({
// content: '{"text":"Hello World"}',
// });
expect(response).property('status').to.equal(200);
});
cy.wait(3500);

cy.get(`[data-cy=${cyChatPluginListChat}]`).children().its('length').should('eq', 3);
cy.get(`[data-cy=${cyChatPluginListChat}]`).filter(':contains("Wonderful Day")');
});
});

// cy.request('POST', 'http://airy.core/conversation.list'

// // send message on behalf of authenticated user
});
});
6 changes: 3 additions & 3 deletions integration/cypress.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
{
"baseUrl": "http://localhost:8080/ui",
"baseUrl": "http://localhost:8080/ui",
"integrationFolder": "integration",
"testFiles": "**/*.spec.?s",
"env": {
Expand All @@ -8,8 +8,8 @@
"chatPluginName": "Cypress Chatplugin",
"tagName": "Cypress Tag",
"searchQuery": "Cypress Filter",
"messageInbox": "Good Night!",
"messageChatplugin": "Good Morning!",
"messageInbox": "Hello from Cypress Inbox!",
"messageChatplugin": "Hello from Cypress ChatPlugin, Today is Beautiful!",
"channelId": "3502a0a7-933d-5410-b5fc-51f041146d89"
},
"viewportHeight": 800,
Expand Down
1 change: 0 additions & 1 deletion integration/ui/filter_conversation.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ import {
cyChannelsChatPluginConnectButton,
cyChannelsChatPluginFormNameInput,
cyChannelsChatPluginFormSubmitButton,
cyChannelsChatPluginList,
cyChannelsFormBackButton,
} from 'handles';

Expand Down

0 comments on commit c1c19c5

Please sign in to comment.