Skip to content

Decorator #6

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
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
12 changes: 12 additions & 0 deletions actions/LoginActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import { write, click, into } from "taiko";
import LoginElements from "../elements/loginElements";

class LoginActions {
async login(userName, password) {
await write(userName, into(LoginElements.userName));
await write(password, into(LoginElements.password));
await click(LoginElements.submit);
}
}

export default new LoginActions();
14 changes: 14 additions & 0 deletions actions/SideNavActions.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import FlowFactory from "../factory/FlowFactory";

let runner;

class SideNavActions {
constructor() {
runner = FlowFactory.getInstance();
}
async addNewPost() {
await runner.writePosts();
}
}

export default new SideNavActions();
12 changes: 12 additions & 0 deletions actor/Actor.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import LoginActions from "../actions/LoginActions";
import SideNavActions from "../actions/SideNavActions";

export default class Actor {
async login() {
await LoginActions.login(this.userName, this.password);
}

async writePost() {
await SideNavActions.writePost();
}
}
15 changes: 15 additions & 0 deletions actor/Admin.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import Actor from "../actor/Actor";

export default class Admin extends Actor {
constructor(credentials) {
super();
this.userName = credentials.user;
this.password = credentials.password;
}

async deletePost() {
return true;
}

async createAUser() {}
}
11 changes: 11 additions & 0 deletions actor/Author.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
import Actor from "../actor/Actor";

export default class Author extends Actor {
constructor(credentials) {
super();
this.userName = credentials.user;
this.password = credentials.password;
}

async publishAPost() {}
}
32 changes: 32 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
version: "3.3"

services:
db:
image: mysql:5.7
volumes:
- db_data:/var/lib/mysql
restart: always
ports:
- "3306:3306"
expose:
- "3306"
environment:
MYSQL_ROOT_PASSWORD: somewordpress
MYSQL_DATABASE: wordpress
MYSQL_USER: wordpress
MYSQL_PASSWORD: wordpress

wordpress:
depends_on:
- db
image: wordpress:latest
ports:
- "8000:80"
restart: always
environment:
WORDPRESS_DB_HOST: db:3306
WORDPRESS_DB_USER: wordpress
WORDPRESS_DB_PASSWORD: wordpress
WORDPRESS_DB_NAME: wordpress
volumes:
db_data: {}
15 changes: 15 additions & 0 deletions elements/loginElements.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
import { $ } from "taiko";

export default class LoginElements {
static get userName() {
return $("#user_login");
}

static get password() {
return $("#user_pass");
}

static get submit() {
return $("#wp-submit");
}
}
8 changes: 8 additions & 0 deletions factory/DesktopFlow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
import { click } from "taiko";

export default class DesktopFlow {
async writePosts() {
await click("Posts");
await click("Add New");
}
}
12 changes: 12 additions & 0 deletions factory/FlowFactory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import MobileFlow from "../factory/MobileFlow";
import DesktopFlow from "../factory/DesktopFlow";

export default class FlowFactory {
static getInstance() {
if (process.env.TAIKO_EMULATE_DEVICE) {
return new MobileFlow();
} else {
return new DesktopFlow();
}
}
}
5 changes: 5 additions & 0 deletions factory/MobileFlow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default class MobileFlow {
async writePost() {
console.log("Writing Post from Mobile Flow!!");
}
}
9 changes: 9 additions & 0 deletions interrogations/SideNavInterrogations.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import { text } from "taiko";

class SideNavInterrogations {
async checkIfSettingsIsPresent() {
return await text("Settings").exists();
}
}

export default new SideNavInterrogations();
10 changes: 10 additions & 0 deletions post/writeAndPublishPost.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
export default class WriteAndPublishPost {
constructor(writePost) {
this.post = writePost;
}

async writePost() {
await this.post.addPost();
await this.post.publishPost();
}
}
25 changes: 25 additions & 0 deletions post/writePost.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
import SideNavActions from "../actions/SideNavActions";
import { write, into, focus, textBox, click } from "taiko";

