Skip to content

Commit e8cb06d

Browse files
Copilotlstein
andcommitted
Fix seek slider thumb position on first display
Set slider value to current index when slider is shown via showSlider() or toggleSlider(). Add tests to verify correct behavior. Co-authored-by: lstein <[email protected]>
1 parent 9c4795a commit e8cb06d

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed

photomap/frontend/static/javascript/seek-slider.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -344,6 +344,9 @@ class SeekSlider {
344344
this.renderSliderTicks();
345345
this.searchResultsChanged = false;
346346
});
347+
// Update slider value to reflect current index
348+
const currentIndex = slideState.getCurrentIndex();
349+
if (this.slider) this.slider.value = currentIndex + 1;
347350
this.resetFadeOutTimer();
348351
}
349352
}
@@ -493,6 +496,9 @@ class SeekSlider {
493496
if (this.scoreSliderRow) this.scoreSliderRow.classList.add("visible");
494497
this.sliderContainer.classList.add("visible");
495498
await this.updateSliderRange();
499+
// Update slider value to reflect current index
500+
const currentIndex = slideState.getCurrentIndex();
501+
if (this.slider) this.slider.value = currentIndex + 1;
496502
await this.renderSliderTicks();
497503
this.resetFadeOutTimer();
498504
} else {

tests/frontend/seek-slider.test.js

Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,4 +188,76 @@ describe('seek-slider.js', () => {
188188
);
189189
});
190190
});
191+
192+
describe('showSlider behavior', () => {
193+
let slider;
194+
let mockSlideState;
195+
196+
// Simulate the showSlider logic for updating slider value
197+
const simulateShowSlider = (slider, getCurrentIndex) => {
198+
const currentIndex = getCurrentIndex();
199+
if (slider) slider.value = currentIndex + 1;
200+
};
201+
202+
beforeEach(() => {
203+
// Create DOM elements
204+
document.body.innerHTML = `
205+
<input type="range" id="slideSeekSlider" min="1" max="100" value="1" />
206+
`;
207+
slider = document.getElementById('slideSeekSlider');
208+
209+
// Mock slideState
210+
mockSlideState = {
211+
getCurrentIndex: jest.fn().mockReturnValue(0)
212+
};
213+
});
214+
215+
afterEach(() => {
216+
document.body.innerHTML = '';
217+
jest.clearAllMocks();
218+
});
219+
220+
it('should set slider value to 1 when current index is 0', () => {
221+
mockSlideState.getCurrentIndex.mockReturnValue(0);
222+
223+
simulateShowSlider(slider, mockSlideState.getCurrentIndex);
224+
225+
expect(slider.value).toBe('1');
226+
});
227+
228+
it('should set slider value to match current index + 1', () => {
229+
mockSlideState.getCurrentIndex.mockReturnValue(49);
230+
231+
simulateShowSlider(slider, mockSlideState.getCurrentIndex);
232+
233+
expect(slider.value).toBe('50');
234+
});
235+
236+
it('should set slider value to max when at last slide', () => {
237+
mockSlideState.getCurrentIndex.mockReturnValue(99);
238+
239+
simulateShowSlider(slider, mockSlideState.getCurrentIndex);
240+
241+
expect(slider.value).toBe('100');
242+
});
243+
244+
it('should handle null slider gracefully', () => {
245+
mockSlideState.getCurrentIndex.mockReturnValue(10);
246+
247+
expect(() => simulateShowSlider(null, mockSlideState.getCurrentIndex)).not.toThrow();
248+
});
249+
250+
it('should update from default value of 1 to current index', () => {
251+
// Slider starts at value 1
252+
expect(slider.value).toBe('1');
253+
254+
// Current index is actually at position 25
255+
mockSlideState.getCurrentIndex.mockReturnValue(25);
256+
257+
simulateShowSlider(slider, mockSlideState.getCurrentIndex);
258+
259+
// Slider should now reflect the actual position
260+
expect(slider.value).toBe('26');
261+
});
262+
});
191263
});

0 commit comments

Comments
 (0)