Okay, so we're gonna just run that application in the background at all times. Okay, so it's a TodoMVC because that's the hardest application, almost difficult application I know how to code. If you have view, you can see the view interaction. It doesn't really matter how the application is implemented. We can run the CSS pretty much against any implementation because Cypress doesn't care about the permutation details, right? It does the browser, it does the UI, right? But user doesn't care how it's implemented. So why should Cypress?
Okay, let's open DevTools. So the one thing we wanna know right away is what happens when we'll work with the implementation, like this application, right? So the thing that I usually try to observe are like what are the network calls that happen when the application loads, right? So I can reload and I can see what we get in document, we get in a bunch of you know, scripts, right? And at the end, our application is making AJAX call, so we can inspect it. So our application is doing a GET to todos, right? And gets an empty list, cuz there are no todos. So inside of a page, we kinda have like standard mark markup, right? We have classes for the main section. We have a header, that's where we probably will have input box, and when we just play all to those in unordered list. And so for every todos, we'll just show it on the screen. So that's our markup. You can take a look at todo.mvc.app.js, it has a view store, but it's a implementation details. I don't really care. But I have a question for you, right? My audience. So what happens when you add a new todo item? So you can do it yourself. Let's type, you know, first to do. Okay, so when we press Enter, you can see that there is another call that application is making, and it's a POST, right? So it sends something to the todos endpoint, right? The server responds with 201, which means a new item was created. And what does the app send? Well, it sends the todo. And notice that the app sends the title, right? Which is first to do completed false. So by default, every item is incomplete and the frontend also sends the ID. So the app is creating the ID for the app, for to-do item, and sends it, right? So it's not even server-side, it's just client-side. And if we send second todo, right, I can see another call, okay, another ID, another item. And what happens when we reload? Okay, we can see that the items came back. We can see that this original call to get todos, right, fetches the items. So application, when it starts, fetches the items. Okay, so this is how it works. So it gets to the server by using Ajax calls. Now here's another question but you should look locally. You wanna figure out where the items were stored. So for this, I will switch to my code editor. Okay, so you can use any code editor, right? But I love VS Code nowadays. So it's so simple. Kareem, no, the presentation is not private. So if you go to the code, all right, you can follow along if you get lost or if you wanna spend more time, you can take this link and just click on any of the links. So right now I'm at the intro. Okay, so let's find where the application saves the data. All right, so it sends it, stores it, and then when we reload, we can see the data again. So it has to store somewhere. Okay, if you have troubles running application, make sure you have the right version of Node, at least 12, all right, and that you can execute npm start. One thing, it might be because this is using, where's our start, if you haven't troubles, maybe go directly into todo.nvc subfolder and do npm start there. Make sure you do npm install first. So if in my text editor, if I look around, right, and I go to todo.nvc, I can see this data JSON file. Okay, and yes, Martin, you're right. I'm not ignoring it because usually it's started with a simple, empty file. Okay, so this is where my server is storing the data. Let's verify it. Let's see, is it data JSON? Okay, so yeah, that's where it's at. Yeah, yeah, Lindsey, try installing dependencies again and trying to start on the one. All right, Nikolai, if you have a Grafana app, that's not me, that probably is some other app that you're running locally. Okay, so at startup, right, when application is starting, it's getting those items again, right, so we always return, okay? Okay, this is kind of a structure application and I'm only using it, you know, to kind of explain, but this is a modern application, right? It has a UI layer, this is all the markup, the input, the list of items, they're all there. Under the hood, the app is using Datastore and the Datastore is making rest API calls, so in this presentation, I will only talk about, kind of testing rest calls. They're a little bit simpler to test than GraphQL, you know, GraphQL is more advanced and just look at our documentation if you need to intercept and spy on GraphQL calls or other types of calls. Okay, I have a more kind of detail explanation of app and how you can test it, but for now, let's start with Cypress. So I finished the introduction and let me start with the next one.
Okay, so the first thing I wanna show is, you know, what happens when you just start with Cypress, right? I had the question actually, but it's kinda, you know, in the Zoom chat or in Discord, you know, how long have you used Cypress? How long have you used Cypress for, right? So, I use Cypress for longer than four years. I'm wondering if majority of people six months, three years, not yet one day. Excellent, so we have a range from just starting to veterans. Perfect, perfect, so everyone is welcome.
Okay, so this section is for people who just started Cypress, right, or wanna try. So, we'll write first test, we'll set up, and I'll explain documentation. So, for this test, we'll create a new folder, all right? So, you did install in, you know, to MVC in testing workshop, right? But here's what happens when you start from scratch. So, let me just show how it's happened. So, I'll do, I'll go to my temp folder, and I'll make a directory like first. And I'll make a directory like first-use-site. All right, and I'll switch. So, here's what happens if you just create a new project. Right, so I'm using NPM in here to quickly create package JSON. When I install Cypress and I save it as dev-dependency, it's not production-dependency, right? It's not something necessary for your app to run, right? No, but it's something that you want to install if you're developing, so that's why it's a dev-dependency. So, I'm installing Cypress, right? Using NPM install Cypress. Come on. Okay. So, because I already installed that version of Cypress, right, it found it, so I never have to re-download that big file. Okay, so what do we have here? Right now, just pack a JSON, right, and node modules. Now we wanna open Cypress and there are different ways. The best way, I would say, the most modern and portable way after doing PM install Cypress is to do this, NPX Cypress open, I suggest you do that with me. All right, NPX Cypress open. So, this is a folder where we just installed Cypress, we run it for the very first time. Okay. Notice that it shows that to help get you started, it created a bunch of files. Okay. So, here's what we see. Oh, by the way, sometimes I don't do NPX Cypress open. So, instead I just create scripts in my package file and then I can open with a command. And then I can just create a command. But first time you start a Cypress in a folder, right? It creates a bunch of files. So, the most kind of useful is cypress.json. Okay. Then you can follow the contents by looking at, for example, a markdown, and then you'll have all the files. Look all the commands and you can go back and forth.
Comments