|
| 1 | +import i18next from 'i18next' |
| 2 | +import { makeStoreModule } from '../src/store' |
| 3 | + |
| 4 | +describe('plugin-icon-menu', () => { |
| 5 | + describe('store', () => { |
| 6 | + describe('actions', () => { |
| 7 | + let actionContext |
| 8 | + let commit |
| 9 | + let dispatch |
| 10 | + let storeModule |
| 11 | + beforeEach(() => { |
| 12 | + commit = jest.fn() |
| 13 | + dispatch = jest.fn() |
| 14 | + storeModule = makeStoreModule() |
| 15 | + actionContext = { |
| 16 | + commit, |
| 17 | + dispatch, |
| 18 | + getters: { |
| 19 | + menus: [ |
| 20 | + { id: 'draw', hint: 'Draw hint', plugin: Symbol('draw plugin') }, |
| 21 | + ], |
| 22 | + }, |
| 23 | + rootGetters: {}, |
| 24 | + } |
| 25 | + }) |
| 26 | + describe('openMenuById', () => { |
| 27 | + it('should open the menu with the given id if it is configured', () => { |
| 28 | + const openId = 'gfi' |
| 29 | + actionContext.getters.menus.push({ id: openId }) |
| 30 | + storeModule.actions.openMenuById(actionContext, openId) |
| 31 | + |
| 32 | + expect(commit.mock.calls.length).toEqual(1) |
| 33 | + expect(commit.mock.calls[0][0]).toEqual('setOpen') |
| 34 | + expect(commit.mock.calls[0][1]).toEqual(1) |
| 35 | + expect(dispatch.mock.calls.length).toEqual(1) |
| 36 | + expect(dispatch.mock.calls[0][0]).toEqual('openInMoveHandle') |
| 37 | + expect(dispatch.mock.calls[0][1]).toEqual(1) |
| 38 | + }) |
| 39 | + it('should do nothing if the menu with the given id is not configured', () => { |
| 40 | + storeModule.actions.openMenuById(actionContext, '') |
| 41 | + |
| 42 | + expect(commit.mock.calls.length).toEqual(0) |
| 43 | + expect(dispatch.mock.calls.length).toEqual(0) |
| 44 | + }) |
| 45 | + }) |
| 46 | + describe('openInMoveHandle', () => { |
| 47 | + it('should add the menu with the given index to the moveHandle if the client has the same size as the window and the width of the client is small', () => { |
| 48 | + i18next.init({ |
| 49 | + lng: 'cimode', |
| 50 | + debug: false, |
| 51 | + }) |
| 52 | + |
| 53 | + actionContext.rootGetters.hasWindowSize = true |
| 54 | + actionContext.rootGetters.hasSmallWidth = true |
| 55 | + storeModule.actions.openInMoveHandle(actionContext, 0) |
| 56 | + |
| 57 | + expect(commit.mock.calls.length).toEqual(1) |
| 58 | + expect(commit.mock.calls[0][0]).toEqual('setMoveHandle') |
| 59 | + const secondParameter = commit.mock.calls[0][1] |
| 60 | + expect(typeof secondParameter).toEqual('object') |
| 61 | + expect(secondParameter.closeLabel).toEqual( |
| 62 | + 'plugins.iconMenu.mobileCloseButton' |
| 63 | + ) |
| 64 | + expect(typeof secondParameter.closeFunction).toEqual('function') |
| 65 | + expect(secondParameter.component).toEqual( |
| 66 | + actionContext.getters.menus[0].plugin |
| 67 | + ) |
| 68 | + expect(secondParameter.plugin).toEqual('iconMenu') |
| 69 | + |
| 70 | + expect(dispatch.mock.calls.length).toEqual(0) |
| 71 | + }) |
| 72 | + it('should do nothing if the client either does not have the same size as the window or the width of the client is considered large', () => { |
| 73 | + storeModule.actions.openInMoveHandle(actionContext, 0) |
| 74 | + |
| 75 | + expect(commit.mock.calls.length).toEqual(0) |
| 76 | + expect(dispatch.mock.calls.length).toEqual(0) |
| 77 | + }) |
| 78 | + }) |
| 79 | + }) |
| 80 | + }) |
| 81 | +}) |
0 commit comments