Skip to content

Commit dd6db52

Browse files
committed
test: update tests for messageCanvas and copy
1 parent 46b9266 commit dd6db52

File tree

3 files changed

+52
-11
lines changed

3 files changed

+52
-11
lines changed

src/components/messageCanvas/actions/copy/copy.cy.tsx

Lines changed: 14 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import 'cypress-real-events'
22

3+
import { supportedViewports } from '../../../../../cypress/support/variables'
34
import Copy from './copy'
45
describe('Copy component', () => {
56
const copyButton = '[data-cy=copy-text-button]'
@@ -14,14 +15,21 @@ describe('Copy component', () => {
1415
data: { text: 'Hello World' },
1516
}
1617

17-
it('should copy text when clicked', () => {
18-
cy.mount(<Copy message={message} />)
18+
supportedViewports.forEach((viewport) => {
19+
it(`should copy text when clicked on ${viewport} screen`, () => {
20+
cy.viewport(viewport)
21+
cy.mount(<Copy message={message} />)
1922

20-
cy.get(copyButton).focus().realClick()
23+
if (viewport === 'iphone-6') {
24+
cy.get(copyButton).focus().realTouch()
25+
} else {
26+
cy.get(copyButton).focus().realClick()
27+
}
2128

22-
cy.window().then((win) => {
23-
win.navigator.clipboard.readText().then((text) => {
24-
expect(text).to.eq('Hello World')
29+
cy.window().then((win) => {
30+
win.navigator.clipboard.readText().then((text) => {
31+
expect(text).to.eq('Hello World')
32+
})
2533
})
2634
})
2735
})

src/components/messageCanvas/messageCanvas.cy.tsx

Lines changed: 37 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@ import 'cypress-real-events'
33

44
import { supportedViewports } from '../../../cypress/support/variables'
55
import Icon from '../icon'
6+
import type { ThreadableMessage } from '../types'
7+
import Copy from './actions/copy/copy'
68
import MessageCanvas from './messageCanvas'
79

810
describe('MessageCanvas', () => {
@@ -30,6 +32,7 @@ describe('MessageCanvas', () => {
3032
},
3133
}
3234

35+
const messageCanvas = '[data-cy=message-canvas]'
3336
supportedViewports.forEach((viewport) => {
3437
it(`renders the component on ${viewport} screen`, () => {
3538
cy.viewport(viewport)
@@ -46,6 +49,36 @@ describe('MessageCanvas', () => {
4649
cy.contains('senderId').should('be.visible')
4750
cy.get('[data-cy="account-circle-icon"]').should('be.visible')
4851
})
52+
53+
it(`allows copying text on ${viewport} screen`, () => {
54+
cy.mount(
55+
<MessageCanvas
56+
message={testMessage}
57+
getActionsComponent={(message: ThreadableMessage) => {
58+
const copyButton = message.format === 'text' && (
59+
<Copy message={message} />
60+
)
61+
if (copyButton) {
62+
return <>{copyButton}</>
63+
}
64+
}}
65+
>
66+
<p>Hello World</p>
67+
</MessageCanvas>
68+
)
69+
if (viewport === 'iphone-6') {
70+
cy.get(messageCanvas).realTouch()
71+
} else {
72+
cy.get(messageCanvas).realHover()
73+
}
74+
75+
cy.get('[data-cy=copy-text-button]').focus().realClick()
76+
cy.window().then((win) => {
77+
win.navigator.clipboard.readText().then((text) => {
78+
expect(text).to.eq('Hello World')
79+
})
80+
})
81+
})
4982
})
5083

5184
context('Desktop', () => {
@@ -60,7 +93,7 @@ describe('MessageCanvas', () => {
6093
</MessageCanvas>
6194
)
6295
cy.contains('Jan 1 2020').should('not.be.visible')
63-
cy.get('.rustic-message-canvas').realHover()
96+
cy.get(messageCanvas).realHover()
6497
cy.contains('Jan 1 2020').should('be.visible')
6598
})
6699

@@ -71,7 +104,7 @@ describe('MessageCanvas', () => {
71104
</MessageCanvas>
72105
)
73106

74-
cy.get('.rustic-message-canvas').realHover()
107+
cy.get(messageCanvas).realHover()
75108
cy.contains('last updated').should('be.visible')
76109
})
77110
})
@@ -88,7 +121,7 @@ describe('MessageCanvas', () => {
88121
</MessageCanvas>
89122
)
90123
cy.contains('Jan 1 2020').should('not.be.visible')
91-
cy.get('.rustic-message-canvas').realTouch()
124+
cy.get(messageCanvas).realTouch()
92125
cy.contains('Jan 1 2020').should('be.visible')
93126
})
94127

@@ -99,7 +132,7 @@ describe('MessageCanvas', () => {
99132
</MessageCanvas>
100133
)
101134

102-
cy.get('.rustic-message-canvas').realTouch()
135+
cy.get(messageCanvas).realTouch()
103136
cy.contains('last updated').should('be.visible')
104137
})
105138
})

src/components/messageCanvas/messageCanvas.stories.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ export default {
1515
docs: {
1616
description: {
1717
component:
18-
'The `MessageCanvas` component serves as a container for displaying messages within a chat interface. It provides a structured layout for rendering message content along with sender information and timestamp details. This component is designed to encapsulate individual message items and facilitate consistent rendering of messages within an application.\n\n##`getActionsComponent`:\n\n`getActionsComponent` is a single React element and can be composed of several actions supported for the message, such as editing, copying, and deleting. The examples of actions are listed below:\n\n###Copy:\n\nOnly supports copying text from text message.\n\nFields:\n\n```message: ThreadableMessage```\n\nAdditional control options are currently under development.\n\n---\n\n###Advance Usage\n\nFor advanced customization of available message actions, developers can import the `Action` component and extend its functionality to incorporate additional actions as needed. This approach offers flexibility in tailoring message interactions to specific application requirements. For an example, see the copy icon below, which extends the functionality of the `Action` component.',
18+
'The `MessageCanvas` component serves as a container for displaying messages within a chat interface. It provides a structured layout for rendering message content along with sender information and timestamp details. This component is designed to encapsulate individual message items and facilitate consistent rendering of messages within an application.\n\n##`getActionsComponent`:\n\n`getActionsComponent` is a single React element and can be composed of several actions supported for the message, such as editing, copying, and deleting. Listed below are actions you can import from the library to use in your application:\n\n###Copy:\n\nOnly supports copying text from text message.\n\nFields:\n\n```message: ThreadableMessage```\n\nAdditional control options are currently under development.\n\n---\n\n###Advance Usage\n\nFor advanced customization of available message actions, developers can import the `Action` component and extend its functionality to incorporate additional actions as needed. This approach offers flexibility in tailoring message interactions to specific application requirements. For an example, see the copy icon below, which extends the functionality of the `Action` component.',
1919
},
2020
},
2121
},

0 commit comments

Comments
 (0)