Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[#1045] Automated testing of the web socket #1382

Merged
merged 7 commits into from
Mar 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 cyChatPluginMessageList = 'chatPluginMessageList';
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, cyChatPluginMessageList} 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={cyChatPluginMessageList}>
{messages.map((message, index: number) => {
const nextMessage = messages[index + 1];
const lastInGroup = nextMessage ? isFromContact(message) !== isFromContact(nextMessage) : true;
Expand Down
1 change: 1 addition & 0 deletions integration/chat-plugin/BUILD
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ ts_web_library(
srcs = glob(["*.spec.ts"]),
deps = [
"//frontend/chat-plugin/handles:chat-plugin-handles",
"//frontend/ui/handles",
pascal-holy marked this conversation as resolved.
Show resolved Hide resolved
"@npm//cypress",
],
)
Expand Down
84 changes: 84 additions & 0 deletions integration/chat-plugin/websocket_test.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
import {cyBubble, cyInputbarTextarea, cyInputbarButton, cyChatPluginMessageList} from 'chat-plugin-handles';

import {
cyChannelsChatPluginAddButton,
cyChannelsChatPluginConnectButton,
cyChannelsChatPluginFormNameInput,
cyChannelsChatPluginFormSubmitButton,
} from 'handles';

describe('Sends message from Inbox to Chatplugin', () => {
it('Login', () => {
cy.visit('/login');
cy.get('form')
.within(() => {
cy.get('input[type=email]').type(Cypress.env('username'));
cy.get('input[type=password]').type(Cypress.env('password'));
})
.submit();

cy.wait(500);

cy.visit('/channels');
cy.wait(500);
cy.url().should('include', '/channels');
cy.get(`[data-cy=${cyChannelsChatPluginAddButton}]`).click();
cy.get(`[data-cy=${cyChannelsChatPluginConnectButton}]`).click();
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.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=${cyChatPluginMessageList}]`).children().its('length').should('eq', 2);

cy.wait(2500);

cy.request('POST', 'http://airy.core/users.login', {
email: Cypress.env('username'),
password: Cypress.env('password'),
}).then(response => {
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 ${loginToken}`,
},
body: {
cursor: null,
page_size: 2,
},
}).then(response => {
const conversationId = response.body.data[0].id;

cy.request({
method: 'POST',
url: 'http://airy.core/messages.send',
headers: {
'Content-Type': 'application/json',
Authorization: `Bearer ${loginToken}`,
},
body: {
conversation_id: `${conversationId}`,
message: {
text: Cypress.env('websocketMessage'),
},
},
}).then(response => {
expect(response).property('status').to.equal(200);
});
cy.wait(3000);

cy.get(`[data-cy=${cyChatPluginMessageList}]`).children().its('length').should('eq', 3);
});
});
});
});
3 changes: 2 additions & 1 deletion integration/cypress.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
"tagName": "Cypress Tag",
"searchQuery": "Cypress Filter",
"messageInbox": "Hello from Cypress Inbox!",
"messageChatplugin": "Hello from Cypress Chatplugin!",
"messageChatplugin": "Hello from Cypress ChatPlugin!",
"websocketMessage": "Websocket Test Message",
"channelId": "3502a0a7-933d-5410-b5fc-51f041146d89"
},
"viewportHeight": 800,
Expand Down
1 change: 0 additions & 1 deletion integration/ui/create_tag.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import {
cyTagsTableRowDisplayDeleteModal,
cyTagsTableRowDisplayDeleteModalInput,
cyTagsTableRowDisplayDeleteModalButton,
cyChannelsChatPluginList,
ogbeche77 marked this conversation as resolved.
Show resolved Hide resolved
cyChannelsFormBackButton,
} from 'handles';

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