The problem is that each frame you are changing the animation to either run or idle, and then you change it to jump. As you changed it previously, jump animation starts over every frame. Look at this:
if Input.is_action_pressed("ui_right"):
velocity.x = SPEED
$AnimatedSprite.play("run")
$AnimatedSprite.flip_h = false
elif Input.is_action_pressed("ui_left"):
velocity.x = -SPEED
$AnimatedSprite.play("run")
$AnimatedSprite.flip_h = true
else:
$AnimatedSprite.play("idle")
After this piece of code, animation will be either "run" or "idle", as it will always enter one of those three cases. After that you enter this case:
if not is_on_floor():
$AnimatedSprite.play("jump")
And "jump" starts from the beginning.
You could try something like this instead:
if Input.is_action_pressed("ui_right"):
velocity.x = SPEED
$AnimatedSprite.flip_h = false
elif Input.is_action_pressed("ui_left"):
velocity.x = -SPEED
$AnimatedSprite.flip_h = true
if not is_on_floor():
$AnimatedSprite.play("jump")
elif abs(velocity.x) == SPEED:
$AnimatedSprite.play("run")
else:
$AnimatedSprite.play("idle")