Have you heard about Atomic Design? How about Extreme Programming and Test Driven Development? For sure you have heard about React - a few things, I bet. In this talk you will get some insight on leveraging the power of Atomic Design to build the right product (using React, duh!) and capitalize on Extreme Programming and Test Driven Development to build it right ( exploring the React Testing Library).
Building the Right Product and Building It Right: Extreme Programming and Atomic Design
Welcome to this talk, where I'll tell you a little bit about extreme programming and atomic design. First things first, hello, my name is Rita. I'm a geek at heart and I really like to play sports. I'm also a mom, which means that whenever I'm not with my family, that means that I'm probably working. I work at the Volkswagen Software Development Center here in Lisbon, and these are my amazing colleagues and teammates. So, about this talk, I will try to tell you a little bit on how to build the right product. And from where I stand, I think a good product should be user-driven, and it should be a digital product, bear in mind. And it should be done using consistent and quality UIs, because you want your users to be engaged with it. And how exactly can you build it right? Well, you should have tests for it. Tests are an important part of software development. And in fact, they're as important as how they're done. And to me, the best way of doing tests is to do test-driven development. So, this means to write your tests up front before you start writing any sort of production code. On the other hand, and since this is React Summit, of course you want to go from design to React. So, you want to have an easy way to translate what you have from your designs to React. How can we achieve this? This is what I'm setting myself up to tell you and talk to you about. So, the Software Development Center in Lisbon. It was created in 2018. It was the first development center that Volkswagen opened outside of Germany, and they chose to do so in Lisbon, I wouldn't think. And thank you for that. So, I joined. I already knew and I already did test-driven development and used to work in an agile framework, let's put it this way. But they pitched in something new, something different, which was XP and Balanced Teams. So, XP stands for Extreme Programming, and it was created back in 96 by Kent Beck. And it is an agile way of developing software. It is mainly targeted for developers, but the rest of the development team, it also can take a lot of advantage from what XP stands for and what it encompasses at its core. And what does it encompass in its core? So, it's driven by five core values. The value of communication. Keep the chat and the conversation going on within your team, because with this, you are able to share information, you are able to transfer knowledge from one person to the other, regardless of the role they have in your team. Simplicity. When you're building your product, build it the leanest way as you can. Why? So that you can get feedback from it really, really often. You don't want to be developing something that the users won't need or that the users don't want or that it's poorly developed and unusable. So, get feedback as fast as you can. Have the guts or the courage to toss things away if they are not what the user needs or wants, regardless of how much you've invested in it. And most important, have respect amongst your team. Each and every decision you make for your product, it is a team decision. So, it is not something that you do by yourself. Everyone's voice is heard. Everyone's voice is respected. Opinions are worth it and you can voice them out loud. However, these values, they're a bit barren if you don't have any sort of practices that you can use them upon. So, the two values, sorry, the two practices that I would like to stand out from XP are paired programming and test-driven development. For paired programming, it is important because you're able, again, to share the communication, to share the knowledge that you have amongst yourselves. So, regardless of your role in the team, you're going to pair. So, you're going to be working with someone that will share the information that you're building upon. Test-driven development, so that you do just what is needed to get your feature up and running. Where do we do this? Integrated and balanced teams. What are they then? They're composed of designers, product managers, and developers, us. What do designers bring to the table? Well, they are the bridge between the team and the users. They understand what are the pain points that the users have and they come up with solutions to make their lives a lot easier. What do product managers do? Well, they take care of the money and they break down the stories, sorry, they break down the features that we want to build for our product into stories that we, the developers, can do. And what do we do? Well, apart from coding, we're also the ones that are responsible for seeing and evaluating if something is feasible to be done. We are the gatekeepers of the technology, but we are also the ones responsible for evaluating the feasibility of the product. What happens when all of us work together? Magic happens. That's what. In the SDC, me, so I joined in 2017, as I told you, sorry, 2018, as I told you, and now it's 2021. What have I done in the middle? Apart from having the kit, I have worked in four different products. All of them had React as its front-end framework. Why did we choose React? Well, because in quoting the documentation from React, React is supposed to make our lives a lot easier. It is supposed to make it painless to create interactive UIs. And you should be able to build encapsulated components so that you can make these UIs in a very easy and good way. However, we used to do feature-driven development, a loose adaptation of it, at least, which means that for every feature that we wanted to develop within our code or within our product, we would have a folder for it, and then we would start nesting out things that are specific to that feature in it, and if we had components that would be reused and shared throughout a couple of features, we would extract them to the components feature. But then, as the products began to escalate, the features became a little bit too crowded, let's put it this way. So we had to find a different way of organizing our front-end code. Enter Atomic Design. What is it? It is a design methodology, and it goes into creating and maintaining anything from the design system. It was created by Brad Frost in 2013, and it's composed of five different levels of elements. Please bear in mind that this is a design framework, so we're going to do an adaptation from a design framework to React. So how is it structured? There are atoms, which are the most basic elements of all. If you combine atoms together, you will get molecules. Cool. If you join molecules and other atoms, or eventually molecules and organisms as well, you'll get organisms. And when you set out, when you build the layout and you decide, okay, this goes here, that goes there, etc., you have a template, and when you pick the organisms and you put them on your templates, you get pages. So it's a linear flow to build your UI, and it's quite easy. So having this in mind, I'm going to tell you the experience that we're currently doing in the SDC. We are trying to solve a problem, or what we perceive as a problem, from the dealers, from the dealers that sell cars. So imagine that you're a dealer. You sell a car. You sell a car to a customer today. You sell another car tomorrow to a different customer, and tomorrow, and tomorrow, and tomorrow. So you sell a lot of cars because you're good at it. In average, dealers sell around 20 cars per month, and each of these cars, so each of these orders, takes around three months to be fulfilled. So within this time span, the dealer needs to keep track of what's the status of the order. Is the car here? Is it about to get here? Is it delayed? Well, if you don't communicate with your customer, it is really, really likely that the customer will pick up the phone and call and say, hey, where's my car? And that's a problem because then the dealer has to be able to find the information about the order of that customer really, really fast because you don't want them holding back. So how am I able to tell you all of this? Because we did a lot of user interviews with dealers so that we would understand the pain points and the needs that they have. With that, our designers formulated three assumptions. The first one being that the dealers want to know the status about their orders. The second, that they want to be updated about those status. And third, that they want to be able to share that information with the customers. Given that, we think we can come up with something. So us, the developers, we checked if it would be possible to get information from the orders. It is. We can integrate with the systems that are really, really old, but we are able to extract information and provide it for the dealers. Can we integrate it in a product that is already used by the dealers so that this isn't just another tool that they have to use? Yes, we can also achieve that. So we're on the good side. In that case, it's up for the designers to create something that we call the user journey, the dealer's journey in this case, because the user is a dealer. And what is it? So you open your browser, you have a dashboard with the information about all the orders that you have. At a glance from the top, you are able to see the information about the orders in a set of tabs. Below the tabs, you have information about all of the orders that you have available. Imagine that Lisa Marie calls, hey, I want to know what's wrong with my car. The dealer clicks on the button that says view details and they are taken to a different page, the details page. In the details page, you get to see the details for Lisa Marie. So all of the information about the order or the information that was deemed relevant about the order and you check the status of the order. How is it? Is the car delayed? Is it in production? Is it arriving to the country, etc. Given this and having a little bit of a throwback to the beginning of this talk, the fact that it's user driven and that we want to do test driven development for our product, this means and the fact that you want to have an easy way to go from design to code with consistent UIs. Well, for the first one, let's use React Testing Library. It's really, really good. It's solid and it does what we want. For the design part, well, let's use the Atomic framework that I just presented you. Then in reality, we are doing nothing more than using XP with the Atomic design. Let's see how it goes. So let's start and let's start by what? By writing a failing test because that's how the test driven development flow works. But which test are we going to write? Good question. Let's start small. What can be smaller than atoms? Nothing in this case. So let's take the dashboard. From the dashboard, let's try to identify a few atoms from the designs. Okay. We already know they are unbreakable components and they will provide us the base tiles from the UI, which means that we can have the view details button as an atom, a formatted date as an atom, text as atoms, icons to say, to name a few. Then we can implement a test for it. You render the view details button. You expect the text to be in the document and you expect that there is a link to take us somewhere else. In this case, React Summit in Amsterdam. Why not? Then, then, then you run the test. When you run the test, of course it will fail because your implementation has nothing. What do you do? You fulfill the implementation to or you do the implementation to be able to see a text that says view details. There you go. There's a paragraph with view details. That part of the test has passed, but you still get an error for the link. Yeah, we're a little bit naughty here. We cheated a little bit on the test because, well, not cheating. We were playing a little bit. So with the pair programming, usually one person does the test, another person does the code. It's called ping pong. And sometimes you want to be able to dare the person writing the test to be more specific and to be more as objective as possible so that it leaves you no room for free interpretations with your test. So with that said, fine, I'll give you a link. And when you have a link, the test passes and we're good to go. A small detail is that I'm using the previous test that I showed you. I was using a mocked component for the React router DOM. So instead of using the actual link, I was mocking it. Why? So that I don't have to wrap the component that I'm rendering with the memory router. There is no right or wrong. There is no good or bad in the middle of this. You need to understand what makes sense for you and makes sense for your team and stick with it. So you do you. No right or wrong. You decide what is the best. So the team talks amongst itself, the team talks among themselves and they see what is best for them. But whatever you do, be consistent. Moving up in the atomic ladder, we have molecules. Molecules. What are the molecules? Molecules are atoms bonded together. So they did something that brings functionality. The search bar, the order progress, for example. So the order progress, it has two elements. It has the text in transit and it has the transit icon. You render the thing, you expect the text to be there, you expect the icon to be there. Excellent. Let's see how it goes. You get it there. It's really, really easy. It's really, really fast. From design, it's fast. Next in the ladder, organisms. Organisms are a flock of atoms, molecules and even other organisms. And most important of all, they bring you user value. So with the user value, what do you have? You have these two main elements. So the tab list and the orders list. But then let's build a test for it. So the orders list, it needs to have the text that says all orders and it needs to have the components for the search bar, the filters and the orders table. Sounds good. But then you're mocking it. So at this time, you need to be able to understand and decide what you want to do. To mock or not to mock. So a pro-con list. When you're mocking, it is really, really good because you get to encapsulate everything. You don't need to know the details of the elements that you're using down below the tree. And you get a clear view of what you're using. You don't get to do any cheating. So if you want to have a text, you need to have a text, not a paragraph that says text. And it's really, really easy for new team members to get on board to the new concepts. However, we drift a little bit away from the user experience. We've got a little bit of shallow rendering going on. And sometimes mocks can be tricky. Especially if you're using third party libraries. Again, it is a team's decision to choose what is best. And what I can recommend you is that you will find your balance if you follow this road. So on one hand, you'll have unit tests. On the other hand, you will have integration tests. So for the unit tests, you should mock them all. So this will allow you to make sure that you're using the right components to build your product. But then on the other hand, for the integration tests, you should render them all. Because then you will be sure that you are using them right. And this is this resembles a little bit or this flashes takes us back to a quote from Ken C Dodds, from the creator of React Testing Library. So the more your tests resemble your software, the more confidence they give you. And that's damn right. And why? Because now we can build a test for the orders, the order list organism, in which, okay, we know that on the route, we have the orders list. And we know that eventually when we have the link that will take us to the order, we will be on the details page. So when we open the page or when we render the page, we expect to have the heading for the all orders to be there. Then we expect to have the contents of the row to be displayed. For example, a car, I'm buying a car. You expect to have the button, the link button for with the view details to be clicked. And then you click on it. And when you click on it, you get redirected to a different page. So this is good. This is a valuable test. This resembles how the user is interacting with your software. For completion and to wrap it up, templates and pages. If you define the layout, you place the organisms there, you get a page. It cannot be as simple as it is. The other page that we have in our design is the details page. It looks like this. It's composed of also, it has atoms, it has molecules and it has organisms. Perfectly fine. We're not going to dwell into that. Let's go back to the dealer's journey. So we can write a test for the dealer's journey and it would look something like this. You render the dashboard. You expect to be in the dashboard. So you expect the region dashboard to be there. You expect to see the tabs, also good. And within the dashboard, you expect to see the orders. You expect to have the search bar for the search orders. You expect to have the filters. So you can achieve that with the implementation of the dashboard. Eventually, you will also would really, really like to be able to see information from the table. So to get something from the table, you can get the DRB label for a given role and then click the link button and be able to go to the rest. When you go to the rest, you know that you're no longer in the dashboard page, but you're now in the details page. Finally, you've seen all there is to see. You click on the back button. And when you click on the back button, you are taken back to the all orders page. So things are clean. Things are nice. And this completes the user journey. So with one test, one somewhat big test, you are able to do the complete user journey described in a way that is as close as possible to the way the user is going to interact with your software. So to wrap up, I really, really think it is my personal opinion that when you use XP with Atomic Design, you get a very sweet spot. And this sweet spot is that you're able to deliver high quality software with consistent and solid UIs faster than ever before, any day of the week, including Fridays. So thank you so much for attending. I'll talk to you soon. You can find me on any of those social media. Bye!