123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333 |
- /*
- * <<
- * Davinci
- * ==
- * Copyright (C) 2016 - 2017 EDP
- * ==
- * Licensed under the Apache License, Version 2.0 (the "License");
- * you may not use this file except in compliance with the License.
- * You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS,
- * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- * >>
- */
- import produce from 'immer'
- import reducer, { displayInitialState } from 'app/containers/Display/reducer'
- import actions from 'app/containers/Display/actions'
- import VizActions from 'app/containers/Viz/actions'
- import { ActionTypes as VizActionTypes } from 'containers/Viz/constants'
- import {
- mockDisplayId,
- mockSlideId,
- mockSlideList,
- mockHttpError,
- mockGraphLayerFormed,
- mockSlideLayersOperationInfo,
- mockWidgetFormed,
- mockPasswordToken,
- mockPassword,
- mockChangedOperationInfo,
- mockDeltaSize,
- mockFinish,
- mockSlideSize,
- mockDeltaPosition,
- mockSelected,
- mockExclusive,
- mockBaseLines,
- mockShareLinkParams,
- mockShareToken,
- mockAuthShareToken,
- mockDisplayTitle,
- mockFormedViews,
- mockCurrentDisplayWidgets,
- mockDefaultSlideLayersOperationGraphInfo,
- mockGraphLayerId,
- mockDisplayState,
- mockChartLayerId,
- mockSlideLayersInfoGraphSingle,
- mockSlideSingleGraphLayerFormed,
- defaultSharePanelState
- } from './fixtures'
- describe('displayReducer', () => {
- let state
- beforeEach(() => {
- state = mockDisplayState.display
- })
- it('should handle the editSlidesSuccess action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.lastOperationType = VizActionTypes.EDIT_SLIDES_SUCCESS
- })
- expect(
- reducer(state, VizActions.slidesEdited(mockDisplayId, mockSlideList))
- ).toEqual(expectedResult)
- })
- it('should handle the loadSlideDetail action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.loading.slideLayers = true
- })
- expect(
- reducer(state, actions.loadSlideDetail(mockDisplayId, mockSlideId))
- ).toEqual(expectedResult)
- })
- it('should handle the slideDetailLoaded action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.currentDisplayWidgets = mockCurrentDisplayWidgets
- draft.currentSlideId = mockSlideId
- draft.slideLayers[draft.currentSlideId] = mockSlideSingleGraphLayerFormed
- draft.slideLayersInfo = mockSlideLayersInfoGraphSingle
- draft.slideLayersOperationInfo[draft.currentSlideId] = mockDefaultSlideLayersOperationGraphInfo
- })
- expect(
- reducer(
- state,
- actions.slideDetailLoaded(
- mockSlideId,
- [mockGraphLayerFormed],
- [mockWidgetFormed],
- mockFormedViews
- )
- )
- ).toEqual(expectedResult)
- })
- it('should handle the loadSlideDetailFailure action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.loading.slideLayers = false
- })
- expect(reducer(state, actions.loadSlideDetailFail(mockHttpError))).toEqual(
- expectedResult
- )
- })
- it('should handle the slideLayersDeleted action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.lastOperationType = 'davinci/Display/DELETE_SLIDE_LAYERS_SUCCESS'
- draft.lastLayers = [draft.slideLayers[mockSlideId][mockGraphLayerId]]
- delete draft.slideLayers[mockSlideId][mockGraphLayerId]
- delete draft.slideLayersInfo[mockSlideId][mockGraphLayerId]
- delete draft.slideLayersOperationInfo[mockSlideId][mockGraphLayerId]
- })
- expect(
- reducer(
- state,
- actions.slideLayersDeleted(mockSlideId, [mockGraphLayerId])
- )
- ).toEqual(expectedResult)
- })
- it('should handle the displayPasswordShareLinkLoaded action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.currentDisplayPasswordShareToken = mockPasswordToken
- draft.currentDisplayPasswordPassword = mockPassword
- draft.loading.shareToken = false
- })
- expect(
- reducer(
- state,
- actions.displayPasswordShareLinkLoaded(mockPasswordToken, mockPassword)
- )
- ).toEqual(expectedResult)
- })
- it('should handle the slideLayersEdited action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.lastOperationType = 'davinci/Display/EDIT_SLIDE_LAYERS_SUCCESS'
- draft.lastLayers = [draft.slideLayers[mockSlideId][mockGraphLayerId]]
- })
- expect(
- reducer(
- state,
- actions.slideLayersEdited(mockSlideId, [mockGraphLayerFormed])
- )
- ).toEqual(expectedResult)
- })
- it('should handle the changeLayerOperationInfo action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.slideLayersOperationInfo = mockSlideLayersOperationInfo
- })
- expect(
- reducer(
- state,
- actions.changeLayerOperationInfo(mockGraphLayerId, mockChangedOperationInfo)
- )
- ).toEqual(expectedResult)
- })
- it('should handle the resizeLayerAdjusted action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.slideLayersOperationInfo[draft.currentSlideId][
- mockGraphLayerId
- ].resizing = false
- })
- expect(
- reducer(
- state,
- actions.resizeLayerAdjusted([mockGraphLayerId], mockDeltaSize, true)
- )
- ).toEqual(expectedResult)
- })
- it('should handle the dragLayerAdjusted action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.slideLayersOperationInfo[draft.currentSlideId][
- mockGraphLayerId
- ].dragging = false
- })
- expect(
- reducer(
- state,
- actions.dragLayerAdjusted(
- [mockChartLayerId],
- mockSlideSize,
- mockDeltaPosition,
- mockFinish
- )
- )
- ).toEqual(expectedResult)
- })
- it('should handle the selectLayer action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.slideLayersOperationInfo[draft.currentSlideId][mockGraphLayerId] = {
- dragging: false,
- editing: false,
- resizing: false,
- selected: true
- }
- })
- expect(
- reducer(
- state,
- actions.selectLayer(mockGraphLayerId, mockSelected, mockExclusive)
- )
- ).toEqual(expectedResult)
- })
- it('should handle the clearLayersOperationInfo action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.slideLayersOperationInfo = mockSlideLayersOperationInfo
- })
- expect(
- reducer(state, actions.clearLayersOperationInfo(mockChangedOperationInfo))
- ).toEqual(expectedResult)
- })
- it('should handle the clearEditorBaselines action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.editorBaselines = []
- draft.operateItemParams = []
- draft.slideLayersOperationInfo[draft.currentSlideId][
- mockGraphLayerId
- ].dragging = false
- })
- expect(reducer(state, actions.clearEditorBaselines())).toEqual(
- expectedResult
- )
- })
- it('should handle the showEditorBaselines action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.editorBaselines = [mockBaseLines]
- })
- expect(
- reducer(state, actions.showEditorBaselines([mockBaseLines]))
- ).toEqual(expectedResult)
- })
- it('should handle the slideLayersCopied action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.clipboardLayers = [mockGraphLayerFormed]
- })
- expect(
- reducer(state, actions.slideLayersCopied([mockGraphLayerFormed]))
- ).toEqual(expectedResult)
- })
- it('should handle the loadDisplayShareLink action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.loading.shareToken = true
- draft.currentDisplayAuthorizedShareToken = ''
- })
- expect(
- reducer(state, actions.loadDisplayShareLink(mockShareLinkParams))
- ).toEqual(expectedResult)
- })
- it('should handle the loadDisplayShareLink action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.loading.shareToken = true
- draft.currentDisplayAuthorizedShareToken = ''
- })
- expect(
- reducer(state, actions.loadDisplayShareLink(mockShareLinkParams))
- ).toEqual(expectedResult)
- })
- it('should handle the displayShareLinkLoaded action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.currentDisplayShareToken = mockShareToken
- draft.loading.shareToken = false
- })
- expect(
- reducer(state, actions.displayShareLinkLoaded(mockShareToken))
- ).toEqual(expectedResult)
- })
- it('should handle the displayAuthorizedShareLinkLoaded action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.currentDisplayAuthorizedShareToken = mockAuthShareToken
- draft.loading.shareToken = false
- })
- expect(
- reducer(
- state,
- actions.displayAuthorizedShareLinkLoaded(mockAuthShareToken)
- )
- ).toEqual(expectedResult)
- })
- it('should handle the loadDisplayShareLinkFail action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.loading.shareToken = false
- })
- expect(reducer(state, actions.loadDisplayShareLinkFail())).toEqual(
- expectedResult
- )
- })
- it('should handle the openSharePanel action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.sharePanel = {
- id: mockDisplayId,
- type: 'display',
- title: mockDisplayTitle,
- visible: true
- }
- })
- expect(
- reducer(state, actions.openSharePanel(mockDisplayId, mockDisplayTitle))
- ).toEqual(expectedResult)
- })
- it('should handle the closeSharePanel action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- draft.sharePanel = defaultSharePanelState
- })
- expect(reducer(state, actions.closeSharePanel())).toEqual(expectedResult)
- })
- it('should handle the resetDisplayState action correctly', () => {
- const expectedResult = produce(state, (draft) => {
- return displayInitialState
- })
- expect(reducer(state, actions.resetDisplayState())).toEqual(expectedResult)
- })
- })
|