Skip to content

Commit

Permalink
Update sliders' unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
mattpap committed Mar 28, 2024
1 parent 3413454 commit 5930ea7
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
3 changes: 3 additions & 0 deletions bokehjs/src/lib/models/widgets/sliders/abstract_slider.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,9 @@ export abstract class AbstractSliderView<T extends number | string> extends Orie
abstract pretty(value: number | string): string

protected _meta: SliderMeta<T>
get meta(): Readonly<SliderMeta<T>> {
return this._meta
}

protected _update_state(): void {
const spec = this._calc_spec()
Expand Down
20 changes: 12 additions & 8 deletions bokehjs/test/unit/models/widgets/slider.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import {expect} from "assertions"
import {expect, expect_not_null} from "assertions"
import {display} from "../../_util"

import {Slider, RangeSlider, DateSlider, DateRangeSlider, DatetimeRangeSlider} from "@bokehjs/models/widgets"
import {CustomJSTickFormatter} from "@bokehjs/models/formatters"
import {isInteger} from "@bokehjs/core/util/types"
import {pairwise} from "@bokehjs/core/util/array"
import {build_view} from "@bokehjs/core/build_views"

describe("SliderView", () => {
Expand All @@ -12,8 +13,7 @@ describe("SliderView", () => {
const s = new Slider({start: 0, end: 10, step: 1, value: 0})
const {view: sv} = await display(s, null)

/* @ts-ignore */
const r = sv._calc_from([5.0])
const r = sv.meta.compute(5.0)
expect(r).to.be.equal(5)
expect(isInteger(r)).to.be.true
})
Expand Down Expand Up @@ -57,8 +57,11 @@ describe("DateSliderView", () => {
const slider = new DateSlider({start, end, value, step: 1})
const {view} = await display(slider, null)

const [next_step] = view._steps()
expect(next_step).to.be.equal([86_400_000, 86_400_000])
const {ticks} = view.meta
expect_not_null(ticks)

const steps = pairwise(ticks, (t0, t1) => t1 - t0)
expect(steps).to.be.equal([86_400_000, 86_400_000, 86_400_000, 86_400_000])
})
})

Expand All @@ -84,10 +87,11 @@ describe("DateRangeSliderView", () => {
const slider = new DateRangeSlider({start, end, value: [start, end], step: 1})
const {view} = await display(slider, null)

const [next_left_step, next_right_step] = view._steps()
const {ticks} = view.meta
expect_not_null(ticks)

expect(next_left_step).to.be.equal([null, 86_400_000])
expect(next_right_step).to.be.equal([86_400_000, null])
const steps = pairwise(ticks, (t0, t1) => t1 - t0)
expect(steps).to.be.equal([86_400_000, 86_400_000, 86_400_000, 86_400_000])
})
})

Expand Down

0 comments on commit 5930ea7

Please sign in to comment.