Creating a test helper0:00
Okay, what else do I like to change here? So I think this is something that we're going to use a lot. We have a course and we create a video. Two lines here, not too long. Let's check this here. We're using this here. We're using it here. The same just for three videos. Here again. Here again. And yeah, it seems like we are using this a lot. And every time when there's just two or three liners which are going to use a lot, I think about if there is a better way to call this. So what I like to do in this case is to create a new helper method. And we have seen that we can do this inside our Pest file, like with the function which we have already used, or what do we have here, to get rid of the unused namespace. Like this one. So yeah, if you want to use something globally in all our tests,
have already used, or what do we have here, to get rid of the unused namespace. Like this one. So yeah, if you want to use something globally in all our tests, then it's good to have this inside your pest file so that it's available for all the tests. But inside one test, when there is something like this, which we're going to use a lot, I like just to create a method inside here. There's also a sequence which we don't need. Let's get rid of this. So we can just create here a new function. This is all working since this is not a class. We can just create a function. Let's call it createCourseAndVideos. And I want to provide here the count of the videos. videosCount and I want it by default to be one. Yeah, because we don't have to provide it if we're just creating one video. Okay,
count of the videos. videos count and I want it by default to be one. Yeah, because we don't have to provide it if we're just creating one video. Okay, let's copy this in here. We are getting a course and we're calling the video factory. And we're going to call the count with the videoCount, videosCount. And I think we're also going to want you to return the course because it seems we're going to use it. So let's add the course as a return type here. All right, let's give it a try. Create course and videos. I think we just need one. And now it's one line. I think it's pretty good to read. And it's less code, which I always like. And the code is still working. Perfect. So let's also try to use this now for the other tests here. So this should be the same. We're just creating one video. That's good. Working. Now this will be interesting here.
Using named arguments2:38
Perfect. So let's also try to use this now for the other tests here. So this should be the same. We're just creating one Video. That's good. Working. Now this will be interesting here. We're creating it with three Videos. So we can do this like that. And it's working. And the little issue which we have here with the number which we provide to the method is that we don't really know what it does. Or to be fair, we know what it does because we know it's about the video count. But many other developers will not see it until they get to the method itself. So what is better here is what we can do is use a named argument. So let's bring in videosCount, which is the name of the argument. And now this is very good to read for everyone coming to this file. I really like this. And let's check this again. We're using it here one more time. Here with an argument because we're just creating one Video. This is also passing good. And also
file. I really like this. And let's check this again. We're using it here one more time. Here with an argument because we're just creating one video. This is also passing good. And also here. We don't have to do anything else. We don't have to provide the argument. This looks good. And yeah, I think we've now made sure that all of the tests are still working. And I think this is now, where do we have it here? It's now very good to read. And I think, do we need to use it here? Let's check again. Oh yeah, here we need to use it. Okay. So I'm fine with keeping the User here. But for the courses, this is now very nice. And we have now this little helper method, which is now inside our test file because we're probably only going to need it inside this test. Okay. And there's another thing. Let me check where do we have this method. It shows list of all courses. Yeah. So here we're checking that we show all the videos, all the videos of the course.
Planning sidebar behavior4:27
Okay. And there's another thing. Let me check where do we have this method. It shows list of all courses. Yeah. So here we're checking that we show all the videos, all the videos of the course on the page with the title. And we also want to make sure that we see all the routes here. But I can already mention, there will be a kind of sidebar on the left or right next to our video with all the other videos to choose from. But here we are saying that we also want to see the link for the current video in the sidebar, which we actually don't really need because from the sidebar, we only want to switch to a different video. So this means we want to switch to the second and to the third video, but not to the one which we already have. So I think it's a good idea to check that we actually don't see this one. And what we could do is we could also add this here so that we don't see anything. But this, I think is a very specific test.
Adding a new test5:13
good idea to check that we actually don't see this one. And what we could do is we could also add this here so that we don't see anything. But this, I think is a very specific test. And as I told you already, if something is a little bit more specific and a little bit different from the other things we are testing here, I like to do this in a different test. So let's create a new one. It does not include route for current video. And let me just copy a few things here from the other test. So I think it's already enough if we create a Course with one Video, and then we want to make sure that we don't see the route for this one Video. Yeah. So here we want to make sure assertDontSee HTML. So we want to make sure that we don't see something in the HTML. And then let's copy also how we create this route course videos. I think here we can just grab the first one, which I think is a little bit better to read. And I think this
Updating the view logic6:06
in the HTML. And then let's copy also how we create this route course videos. I think here we can just grab the first one, which I think is a little bit better to read. And I think this should already do it. Let's try it. And it's failing because feeling that it does not contain something, but probably it is contained inside our view file. This means now we have the chance to make this pass by checking this inside our view file. So let's see how can we check this? We want to make sure that if the current videoId equals the current video of the loop currentVideoId. So if this is the same, then we don't want to provide the link. And let me just copy this in here for now. And I think we can put this here at the end. And here we're now going to use an else. Format this. All right. So if the current video of the player, if the ID is equal to the ID of the current video inside the sidebar, which we're currently looping through, then it is the
an else. Format this. All right. So if the current video of the player, if the ID is equal to the ID of the current video inside the sidebar, which we're currently looping through, then it is the current video. And then we only want to show the title and we don't want to show another link. I think this should be it. And yeah, you can see this is already passing. It does not include the route for the current video, but also this other test should fail now. If everything is correct, what we've implemented and it is because now this shouldn't be in here. This is the link for the current video. Let's delete this. And now this should also pass. Perfect. Again, let's run all of our tests. Let's see if we break something. No, everything looks good and we have already 54 passing tests. Okay. I think there's only one thing left now. Let's get back to the view file. So here we are making now this check. And every time we're doing some checks similar to this,
Refactoring with isCurrentVideo8:05
54 passing tests. Okay. I think there's only one thing left now. Let's get back to the view file. So here we are making now this check. And every time we're doing some checks similar to this, I think about how we can improve this because yeah, this is not so easy to read. We have a videoId equals to another videoId. And I think it's always good to think about if there's a name for what we are currently doing. And what we're checking here is we want to make sure that this is the current video. And of course, there are now different ways how we can check this and where to check this. But currently I think this belongs to the player because this is where we want to test this. So inside our videoPlayer, we can now create a new function. Let's call this isCurrentVideo. And we're going to provide here video, which we want to check. videoToCheck. We're going to return a Boolean if it's true or if it's false. And here now we can do the same
is currentVideo. And we're going to provide here video, which we want to check. video to check. We're going to return a boolean if it's true or if it's false. And here now we can do the same like before. So we have the currentVideo, which is this video, getting the ID and want to check if it's equal to the videoToCheck ID. And now this means inside our player, we can get rid of this. And let's call this method now isCurrentVideo. And we're providing the courseVideo. And we also need to close this here. All right, let's run the test again. It seems to be working. I think this is already way better to read and explains really well what we're doing here. Let's run all of our tests. I don't think that we broke anything. No, we didn't. Okay, perfect. Now this is also a little bit cleaner. And I think we have cleaned up the code from the last video quite a bit. But it's
I don't think that we broke anything. No, we didn't. Okay, perfect. Now this is also a little bit cleaner. And I think we have cleaned up the code from the last video quite a bit. But it's always fun to do this directly after you have created the code, you've implemented the code, because yeah, as I mentioned, this is when you still have a fresh understanding of what you just did. And this is the perfect time for refactoring. And as always, our tests will tell us if we break something.
