Skip to content

Conversation

olipyskoty
Copy link
Contributor

Contributing to Twilio

All third party contributors acknowledge that any contributions they provide will be made under the same open source license that the open source project is provided under.

  • I acknowledge that all my contributions will be made under the project's license.

Pull Request Details

JIRA link(s):

Description

This PR adds cypress tests for the chat feature. The tests test the ability to send and receive messages (implicitly) as well as the chat window's scrolling behavior. We also found a small bug in the<MessageListScrollingContainer /> when checking whether to scroll the component to the bottom in the componentDidUpdate() method. We made it so the component only auto-scrolls when the user has a new message and they are already scrolled to the bottom before receiving that message.

Burndown

Before review

  • Updated CHANGELOG.md if necessary
  • Added unit tests if necessary
  • Updated affected documentation
  • Verified locally with npm test
  • Manually sanity tested running locally
  • Included screenshot as PR comment (if needed)
  • Ready for review

Before merge

  • Got one or more +1s
  • Re-tested if necessary

@olipyskoty olipyskoty requested a review from timmydoza March 30, 2021 17:48
Copy link
Contributor

@timmydoza timmydoza left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice work! Left some comments.

Also, my cross-browser fixes are now on the feature/conversations branch. Can you merge that branch in to this one? It has updates to the MessageListScrollContainer component, and I'd like to make sure that these tests still pass with those updates.

Comment on lines 111 to 128
before(() => {
cy.get('[data-cy-chat-button]').click();
});

after(() => {
cy.get('[data-cy-chat-button]').click();
});

