If your windows license is oem rather than retail ensure you sign in with your Microsoft account on the old hardware before upgrading.
Once you have installed the new hardware, Windows will show as not being activated but if you follow the prompts and confirm you have installed new hardware then windows will reactivate with no trouble.
I completed the above only last week following a motherboard, cpu and memory upgrade. (i even went AMD to intel and my windows installation switched over seemlessly)