Heat the oil over medium heat. When it's hot, add in the mustard seeds. When they start popping, add in the cumin seeds, then the chile/red pepper flakes. Stir for a few seconds. ( I sometimes have trouble with getting my mustard seeds to pop. I always suspect that it has to do with their age, but I'm only guessing there. If they don't pop in a reasonable amount of time, I just proceed. It's never affected the flavor of the finished dish).
Add the onion, garlic and green chile if you're using one. Stir fry these for 5 minutes, adjusting the heat down partway through the fry time.
Add the potatoes and increase the heat a little. Stir fry for 5 minutes, then cover, turn the heat back down a bit, and cook for 4 minutes. I lift the lid and give them a quick stir halfway through this time. The potatoes and onion will be starting to brown at this point.
Stir in the salt and spices. Reduce the heat to low, cover the pan and continue to cook for 10 minutes. Give a quick stir after the first 5 minutes.
Add the spinach and increase the heat. Stir in the spinach as it wilts, then cover pan again, reduce heat again and let cook for another 7 minutes.
Remove the lid and test one of the potatoes, they should be cooked through at this point. (if not, recover and cook a bit longer) Reduce the heat a little and continue cooking to evaporate any remaining juices from the spinach. Stir frequently during this time to avoid sticking.