Skip to content

Commit

Permalink
fix: v2 slider export (#1705)
Browse files Browse the repository at this point in the history
  • Loading branch information
kswenson authored Dec 24, 2024
1 parent 02af839 commit 822ee37
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 2 deletions.
11 changes: 10 additions & 1 deletion v3/src/components/slider/slider-registration.test.ts
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
import { getSnapshot } from "mobx-state-tree"
import { createCodapDocument } from "../../models/codap/create-codap-document"
import { FreeTileRow, IFreeTileRow } from "../../models/document/free-tile-row"
import { GlobalValue, IGlobalValueSnapshot } from "../../models/global/global-value"
import { getTileComponentInfo } from "../../models/tiles/tile-component-info"
import { getTileContentInfo } from "../../models/tiles/tile-content-info"
import { getGlobalValueManager, getSharedModelManager } from "../../models/tiles/tile-environment"
import { ITileModelSnapshotIn } from "../../models/tiles/tile-model"
import { toV2Id } from "../../utilities/codap-utils"
import { CodapV2Document } from "../../v2/codap-v2-document"
import { exportV2Component } from "../../v2/codap-v2-tile-exporters"
import { importV2Component } from "../../v2/codap-v2-tile-importers"
Expand Down Expand Up @@ -63,9 +65,12 @@ describe("Slider registration", () => {
expect(tile).toBeDefined()
expect(mockInsertTile).toHaveBeenCalledTimes(1)
expect(globalValueManager?.globals.size).toBe(1)
const globalValue = Object.values(getSnapshot(globalValueManager!.globals))[0]

const sliderModel = isSliderModel(tile.content) ? tile.content : undefined
expect(sliderModel).toBeDefined()
expect(sliderModel?.name).toBe(globalValue.name)
expect(sliderModel?.value).toBeCloseTo(globalValue._value)
expect(sliderModel?.animationDirection).toBe("lowToHigh")
expect(sliderModel?.animationMode).toBe("onceOnly")
expect(sliderModel?._animationRate).toBeUndefined()
Expand All @@ -90,7 +95,11 @@ describe("Slider registration", () => {
const sliderExport = exportV2Component({ tile, row, sharedModelManager })
expect(sliderExport?.type).toBe("DG.SliderView")
const sliderStorage = sliderExport!.componentStorage as ICodapV2SliderStorage
expect(sliderStorage._links_?.model).toBeDefined()
expect(sliderStorage._links_?.model).toEqual({
type: "DG.GlobalValue",
id: toV2Id(globalValue.id)
})
expect(sliderStorage.name).toBe(globalValue.name)
expect(sliderStorage.animationDirection).toBe(1)
expect(sliderStorage.animationMode).toBe(1)
expect(sliderStorage.maxPerSecond).toBeNull()
Expand Down
5 changes: 4 additions & 1 deletion v3/src/components/slider/slider-registration.ts
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,8 @@ registerV2TileExporter(kSliderTileType, ({ tile }) => {
const sliderModel = isSliderModel(tile.content) ? tile.content : undefined
if (!sliderModel) return
const {
name,
globalValue,
domain: [lowerBound, upperBound],
animationDirection,
animationMode,
Expand All @@ -104,7 +106,8 @@ registerV2TileExporter(kSliderTileType, ({ tile }) => {
const v3: ICodapV2SliderStorage["v3"] = { scaleType, multipleOf, dateMultipleOfUnit }

const componentStorage: SetOptional<ICodapV2SliderStorage, keyof ICodapV2BaseComponentStorage> = {
_links_: { model: guidLink("DG.GlobalValue", toV2Id(tile.id)) },
_links_: { model: guidLink("DG.GlobalValue", toV2Id(globalValue.id)) },
name, // override tile `name` with slider model `name` (i.e. global value `name`)
...domain,
animationDirection: getAnimationDirectionIndex(animationDirection),
animationMode: getAnimationModeIndex(animationMode),
Expand Down

0 comments on commit 822ee37

Please sign in to comment.