Allah tests those He love.
“It is He who created death and life to test which of you are best in deeds, for He is the Almighty, the Forgiving.” (Qur'an 67:2).
It could be that you dislike something, when it is good for you; and it could be that you like something when it is bad for you. Allah knows, and you do not know. Quran 2:216
When we shift our perspective from what Allah is doing to us, to what Allah is doing for us, we are able to see that although Allah may not always give us what we want, He will always give us exactly what we need
He gives your people to love you, leave you, Inspire you, doubt you and to believe in you
He tests us to strengthen our Imaan an make us stronger
When Allah test his servants its because He wants to raise His rank in Jannah
Prophet (ﷺ) says: "If Allah wants to do good to somebody, He afflicts him with trials" [Imam Bukhari]
We don't know what is good or bad for us and we cannot see the future, so whatever Allah decrees on us, we should accept in and place our Tawakkul in Allah. "Verily with difficulty comes ease" [94:5]
Leave all your matter to Allah, and you will never be disappointed.