From the Online Etymology Dictionary it starts to take a figurative sense of "routine" in 1842.
Then we have:
- jazz slang in the groove: "performing well (without grandstanding) in 1932
- american slang groovy: "first-rate, excellent" in 1937
- teen slang groovey: "wonderful" in 1941
The New Grove Dictionary of Jazz by Barry Kernfeld states:
Within jazz circles, Gold identifies the phrase "in the groove" – which from around 1936 to 1945 (i.e., during the height of the swing era) was in widespread use in referring to jazz performances which were "excellent" or, by extension, "sophisticated" – and the term "groove" – referring in the 1940s and 1950s to "routine, preference, style, source of pleasure".
( . . . )
[groove] tends to operate with reference to styles from the latter third of the twentieth century which utilize characteristic accompanimental ostinatos drawn from African-derived dance music, whether African-American (e.g., soul, funk, disco, rap, hip-hop), Afro-Cuban dance music (e.g., salsa), or Afro-Brazilian (samba), or some other such fusion.