export default class WritePost {
async addPost() {
await SideNavActions.addNewPost();
await this.addTitle();
await this.addDescription();
}

async addTitle() {
await focus(textBox("Add title"));
await write("Post Title", into("#post-title-0"));
}

async addDescription() {
//TODO: Add Description
console.log("Description added");
}

async publishPost() {
await click("Publish");
await click("Publish");
}
}
18 changes: 18 additions & 0 deletions post/writePostWithCategory.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
import { click } from "taiko";

export default class WritePostWithCategory {
constructor(writePost) {
this.post = writePost;
}

async writePost() {
await this.post.addPost();
await this.addCategory();
await this.post.publishPost();
}

async addCategory() {
await click("Categories");
await click("JS");
}
}
19 changes: 19 additions & 0 deletions post/writePostWithTag.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import { click, focus, write, textBox } from "taiko";

export default class WritePostWithTag {
constructor(writePost) {
this.post = writePost;
}

async writePost() {
await this.post.addPost();
await this.addTags();
await this.post.publishPost();
}

async addTags() {
await click("Tags");
await focus(textBox("Add New Tag"));
await write("Blog, ");
}
}
53 changes: 53 additions & 0 deletions test/addPost.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
import { openBrowser, goto, closeBrowser, text } from "taiko";
import { expect } from "chai";
import Admin from "../actor/Admin";
import Author from "../actor/Author";
import SideNavInterrogations from "../interrogations/SideNavInterrogations";
import WritePost from "../post/writePost";
import WriteAndPublishPost from "../post/writeAndPublishPost";
import WritePostWithTag from "../post/writePostWithTag";
import WritePostWithCategory from "../post/writePostWithCategory";

describe("WordPress Login", async () => {
beforeEach("Open Browser", async () => {
await openBrowser();
await goto("http://127.0.0.1:8000/wp-admin/");
});

afterEach("Close Browser", async () => {
await closeBrowser();
});

it.only("Admin should be able to add a new post", async () => {
let admin = new Admin({
user: "Karley Crist",
password: "gkbjp93kFUFthK7",
});
await admin.login();

let post = new WriteAndPublishPost(new WritePost());
await post.writePost();
});

it("Admin should be able to add a new post with tags", async () => {
let admin = new Admin({
user: "Karley Crist",
password: "gkbjp93kFUFthK7",
});
await admin.login();

let post = new WritePostWithTag(new WritePost());
await post.writePost();
});

it("Admin should be able to add a new post with category", async () => {
let admin = new Admin({
user: "Karley Crist",
password: "gkbjp93kFUFthK7",
});
await admin.login();

let post = new WritePostWithCategory(new WritePost());
await post.writePost();
});
});
43 changes: 24 additions & 19 deletions test/login.spec.js
Original file line number Diff line number Diff line change
@@ -1,29 +1,34 @@
import {
openBrowser,
goto,
closeBrowser,
write,
click,
into,
$,
text,
} from "taiko";
import { openBrowser, goto, closeBrowser, text } from "taiko";
import { expect } from "chai";

import Admin from "../actor/Admin";
import Author from "../actor/Author";
import SideNavInterrogations from "../interrogations/SideNavInterrogations";
describe("WordPress Login", async () => {
before("Open Browser", async () => {
beforeEach("Open Browser", async () => {
await openBrowser();
await goto("http://127.0.0.1:8000/wp-admin/");
});

after("Close Browser", async () => {
afterEach("Close Browser", async () => {
await closeBrowser();
});
it("User with Valid Login should be able to see settings option", async () => {
await write("Karley Crist", into($("#user_login")));
await write("gkbjp93kFUFthK7", into($("#user_pass")));
await click($("#wp-submit"));
const elementPresent = await text("Settings").exists();
expect(elementPresent).to.be.true;

it("User with Valid Admin Login should be able to see settings option", async () => {
let admin = new Admin({
user: "Karley Crist",
password: "gkbjp93kFUFthK7",
});
await admin.login();
await admin.deletePost();
expect(await SideNavInterrogations.checkIfSettingsIsPresent()).to.be.true;
});

it("User with Valid Non Admin Login should not be able to see settings option", async () => {
let author = new Author({
user: "taiko",
password: "taiko",
});
await author.login();
expect(await SideNavInterrogations.checkIfSettingsIsPresent()).to.be.false;
});
});