it('should see "1 new message" button when not scrolled to bottom of chat and a new message is received', () => {
cy.task('sendAMessage', {
name: 'test1',
message: 'welcome \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n to the chat!',
});
cy.contains('welcome');
cy.get('[data-cy-message-list-inner-scroll]').scrollTo(0, 0);
cy.task('sendAMessage', { name: 'test1', message: 'how is it going?' });
cy.get('[data-cy-message-list-outer]').should('contain', '1 new message');
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When it comes to testing, one general rule is that the order of the tests should not matter. The tests should be written in a way where their order can change and they will still pass. This just helps the tests to be less brittle.

Looks like all the tests rely on the welcome to the chat! message being present, so I think it would be best to move that command up to the before() block. This ensures that the message will be present before all tests are run:

Suggested change
before(() => {
cy.get('[data-cy-chat-button]').click();
});
after(() => {
cy.get('[data-cy-chat-button]').click();
});
it('should see "1 new message" button when not scrolled to bottom of chat and a new message is received', () => {
cy.task('sendAMessage', {
name: 'test1',
message: 'welcome \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n to the chat!',
});
cy.contains('welcome');
cy.get('[data-cy-message-list-inner-scroll]').scrollTo(0, 0);
cy.task('sendAMessage', { name: 'test1', message: 'how is it going?' });
cy.get('[data-cy-message-list-outer]').should('contain', '1 new message');
});
before(() => {
cy.get('[data-cy-chat-button]').click();
cy.task('sendAMessage', {
name: 'test1',
message: 'welcome \n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n\n to the chat!',
});
cy.contains('welcome');
});
after(() => {
cy.get('[data-cy-chat-button]').click();
});
it('should see "1 new message" button when not scrolled to bottom of chat and a new message is received', () => {
cy.get('[data-cy-message-list-inner-scroll]').scrollTo(0, 0);
cy.task('sendAMessage', { name: 'test1', message: 'how is it going?' });
cy.get('[data-cy-message-list-outer]').should('contain', '1 new message');
});

Comment on lines 130 to 141
it('should scroll to bottom of chat when "1 new message button" is clicked on', () => {
cy.get('[data-cy-message-list-inner-scroll]').scrollTo(0, 0);
cy.get('[data-cy-new-message-button]')
.should('be.visible')
.click();
cy.get('[data-cy-message-list-outer]')
.contains('how is it going')
.should('be.visible');
cy.get('[data-cy-message-list-inner-scroll]').should($el => {
expect($el.prop('scrollHeight')).to.equal($el.prop('scrollTop') + $el.prop('clientHeight'));
});
});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. I think this test should send a new message to make the "1 new message" button appear. This way it doesn't matter if the previous test already did this or not:

Suggested change
it('should scroll to bottom of chat when "1 new message button" is clicked on', () => {
cy.get('[data-cy-message-list-inner-scroll]').scrollTo(0, 0);
cy.get('[data-cy-new-message-button]')
.should('be.visible')
.click();
cy.get('[data-cy-message-list-outer]')
.contains('how is it going')
.should('be.visible');
cy.get('[data-cy-message-list-inner-scroll]').should($el => {
expect($el.prop('scrollHeight')).to.equal($el.prop('scrollTop') + $el.prop('clientHeight'));
});
});
it('should scroll to bottom of chat when "1 new message button" is clicked on', () => {
cy.get('[data-cy-message-list-inner-scroll]').scrollTo(0, 0);
cy.task('sendAMessage', { name: 'test1', message: 'Ahoy!' });
cy.contains('Ahoy!');
cy.get('[data-cy-new-message-button]')
.should('be.visible')
.click();
cy.get('[data-cy-message-list-outer]')
.contains('Ahoy!')
.should('be.visible');
cy.get('[data-cy-message-list-inner-scroll]').should($el => {
expect($el.prop('scrollHeight')).to.equal($el.prop('scrollTop') + $el.prop('clientHeight'));
});
});

Comment on lines 135 to 136
cy.get('[data-cy-message-list-outer]')
.contains('how is it going')
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: I think that cy.get('[data-cy-message-list-outer]').contains('foo') is the same as cy.get('[data-cy-message-list-inner-scroll]').contains('foo') since both of those divs wrap the same messages. So let's change all instances of [data-cy-message-list-outer] to [data-cy-message-list-inner-scroll] and remove the [data-cy-message-list-outer] attribute altogether.

@@ -98,6 +100,11 @@ export class MessageListScrollContainer extends React.Component<

handleScroll = throttle(() => {
const innerScrollContainerEl = this.chatThreadRef.current!;
// Because this.handleScroll() is a throttled method,
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice comment! 🎉

@olipyskoty olipyskoty requested a review from timmydoza March 30, 2021 22:58
@olipyskoty olipyskoty merged commit f382369 into feature/conversations Mar 30, 2021
@olipyskoty olipyskoty deleted the VIDEO-3727-cypress-testing branch March 30, 2021 23:30
timmydoza pushed a commit that referenced this pull request Mar 31, 2021
* VIDEO 3731 Conversations UI - create chat window (#421)

* Video 4078 add flip camera button to mobile menu (#433)

VIDEO 4078 Conversations - Add flip camera button to 'more' mobile menu

* Video 3730 add conversation hooks (#438)

* Add initial hooks for chat

* Update hooks in chat provider

* Add tests for conversationProvider component

* Fix DeviceSelectionScreen tests

* Update variable names

* Revert proxy url in package.json

* Fix linting issues

* Make error handling more user friendly

* Fix a test in src/state

* Temporarily disable cypress tests

* Undo prettier changes to config.yml

* Update chatProvider test

* Cleanup ChatProvider

* Video 3732 Conversations UI - create message components (#441)

* Add links to TextMessage component (#446)

* Add links to TextMessage component

* Update CSS in TextMessage

* Update snapshot test

* Fix issue in addLinks function

* Use forEach loop in addLinks function

* Add new server (#443)

* Use new server with reused code

* Add firebase auth to server

* Convert server to typescript

* Add tests for firebaseAuthMiddleware

* Refactor server

* Add more server tests

* Add tests for CreateExpressHandler

* Fix linter issue

* Delete old server

* Fix linter issues

* Fix some server issues

* Set up server build steps

* Change request to match new server api

* Fix token fetch test

* Add server build step to circleci config

* Enable cyress tests in CI

* Undo prettier changes in config.yml

* install plugin-rtc from npm

* Fix firebaseAuth test

* Add create_conversation:true to token requests

* Upgrade plugin-rtc to 0.8.0

* Temorarily remove firebaseAuthMiddleware and recording rules route

* Add ChatProvider back in

* Update .env.example

* Change build:server script

* Add firebaseAuthMiddleware

* Add comments to firebaseAuthMiddleware

* Update useFirebaseAuth tests

* Video 3728 Conversations UI - add input field and send button (#451)

* Chat notification (#454)

* Add notification to chat icon

* Add tests for ToggleChatButton

* Some cleanup

* Fix linting issue

* Video-4525 loading screen (#461)

* Video 4454 Conversations UI -  message list scrolling (#467)

* Update MessageList component to change how messages are grouped (#469)

* Update MessageList component to change how messages are grouped

* Simplify MessageList code

* Video 3888 file input for conversations (#458)

* Add FileAttachmentIcon

* Add File Input to ChatInput component

* Add change handler to file input

* Create MediaMessage component and add it to MessageList

* Toggle ChatWindow visibility with CSS

* Update messageList tests

* Add function to format the file size

* Update error handling in ChatInput component

* Add tests for MediaMessage component

* Update snapshot test

* Add tests for ChatInput

* Fix linting issue

* Update filesize formatting

* Update error language and tests

* Reset file input value after file sent

* Center icon in MediaMessage

* Update Icon size

* Fix breaking ChatInput test

* Update snapshot

* Use accept attribute on file input element

* Update readme to add information about the chat feature and conversations api

* Cross browser fixes (#472)

* Update app.yaml for the new server

* Add cache controls for static assets

* Only hide Screenshare button on mobile devices

* Auto focus on chat input when user opens chat window

* Fix iOS bug with media messages

* Fix issues in MessageListScrollContainer

* Fix app.yaml

* Fix infinite loop when there is a conversations error

* Update tests for ChatInput

* Update mediamessage test

* Update menubar tests

* Update messageList snapshot

* Fix linting issue

* Add comments to the server

* Video 3727 - cypress testing (#473)

* Video 4597 feature flag (#475)

* Update plugin-rtc version

* Add feature flag for Twilio Conversations

* Add tests

* Add info to .env.example

* Update readme with info about twilio conversations (#476)

* Update readme with info about twilio conversations

* Update readme to address feedback

* Release 0.3.0 (#479)

* Bump version and update changelog

* Add plugin-rtc upgrade instructions to the readme

Co-authored-by: olipyskoty <77076398+olipyskoty@users.noreply.github.com>
Co-authored-by: Sean Coleman <smcoleman27@gmail.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants