2021-11-30 09:54:14 -05:00
|
|
|
import sinon from 'sinon'
|
2021-12-14 08:24:53 -05:00
|
|
|
import fetchMock from 'fetch-mock'
|
|
|
|
import { expect } from 'chai'
|
2021-11-30 09:54:14 -05:00
|
|
|
import { fireEvent, screen } from '@testing-library/react'
|
2021-11-03 09:21:14 -04:00
|
|
|
import LayoutDropdownButton from '../../../../../frontend/js/features/editor-navigation-toolbar/components/layout-dropdown-button'
|
2021-11-30 09:54:14 -05:00
|
|
|
import { renderWithEditorContext } from '../../../helpers/render-with-context'
|
2021-12-14 08:24:53 -05:00
|
|
|
import * as eventTracking from '../../../../../frontend/js/infrastructure/event-tracking'
|
|
|
|
|
2021-11-03 09:21:14 -04:00
|
|
|
describe('<LayoutDropdownButton />', function () {
|
2021-11-30 09:54:14 -05:00
|
|
|
let openStub
|
2022-04-22 09:49:26 -04:00
|
|
|
let sendMBSpy
|
2021-11-30 09:54:14 -05:00
|
|
|
const defaultUi = {
|
2021-11-03 09:21:14 -04:00
|
|
|
pdfLayout: 'flat',
|
2021-11-15 11:33:57 -05:00
|
|
|
view: 'pdf',
|
2021-11-03 09:21:14 -04:00
|
|
|
}
|
|
|
|
|
2021-11-30 09:54:14 -05:00
|
|
|
beforeEach(function () {
|
|
|
|
openStub = sinon.stub(window, 'open')
|
2022-04-22 09:49:26 -04:00
|
|
|
sendMBSpy = sinon.spy(eventTracking, 'sendMB')
|
2021-12-14 08:24:53 -05:00
|
|
|
window.metaAttributesCache = new Map()
|
2021-11-30 09:54:14 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
afterEach(function () {
|
|
|
|
openStub.restore()
|
2022-04-22 09:49:26 -04:00
|
|
|
sendMBSpy.restore()
|
2021-12-14 08:24:53 -05:00
|
|
|
window.metaAttributesCache = new Map()
|
|
|
|
fetchMock.restore()
|
2021-11-30 09:54:14 -05:00
|
|
|
})
|
|
|
|
|
2021-11-15 11:33:57 -05:00
|
|
|
it('should mark current layout option as selected', function () {
|
|
|
|
// Selected is aria-label, visually we show a checkmark
|
2021-11-30 09:54:14 -05:00
|
|
|
renderWithEditorContext(<LayoutDropdownButton />, { ui: defaultUi })
|
2021-11-03 09:21:14 -04:00
|
|
|
screen.getByRole('menuitem', {
|
|
|
|
name: 'Editor & PDF',
|
|
|
|
})
|
|
|
|
screen.getByRole('menuitem', {
|
2021-11-15 11:33:57 -05:00
|
|
|
name: 'Selected PDF only (hide editor)',
|
2021-11-03 09:21:14 -04:00
|
|
|
})
|
2021-11-15 11:33:57 -05:00
|
|
|
screen.getByRole('menuitem', {
|
|
|
|
name: 'Editor only (hide PDF)',
|
|
|
|
})
|
|
|
|
screen.getByRole('menuitem', {
|
2021-11-30 09:54:14 -05:00
|
|
|
name: 'PDF in separate tab',
|
2021-11-15 11:33:57 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2022-03-15 09:55:17 -04:00
|
|
|
it('should not select any option in history view', function () {
|
|
|
|
// Selected is aria-label, visually we show a checkmark
|
|
|
|
renderWithEditorContext(<LayoutDropdownButton />, {
|
|
|
|
ui: { ...defaultUi, view: 'history' },
|
|
|
|
})
|
|
|
|
screen.getByRole('menuitem', {
|
|
|
|
name: 'Editor & PDF',
|
|
|
|
})
|
|
|
|
screen.getByRole('menuitem', {
|
|
|
|
name: 'PDF only (hide editor)',
|
|
|
|
})
|
|
|
|
screen.getByRole('menuitem', {
|
|
|
|
name: 'Editor only (hide PDF)',
|
|
|
|
})
|
|
|
|
screen.getByRole('menuitem', {
|
|
|
|
name: 'PDF in separate tab',
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should treat file and editor views the same way', function () {
|
|
|
|
// Selected is aria-label, visually we show a checkmark
|
|
|
|
renderWithEditorContext(<LayoutDropdownButton />, {
|
|
|
|
ui: {
|
|
|
|
pdfLayout: 'flat',
|
|
|
|
view: 'file',
|
|
|
|
},
|
|
|
|
})
|
|
|
|
screen.getByRole('menuitem', {
|
|
|
|
name: 'Editor & PDF',
|
|
|
|
})
|
|
|
|
screen.getByRole('menuitem', {
|
|
|
|
name: 'PDF only (hide editor)',
|
|
|
|
})
|
|
|
|
screen.getByRole('menuitem', {
|
|
|
|
name: 'Selected Editor only (hide PDF)',
|
|
|
|
})
|
|
|
|
screen.getByRole('menuitem', {
|
|
|
|
name: 'PDF in separate tab',
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
2021-12-14 08:24:53 -05:00
|
|
|
describe('on detach', function () {
|
2022-05-16 05:52:12 -04:00
|
|
|
let originalBroadcastChannel
|
2021-12-14 08:24:53 -05:00
|
|
|
beforeEach(function () {
|
2022-05-16 05:52:12 -04:00
|
|
|
window.BroadcastChannel = originalBroadcastChannel || true // ensure that window.BroadcastChannel is truthy
|
|
|
|
|
2021-12-14 08:24:53 -05:00
|
|
|
renderWithEditorContext(<LayoutDropdownButton />, {
|
|
|
|
ui: { ...defaultUi, view: 'editor' },
|
|
|
|
})
|
|
|
|
|
|
|
|
const menuItem = screen.getByRole('menuitem', {
|
|
|
|
name: 'PDF in separate tab',
|
|
|
|
})
|
|
|
|
fireEvent.click(menuItem)
|
2021-11-15 11:33:57 -05:00
|
|
|
})
|
|
|
|
|
2022-05-16 05:52:12 -04:00
|
|
|
afterEach(function () {
|
|
|
|
window.BroadcastChannel = originalBroadcastChannel
|
|
|
|
})
|
|
|
|
|
2021-12-14 08:24:53 -05:00
|
|
|
it('should show processing', function () {
|
|
|
|
screen.getByText('Layout processing')
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should record event', function () {
|
2022-04-22 09:49:26 -04:00
|
|
|
sinon.assert.calledWith(sendMBSpy, 'project-layout-detach')
|
2021-12-14 08:24:53 -05:00
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('on layout change / reattach', function () {
|
|
|
|
beforeEach(function () {
|
|
|
|
window.metaAttributesCache.set('ol-detachRole', 'detacher')
|
|
|
|
renderWithEditorContext(<LayoutDropdownButton />, {
|
|
|
|
ui: { ...defaultUi, view: 'editor' },
|
|
|
|
})
|
|
|
|
|
|
|
|
const menuItem = screen.getByRole('menuitem', {
|
|
|
|
name: 'Editor only (hide PDF)',
|
|
|
|
})
|
|
|
|
fireEvent.click(menuItem)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should not show processing', function () {
|
|
|
|
const processingText = screen.queryByText('Layout processing')
|
|
|
|
expect(processingText).to.not.exist
|
|
|
|
})
|
|
|
|
|
|
|
|
it('should record events', function () {
|
2022-04-22 09:49:26 -04:00
|
|
|
sinon.assert.calledWith(sendMBSpy, 'project-layout-reattach')
|
|
|
|
sinon.assert.calledWith(sendMBSpy, 'project-layout-change', {
|
|
|
|
layout: 'flat',
|
|
|
|
view: 'editor',
|
|
|
|
})
|
2021-11-30 09:54:14 -05:00
|
|
|
})
|
2021-11-15 11:33:57 -05:00
|
|
|
|
2021-12-14 08:24:53 -05:00
|
|
|
it('should select new menu item', function () {
|
|
|
|
screen.getByRole('menuitem', {
|
|
|
|
name: 'Selected Editor only (hide PDF)',
|
|
|
|
})
|
|
|
|
})
|
2021-11-03 09:21:14 -04:00
|
|
|
})
|
|
|
|
})
|