|
1 | 1 | import 'editor/config'; |
2 | 2 | import {editor} from 'pageflow-scrolled/editor'; |
| 3 | +import {features} from 'pageflow/frontend'; |
3 | 4 | import {ScrolledEntry} from 'editor/models/ScrolledEntry'; |
4 | 5 | import {PreviewMessageController} from 'editor/controllers/PreviewMessageController'; |
5 | 6 | import {InsertContentElementDialogView} from 'editor/views/InsertContentElementDialogView'; |
@@ -47,6 +48,31 @@ describe('PreviewMessageController', () => { |
47 | 48 | })).resolves.toMatchObject({type: 'ACK'}); |
48 | 49 | }); |
49 | 50 |
|
| 51 | + it('sends REVIEW_STATE_RESET to iframe after READY when commenting enabled', () => { |
| 52 | + features.enable('frontend', ['commenting']); |
| 53 | + jest.spyOn(window, 'fetch').mockResolvedValue({ |
| 54 | + ok: true, |
| 55 | + json: () => Promise.resolve({currentUser: {id: 1}, commentThreads: []}) |
| 56 | + }); |
| 57 | + |
| 58 | + const entry = factories.entry(ScrolledEntry, {}, {entryTypeSeed: normalizeSeed()}); |
| 59 | + const iframeWindow = createIframeWindow(); |
| 60 | + |
| 61 | + controller = new PreviewMessageController({entry, iframeWindow}); |
| 62 | + |
| 63 | + return expect(new Promise(resolve => { |
| 64 | + iframeWindow.addEventListener('message', event => { |
| 65 | + if (event.data.type === 'REVIEW_STATE_RESET') { |
| 66 | + resolve(event.data); |
| 67 | + } |
| 68 | + }); |
| 69 | + window.postMessage({type: 'READY'}, '*'); |
| 70 | + })).resolves.toMatchObject({ |
| 71 | + type: 'REVIEW_STATE_RESET', |
| 72 | + payload: {currentUser: {id: 1}, commentThreads: []} |
| 73 | + }); |
| 74 | + }); |
| 75 | + |
50 | 76 | it('sets current section index in model on CHANGE_SECTION message', () => { |
51 | 77 | const entry = factories.entry(ScrolledEntry, {}, {entryTypeSeed: normalizeSeed()}); |
52 | 78 | const iframeWindow = createIframeWindow(); |
@@ -469,6 +495,22 @@ describe('PreviewMessageController', () => { |
469 | 495 | })).resolves.toBe('/'); |
470 | 496 | }); |
471 | 497 |
|
| 498 | + it('navigates to comments route on SELECTED message for contentElementComments', () => { |
| 499 | + const editor = factories.editorApi(); |
| 500 | + const entry = factories.entry(ScrolledEntry, {}, { |
| 501 | + entryTypeSeed: normalizeSeed({ |
| 502 | + contentElements: [{id: 1}] |
| 503 | + }) |
| 504 | + }); |
| 505 | + const iframeWindow = createIframeWindow(); |
| 506 | + controller = new PreviewMessageController({entry, iframeWindow, editor}); |
| 507 | + |
| 508 | + return expect(new Promise(resolve => { |
| 509 | + editor.on('navigate', resolve); |
| 510 | + window.postMessage({type: 'SELECTED', payload: {id: 1, type: 'contentElementComments'}}, '*'); |
| 511 | + })).resolves.toBe('/scrolled/content_elements/1/comments'); |
| 512 | + }); |
| 513 | + |
472 | 514 | it('updates configuration on UPDATE_CONTENT_ELEMENT message', () => { |
473 | 515 | const entry = factories.entry(ScrolledEntry, {}, { |
474 | 516 | entryTypeSeed: normalizeSeed({ |
|
0 commit comments