It is similarly unlikely there will be a test which can predict imminent dementia well enough that you would be happy to euthanise yourself while you still have decision making capacity.
As others have said, what you can do is have some legal document which explains your wishes if you lose capacity to make decisions, where you specify the avoidance of life prolonging therapies, intensive care, resuscitation etc. The other thing which is important is having someone that will take over medical decision making whom you trust will act according to your wishes, in the event you lose decision making capacity. Another aspect of this is making sure friends and family are aware of your wishes. This is a kindness to them as much as anything, so that when the time comes to withhold or withdraw medical treatment, they don't have to ruminate on whether it is the right thing to do.