"Count it all joy when trials come your way!" is one of the great impossibilities of Scripture, unless God intervenes and reveals some higher purpose. So this leads to the question, why are there trials?
Let's start from God's perspective. He saved you and me for the express purpose of having intimate fellowship with us or as Ephesians 1 reveals "that we might be holy and blameless before HIm." His whole purpose in dying on the cross and sending His Spirit was to change us into a new creation that conforms to the nature of Jesus Christ. Simply stated, He wants us to be like Him and this will only happen when He becomes all in all. He invites us to share divine nature (2 Peter1:4).
So what is the holdup? That's easy, it's us. We don't realize how much we need to change and often really don't want to do so. We get complacent where we are at, much like the people of Laodicea who thought everything was fine rather than realize how poor, wretched, and naked they really were.
This is where trials come in. When we have problems the circumstances often open us up to realizing that we need help. Failure makes it clear we need to change. James 1 instructs us to let patience have its complete work that we might become "perfect lacking nothing." God gives grace to the humble. Every mistake, every problem, every "impossibility" opens the door for us to cry out for God to take over. Yes, count it joy when trials come and rather than complain, choose to submit to God. He has a beautiful work to do in you.