Custom exercises: muscles are stored in the map's order, not the order the chips were tapped in

This commit is contained in:
Duarte Santos committed 2026-09-17 11:37:56 +02:00
1 parent 0f7e3e1291
commit 83b2a140d6
3 files changed
+30 -3

No files matched your search

+18
View File
@@ -0,0 +1,18 @@
// A custom exercise used to store its muscles in the order the chips were tapped, so the same
// exercise read differently depending on how it was built (Discord, luckapow).
import { describe, expect, it } from 'vitest'
import { inMuscleOrder, MUSCLES } from './muscles.js'
describe('muscles in the map order', () => {
it('is the same list whatever order it was picked in', () => {
expect(inMuscleOrder(['triceps', 'chest', 'deltoids'])).toEqual(['deltoids', 'chest', 'triceps'])
expect(inMuscleOrder(['chest', 'deltoids', 'triceps'])).toEqual(['deltoids', 'chest', 'triceps'])
})
it('follows MUSCLES, leaves unknown names at the end and the input alone', () => {
const picked = ['calves', 'made-up', 'abs']
expect(inMuscleOrder(picked)).toEqual(['abs', 'calves', 'made-up'])
expect(picked).toEqual(['calves', 'made-up', 'abs'])
expect(inMuscleOrder([...MUSCLES].reverse())).toEqual(MUSCLES)
expect(inMuscleOrder(undefined)).toEqual([])
})
})
+7
View File
@@ -21,6 +21,13 @@ export const MUSCLES = [
'calves', 'tibialis',
]
// A picked list in the map's own order rather than the order the chips were tapped in — two
// people building the same exercise get the same exercise. Unknown names keep their place at the end.
export const inMuscleOrder = list => {
const at = m => { const i = MUSCLES.indexOf(m); return i < 0 ? MUSCLES.length : i }
return [...(list || [])].sort((a, b) => at(a) - at(b))
}
// Drawn as the silhouette, never shaded: they carry no training load.
export const INERT = ['head', 'hair', 'neck', 'hands', 'feet', 'knees', 'ankles']