Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
45 changes: 25 additions & 20 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,14 @@

> ### Angular codebase containing real world examples (CRUD, auth, advanced patterns, etc) that adheres to the [RealWorld](https://github.com/gothinkster/realworld-example-apps) spec and API.


<a href="https://stackblitz.com/edit/angular-realworld" target="_blank"><img width="187" src="https://github.com/gothinkster/realworld/blob/master/media/edit_on_blitz.png?raw=true" /></a>&nbsp;&nbsp;<a href="https://thinkster.io/tutorials/building-real-world-angular-2-apps" target="_blank"><img width="384" src="https://raw.githubusercontent.com/gothinkster/realworld/master/media/learn-btn-hr.png" /></a>

### [Demo](https://angular.realworld.io)&nbsp;&nbsp;&nbsp;&nbsp;[RealWorld](https://github.com/gothinkster/realworld)



This codebase was created to demonstrate a fully fledged application built with Angular that interacts with an actual backend server including CRUD operations, authentication, routing, pagination, and more. We've gone to great lengths to adhere to the [Angular Styleguide](https://angular.io/styleguide) & best practices.

Additionally, there is an Angular 1.5 version of this codebase that you can [fork](https://github.com/gothinkster/angularjs-realworld-example-app) and/or [learn how to recreate](https://thinkster.io/angularjs-es6-tutorial).


# How it works

We're currently working on some docs for the codebase (explaining where functionality is located, how it works, etc) but the codebase should be straightforward to follow as is. We've also released a [step-by-step tutorial w/ screencasts](https://thinkster.io/tutorials/building-real-world-angular-2-apps) that teaches you how to recreate the codebase from scratch.
Expand All @@ -29,16 +25,15 @@ The source code for the backend server (available for Node, Rails and Django) ca

If you want to change the API URL to a local server, simply edit `src/environments/environment.ts` and change `api_url` to the local server's URL (i.e. `localhost:3000/api`)


# Getting started

Make sure you have the [Angular CLI](https://github.com/angular/angular-cli#installation) installed globally. We use [Yarn](https://yarnpkg.com) to manage the dependencies, so we strongly recommend you to use it. you can install it from [Here](https://yarnpkg.com/en/docs/install), then run `yarn install` to resolve all dependencies (might take a minute).

Run `ng serve` for a dev server. Navigate to `http://localhost:4200/`. The app will automatically reload if you change any of the source files.

### Building the project
Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `-prod` flag for a production build.

Run `ng build` to build the project. The build artifacts will be stored in the `dist/` directory. Use the `-prod` flag for a production build.

## Functionality overview

Expand All @@ -47,34 +42,44 @@ The example application is a social blogging site (i.e. a Medium.com clone) call
**General functionality:**

- Authenticate users via JWT (login/signup pages + logout button on settings page)
- CRU* users (sign up & settings page - no deleting required)
- CRU\* users (sign up & settings page - no deleting required)
- CRUD Articles
- CR*D Comments on articles (no updating required)
- CR\*D Comments on articles (no updating required)
- GET and display paginated lists of articles
- Favorite articles
- Follow other users

**The general page breakdown looks like this:**

- Home page (URL: /#/ )
- List of tags
- List of articles pulled from either Feed, Global, or by Tag
- Pagination for list of articles
- List of tags
- List of articles pulled from either Feed, Global, or by Tag
- Pagination for list of articles
- Sign in/Sign up pages (URL: /#/login, /#/register )
- Uses JWT (store the token in localStorage)
- Authentication can be easily switched to session/cookie based
- Uses JWT (store the token in localStorage)
- Authentication can be easily switched to session/cookie based
- Settings page (URL: /#/settings )
- Editor page to create/edit articles (URL: /#/editor, /#/editor/article-slug-here )
- Article page (URL: /#/article/article-slug-here )
- Delete article button (only shown to article's author)
- Render markdown from server client side
- Comments section at bottom of page
- Delete comment button (only shown to comment's author)
- Delete article button (only shown to article's author)
- Render markdown from server client side
- Comments section at bottom of page
- Delete comment button (only shown to comment's author)
- Profile page (URL: /#/profile/:username, /#/profile/:username/favorites )
- Show basic user info
- List of articles populated from author's created articles or author's favorited articles

- Show basic user info
- List of articles populated from author's created articles or author's favorited articles

<br />

[![Brought to you by Thinkster](https://raw.githubusercontent.com/gothinkster/realworld/master/media/end.png)](https://thinkster.io)

requires node js 15.13.0
install node version manager NVM from https://github.com/coreybutler/nvm-windows/releases
re-open CMD
nvm install 15.13.0
nvm use 15.13.0
npm start
http://localhost:4200/
npm install cypress --save-dev
npm i npx
npx cypress open
10 changes: 10 additions & 0 deletions cypress.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
import { defineConfig } from "cypress";

export default defineConfig({
e2e: {
setupNodeEvents(on, config) {
// implement node event listeners here
},
specPattern: "cypress/e2e/*.js",
},
});
17 changes: 17 additions & 0 deletions cypress/e2e/01_signup-login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/// <reference types="cypress" />

describe("Signup & Login", () => {
let randomString = Math.random().toString(36).substring(2);

it("Test Valid Signup", () => {
cy.visit("http://localhost:4200/");

cy.get(".nav").contains("Sign up").click();
cy.get("[placeholder='Username']").type("Auto" + randomString);
cy.get("[placeholder='Email']").type(
"Auto_email" + randomString + "@gmail.com"
);
cy.get("[placeholder='Password']").type("Password1");
cy.get("button").contains("Sign up").click();
});
});
28 changes: 28 additions & 0 deletions cypress/e2e/02_signup.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/// <reference types="cypress" />

describe("Signup & Login", () => {
let randomString = Math.random().toString(36).substring(2);
let username = "Auto" + randomString;
let email = "Auto_email" + randomString + "@gmail.com";

it("Test Valid Signup", () => {
cy.intercept("POST", "**/*.realworld.io/api/users").as("newUser");

cy.visit("http://localhost:4200/");

cy.get(".nav").contains("Sign up").click();
cy.get("[placeholder='Username']").type(username);
cy.get("[placeholder='Email']").type(email);
cy.get("[placeholder='Password']").type("Password1");
cy.get("button").contains("Sign up").click();

cy.wait("@newUser").then(({ request, response }) => {
cy.log("Request: " + JSON.stringify(request));
cy.log("Response: " + JSON.stringify(response));

expect(response.statusCode).to.eq(200);
expect(request.body.user.username).to.eq(username);
expect(request.body.user.email).to.eq(email);
});
});
});
38 changes: 38 additions & 0 deletions cypress/e2e/03_login.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/// <reference types="cypress" />

describe("Signup & Login", () => {
let randomString = Math.random().toString(36).substring(2);
let username = "Auto" + randomString;
let email = "Auto_email" + randomString + "@gmail.com";
let password = "Password1";

it("Test Valid Signup", () => {
cy.intercept("POST", "**/*.realworld.io/api/users").as("newUser");

cy.visit("http://localhost:4200/");

cy.get(".nav").contains("Sign up").click();
cy.get("[placeholder='Username']").type(username);
cy.get("[placeholder='Email']").type(email);
cy.get("[placeholder='Password']").type(password);
cy.get("button").contains("Sign up").click();

cy.wait("@newUser").should(({request, response}) => {
cy.log("Request: " + JSON.stringify(request));
cy.log("Response: " + JSON.stringify(response));

expect(response.statusCode).to.eq(200);
expect(request.body.user.username).to.eq(username);
expect(request.body.user.email).to.eq(email);
})
})

it("Test Valid Login", () => {
cy.visit("http://localhost:4200/");
cy.get(".nav").contains("Sign in").click();
cy.get("[placeholder='Email']").type(email);
cy.get("[placeholder='Password']").type(password);
cy.get("button").contains("Sign in").click();
cy.get(':nth-child(4) > .nav-link').contains(username);
})
})
43 changes: 43 additions & 0 deletions cypress/e2e/04_signup-login_mock.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/// <reference types="cypress" />

describe("Signup & Login", () => {
let randomString = Math.random().toString(36).substring(2);
let username = "Auto" + randomString;
let email = "Auto_email" + randomString + "@gmail.com";
let password = "Password1";

it("Test Valid Signup", () => {
cy.intercept("POST", "**/*.realworld.io/api/users").as("newUser");

cy.visit("http://localhost:4200/");

cy.get(".nav").contains("Sign up").click();
cy.get("[placeholder='Username']").type(username);
cy.get("[placeholder='Email']").type(email);
cy.get("[placeholder='Password']").type(password);
cy.get("button").contains("Sign up").click();

cy.wait("@newUser").should(({ request, response }) => {
cy.log("Request: " + JSON.stringify(request));
cy.log("Response: " + JSON.stringify(response));

expect(response.statusCode).to.eq(200);
expect(request.body.user.username).to.eq(username);
expect(request.body.user.email).to.eq(email);
});
});

it.only("Test Valid Login & Mock Popular Tags", () => {
cy.intercept("GET", "**/tags", { fixture: "popularTags.json" });
cy.visit("http://localhost:4200/");
cy.get(".nav").contains("Sign in").click();
cy.get("[placeholder='Email']").type(email);
cy.get("[placeholder='Password']").type(password);
cy.get("button").contains("Sign in").click();
cy.get(":nth-child(4) > .nav-link").contains(username);

cy.get(".tag-list")
.should("contain", "JavaScript")
.and("contain", "cypress");
});
});
56 changes: 56 additions & 0 deletions cypress/e2e/05_signup-login_FINAL.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/// <reference types="cypress" />

describe("Signup & Login", () => {
let randomString = Math.random().toString(36).substring(2);
let username = "Auto" + randomString;
let email = "Auto_email" + randomString + "@gmail.com";
let password = "Password1";

it.skip("Test Valid Signup", () => {
cy.intercept("POST", "**/*.realworld.io/api/users").as("newUser");

cy.visit("http://localhost:4200/");

cy.get(".nav").contains("Sign up").click();
cy.get("[placeholder='Username']").type(username);
cy.get("[placeholder='Email']").type(email);
cy.get("[placeholder='Password']").type(password);
cy.get("button").contains("Sign up").click();

cy.wait("@newUser").should(({ request, response }) => {
cy.log("Request: " + JSON.stringify(request));
cy.log("Response: " + JSON.stringify(response));

expect(response.statusCode).to.eq(200);
expect(request.body.user.username).to.eq(username);
expect(request.body.user.email).to.eq(email);
});
});

it("Test Valid Login & Mock Popular Tags", () => {
cy.intercept("GET", "**/tags", { fixture: "popularTags.json" });
cy.visit("http://localhost:4200/");
cy.get(".nav").contains("Sign in").click();
cy.get("[placeholder='Email']").type(email);
cy.get("[placeholder='Password']").type(password);
cy.get("button").contains("Sign in").click();
cy.get(":nth-child(4) > .nav-link").contains(username);

cy.get(".tag-list")
.should("contain", "JavaScript")
.and("contain", "cypress");
});

it("Mock global feed data", () => {
cy.intercept("GET", "**/api/articles*", {
fixture: "testArticles.json",
}).as("articles");
cy.visit("http://localhost:4200/");
cy.get(".nav").contains("Sign in").click();
cy.get("[placeholder='Email']").type(email);
cy.get("[placeholder='Password']").type(password);
cy.get("button").contains("Sign in").click();
cy.get(":nth-child(4) > .nav-link").contains(username);
cy.wait("@articles");
});
});
5 changes: 5 additions & 0 deletions cypress/e2e/spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
describe('template spec', () => {
it('passes', () => {
cy.visit('https://example.cypress.io')
})
})
5 changes: 5 additions & 0 deletions cypress/fixtures/example.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
{
"name": "Using fixtures to represent data",
"email": "[email protected]",
"body": "Fixtures are a great way to mock data for responses to routes"
}
8 changes: 8 additions & 0 deletions cypress/fixtures/popularTags.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"tags": [
"JavaScript",
"automation-testing",
"cypress",
"nodejs"
]
}
67 changes: 67 additions & 0 deletions cypress/fixtures/testArticles.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
{
"articles":[
{
"slug":"Welcome-to-RealWorld-project-1",
"title":"Welcome to RealWorld project",
"description":"Exemplary fullstack Medium.com clone powered by React, Angular, Node, Django, and many more",
"body":"See how the exact same Medium.com clone (called Conduit) is built using different frontends and backends. Yes, you can mix and match them, because they all adhere to the same API spec",
"createdAt":"2021-10-08T12:33:19.869Z",
"updatedAt":"2021-10-08T12:33:19.869Z",
"tagList":[

],
"author":{
"username":"Gerome",
"bio":null,
"image":"https://realworld-temp-api.herokuapp.com/images/demo-avatar.png"
},
"comments":[
{
"id":91,
"createdAt":"2021-10-09T03:12:48.578Z",
"updatedAt":"2021-10-09T03:12:48.578Z",
"body":"test",
"author":{
"username":"Joe Blogs",
"bio":"Joe Blogs BIO",
"image":"https://realworld-temp-api.herokuapp.com/images/smiley-cyrus.jpeg"
}
}
],
"favoritesCount":25,
"favorited":false
},
{
"slug":"gianni-b-slug",
"title":"Welcome to the world of Cypress",
"description":"Cypress is the best",
"body":"Learn Cypress now!!!!",
"createdAt":"2021-10-08T12:33:19.869Z",
"updatedAt":"2021-10-08T12:33:19.869Z",
"tagList":[

],
"author":{
"username":"Gerome",
"bio":null,
"image":"https://realworld-temp-api.herokuapp.com/images/demo-avatar.png"
},
"comments":[
{
"id":95,
"createdAt":"2021-10-09T03:12:48.578Z",
"updatedAt":"2021-10-09T03:12:48.578Z",
"body":"gianni b test123",
"author":{
"username":"Gianni b",
"bio":"Gian bio 1223",
"image":"https://realworld-temp-api.herokuapp.com/images/smiley-cyrus.jpeg"
}
}
],
"favoritesCount":50,
"favorited":false
}
],
"articlesCount":2
}
Loading