| 
									
										
										
										
											2018-03-01 02:45:29 +00:00
										 |  |  | import { Selector as $ } from 'testcafe' | 
					
						
							|  |  |  | import { | 
					
						
							|  |  |  |   composeButton, composeInput, composeLengthIndicator, emojiButton, getComposeSelectionStart, getUrl, | 
					
						
							|  |  |  |   homeNavButton, | 
					
						
							| 
									
										
										
										
											2018-03-03 18:11:32 +00:00
										 |  |  |   notificationsNavButton | 
					
						
							| 
									
										
										
										
											2018-03-01 02:45:29 +00:00
										 |  |  | } from '../utils' | 
					
						
							|  |  |  | import { foobarRole } from '../roles' | 
					
						
							|  |  |  | import times from 'lodash/times' | 
					
						
							|  |  |  | 
 | 
					
						
							| 
									
										
										
										
											2018-03-07 05:32:51 +00:00
										 |  |  | fixture`012-compose.js` | 
					
						
							| 
									
										
										
										
											2018-03-01 02:45:29 +00:00
										 |  |  |   .page`http://localhost:4002` | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('shows compose limits', async t => { | 
					
						
							|  |  |  |   await t.useRole(foobarRole) | 
					
						
							|  |  |  |     .hover(composeInput) | 
					
						
							|  |  |  |     .expect(composeLengthIndicator.innerText).eql('500') | 
					
						
							| 
									
										
										
										
											2018-03-23 00:55:35 +00:00
										 |  |  |     .expect(composeButton.hasAttribute('disabled')).notOk() | 
					
						
							| 
									
										
										
										
											2018-03-01 02:45:29 +00:00
										 |  |  |     .typeText(composeInput, 'typing some text') | 
					
						
							|  |  |  |     .expect(composeLengthIndicator.innerText).eql('484') | 
					
						
							|  |  |  |     .expect(composeButton.hasAttribute('disabled')).notOk() | 
					
						
							|  |  |  |     .typeText(composeInput, times(50, () => 'hello world').join(' '), {replace: true, paste: true}) | 
					
						
							|  |  |  |     .expect(composeLengthIndicator.innerText).eql('-99') | 
					
						
							|  |  |  |     .expect(composeButton.getAttribute('disabled')).eql('') | 
					
						
							|  |  |  |     .typeText(composeInput, 'hello world', {replace: true}) | 
					
						
							|  |  |  |     .click(notificationsNavButton) | 
					
						
							|  |  |  |     .expect(getUrl()).contains('/notifications') | 
					
						
							|  |  |  |     .click(homeNavButton) | 
					
						
							|  |  |  |     .expect(getUrl()).eql('http://localhost:4002/') | 
					
						
							|  |  |  |     .expect(composeInput.value).eql('hello world') | 
					
						
							|  |  |  |     .expect(composeLengthIndicator.innerText).eql('489') | 
					
						
							|  |  |  |     .expect(composeButton.hasAttribute('disabled')).notOk() | 
					
						
							|  |  |  |     .selectText(composeInput) | 
					
						
							|  |  |  |     .pressKey('delete') | 
					
						
							|  |  |  |     .expect(composeInput.value).eql('') | 
					
						
							|  |  |  |     .expect(composeLengthIndicator.innerText).eql('500') | 
					
						
							| 
									
										
										
										
											2018-03-23 00:55:35 +00:00
										 |  |  |     .expect(composeButton.hasAttribute('disabled')).notOk() | 
					
						
							| 
									
										
										
										
											2018-03-01 02:45:29 +00:00
										 |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('shows compose limits for URLs/handles', async t => { | 
					
						
							|  |  |  |   await t.useRole(foobarRole) | 
					
						
							|  |  |  |     .expect(composeLengthIndicator.innerText).eql('500') | 
					
						
							| 
									
										
										
										
											2018-03-23 00:55:35 +00:00
										 |  |  |     .expect(composeButton.hasAttribute('disabled')).notOk() | 
					
						
							| 
									
										
										
										
											2018-03-01 02:45:29 +00:00
										 |  |  |     .typeText(composeInput, 'hello world ' + | 
					
						
							|  |  |  |       'http://foo.bar.baz.whatever.example.com/hello ' + | 
					
						
							|  |  |  |       '@reallylongnamethatstretchesonandon@foo.example.com', {paste: true}) | 
					
						
							|  |  |  |     .expect(composeLengthIndicator.innerText).eql('429') | 
					
						
							|  |  |  |     .expect(composeButton.hasAttribute('disabled')).notOk() | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('shows compose limits for emoji', async t => { | 
					
						
							|  |  |  |   await t.useRole(foobarRole) | 
					
						
							|  |  |  |     .typeText(composeInput, 'hello world \ud83c\ude01 \ud83d\udc6a') | 
					
						
							|  |  |  |     .expect(composeLengthIndicator.innerText).eql('485') | 
					
						
							|  |  |  |     .expect(composeButton.hasAttribute('disabled')).notOk() | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('shows compose limits for custom emoji', async t => { | 
					
						
							|  |  |  |   await t.useRole(foobarRole) | 
					
						
							|  |  |  |     .typeText(composeInput, 'hello world ') | 
					
						
							|  |  |  |     .click(emojiButton) | 
					
						
							|  |  |  |     .click($('button img[title=":blobnom:"]')) | 
					
						
							|  |  |  |     .expect(composeInput.value).eql('hello world :blobnom: ') | 
					
						
							|  |  |  |     .expect(composeLengthIndicator.innerText).eql('478') | 
					
						
							|  |  |  | }) | 
					
						
							|  |  |  | 
 | 
					
						
							|  |  |  | test('inserts custom emoji correctly', async t => { | 
					
						
							|  |  |  |   await t.useRole(foobarRole) | 
					
						
							|  |  |  |     .typeText(composeInput, 'hello world') | 
					
						
							|  |  |  |     .selectText(composeInput, 6, 6) | 
					
						
							|  |  |  |     .expect(getComposeSelectionStart()).eql(6) | 
					
						
							|  |  |  |     .click(emojiButton) | 
					
						
							|  |  |  |     .click($('button img[title=":blobpats:"]')) | 
					
						
							|  |  |  |     .expect(composeInput.value).eql('hello :blobpats: world') | 
					
						
							|  |  |  |     .selectText(composeInput, 0, 0) | 
					
						
							|  |  |  |     .expect(getComposeSelectionStart()).eql(0) | 
					
						
							|  |  |  |     .click(emojiButton) | 
					
						
							|  |  |  |     .click($('button img[title=":blobnom:"]')) | 
					
						
							|  |  |  |     .expect(composeInput.value).eql(':blobnom: hello :blobpats: world') | 
					
						
							|  |  |  |     .typeText(composeInput, ' foobar ') | 
					
						
							|  |  |  |     .click(emojiButton) | 
					
						
							|  |  |  |     .click($('button img[title=":blobpeek:"]')) | 
					
						
							|  |  |  |     .expect(composeInput.value).eql(':blobnom: hello :blobpats: world foobar :blobpeek: ') | 
					
						
							|  |  |  | }) | 
					
						
							| 
									
										
										
										
											2018-03-01 05:03:21 +00:00
										 |  |  | 
 | 
					
						
							|  |  |  | test('inserts emoji without typing anything', async t => { | 
					
						
							|  |  |  |   await t.useRole(foobarRole) | 
					
						
							|  |  |  |     .click(emojiButton) | 
					
						
							|  |  |  |     .click($('button img[title=":blobpats:"]')) | 
					
						
							|  |  |  |     .expect(composeInput.value).eql(':blobpats: ') | 
					
						
							|  |  |  |     .click(emojiButton) | 
					
						
							|  |  |  |     .click($('button img[title=":blobpeek:"]')) | 
					
						
							|  |  |  |     .expect(composeInput.value).eql(':blobpeek: :blobpats: ') | 
					
						
							|  |  |  | }) |