feat: init
This commit is contained in:
@@ -0,0 +1,27 @@
|
||||
# See https://help.github.com/ignore-files/ for more about ignoring files.
|
||||
|
||||
# dependencies
|
||||
/node_modules
|
||||
/dist
|
||||
coverage
|
||||
|
||||
# misc
|
||||
.DS_Store
|
||||
.env.local
|
||||
.env.development.local
|
||||
.env.test.local
|
||||
.env.production.local
|
||||
|
||||
npm-debug.log*
|
||||
yarn-debug.log*
|
||||
yarn-error.log*
|
||||
|
||||
/.bin/
|
||||
/.storybook/
|
||||
/.idea/
|
||||
/public/dist/
|
||||
/public/public/dist/
|
||||
/storybook-static/
|
||||
/build/
|
||||
/counter-clone/
|
||||
__old
|
||||
@@ -0,0 +1 @@
|
||||
module.exports = { presets: ["@babel/preset-env"] };
|
||||
@@ -0,0 +1,8 @@
|
||||
module.exports = {
|
||||
preset: "ts-jest",
|
||||
transform: {
|
||||
"^.+\\.(ts|tsx)?$": "ts-jest",
|
||||
"^.+\\.(js|jsx)$": "babel-jest",
|
||||
},
|
||||
testTimeout: 60000,
|
||||
};
|
||||
@@ -0,0 +1,24 @@
|
||||
{
|
||||
"name": "twake",
|
||||
"version": "2020.3.107",
|
||||
"repository": "https://github.com/Twake/Twake",
|
||||
"license": "AGPL-3.0",
|
||||
"scripts": {
|
||||
"test:all": "jest --detectOpenHandles --forceExit --coverage --runInBand --verbose false",
|
||||
"test:login": "tsc && node ./dist/commands/test-login.js",
|
||||
"test:signin": "tsc && node ./dist/commands/test-signin.js",
|
||||
"test:create-channel": "tsc && node ./dist/commands/test-create-channel.js"
|
||||
},
|
||||
"devDependencies": {
|
||||
"@faker-js/faker": "^6.1.2",
|
||||
"@types/jest": "^27.4.1",
|
||||
"@types/node": "^17.0.23",
|
||||
"ts-jest": "^27.1.4",
|
||||
"typescript": "^4.6.3"
|
||||
},
|
||||
"dependencies": {
|
||||
"babel-jest": "^27.5.1",
|
||||
"jest": "^27.5.1",
|
||||
"puppeteer": "^13.5.2"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,35 @@
|
||||
import puppeteer from "puppeteer";
|
||||
|
||||
import config from "../config";
|
||||
|
||||
import { createChannel } from "../steps/create-channel";
|
||||
import { login } from "../steps/login";
|
||||
import { signIn } from "../steps/signin";
|
||||
|
||||
// This is the entry point for the integration tests.
|
||||
async function init() {
|
||||
const { headless, slowMo, executablePath, args } = config;
|
||||
const browser = await puppeteer.launch({
|
||||
headless,
|
||||
slowMo,
|
||||
executablePath,
|
||||
args,
|
||||
});
|
||||
|
||||
await Promise.all([
|
||||
signIn(config.twake_url, browser, config.accounts_for_sign_in[0], {
|
||||
withConsole: config.console,
|
||||
}),
|
||||
|
||||
login(config.twake_url, browser, config.accounts_for_login[0], {
|
||||
withConsole: config.console,
|
||||
}),
|
||||
|
||||
createChannel(config.twake_url, browser, undefined, {
|
||||
withConsole: config.console,
|
||||
}),
|
||||
// Do other tests here
|
||||
]);
|
||||
}
|
||||
|
||||
init();
|
||||
@@ -0,0 +1,21 @@
|
||||
import puppeteer from "puppeteer";
|
||||
|
||||
import config from "../config";
|
||||
|
||||
import { createChannel } from "../steps/create-channel";
|
||||
|
||||
async function init() {
|
||||
const { headless, slowMo, executablePath, args } = config;
|
||||
const browser = await puppeteer.launch({
|
||||
headless,
|
||||
slowMo,
|
||||
executablePath,
|
||||
args,
|
||||
});
|
||||
|
||||
await createChannel(config.twake_url, browser, config.accounts_for_login[0], {
|
||||
withConsole: config.console,
|
||||
});
|
||||
}
|
||||
|
||||
init();
|
||||
@@ -0,0 +1,21 @@
|
||||
import puppeteer from "puppeteer";
|
||||
|
||||
import config from "../config";
|
||||
|
||||
import { login } from "../steps/login";
|
||||
|
||||
async function init() {
|
||||
const { headless, slowMo, executablePath, args } = config;
|
||||
const browser = await puppeteer.launch({
|
||||
headless,
|
||||
slowMo,
|
||||
executablePath,
|
||||
args,
|
||||
});
|
||||
|
||||
await login(config.twake_url, browser, config.accounts_for_login[0], {
|
||||
withConsole: config.console,
|
||||
});
|
||||
}
|
||||
|
||||
init();
|
||||
@@ -0,0 +1,21 @@
|
||||
import puppeteer from "puppeteer";
|
||||
|
||||
import config from "../config";
|
||||
|
||||
import { signIn } from "../steps/signin";
|
||||
|
||||
async function init() {
|
||||
const { headless, slowMo, executablePath, args } = config;
|
||||
const browser = await puppeteer.launch({
|
||||
headless,
|
||||
slowMo,
|
||||
executablePath,
|
||||
args,
|
||||
});
|
||||
|
||||
await signIn(config.twake_url, browser, config.accounts_for_sign_in[0], {
|
||||
withConsole: config.console,
|
||||
});
|
||||
}
|
||||
|
||||
init();
|
||||
@@ -0,0 +1,15 @@
|
||||
import { createSomeFakeChannels } from "./utils/create-some-fake-channels";
|
||||
import { createSomeFakeUsers } from "./utils/create-some-fake-users";
|
||||
|
||||
export default {
|
||||
twake_url: process.env.SERVER || "http://localhost:3000",
|
||||
executablePath: "/usr/bin/google-chrome", //"/Applications/Chromium.app/Contents/MacOS/Chromium"
|
||||
args: ["--no-sandbox"],
|
||||
screenshot_path: "screenshots/",
|
||||
console: false,
|
||||
headless: true,
|
||||
slowMo: 50,
|
||||
accounts_for_login: createSomeFakeUsers(5),
|
||||
accounts_for_sign_in: createSomeFakeUsers(5),
|
||||
channels_for_create: createSomeFakeChannels(5),
|
||||
};
|
||||
@@ -0,0 +1,71 @@
|
||||
import { Browser, Page } from "puppeteer";
|
||||
|
||||
import config from "../config";
|
||||
|
||||
import { signIn } from "./signin";
|
||||
|
||||
const popupSelector = "div.int-channel-edit-modal";
|
||||
const plusIconBtnSelector =
|
||||
"div.workspace_channels div.channel_category div.add";
|
||||
const createChannelMenuItemSelector = "div.menu.add-channel";
|
||||
const inputChannelNameSelector = ".int-channel-name";
|
||||
const inputChannelDescriptionSelector = ".int-channel-description";
|
||||
const createButtonSelector = ".int-channel-save-information";
|
||||
|
||||
export async function createChannel(
|
||||
url: string,
|
||||
browser: Browser,
|
||||
credentials: { email: string; password: string },
|
||||
opts: { withConsole: boolean } = { withConsole: false }
|
||||
): Promise<Page> {
|
||||
const page = await signIn(url, browser, credentials, {
|
||||
withConsole: opts.withConsole,
|
||||
});
|
||||
|
||||
await Promise.all([
|
||||
// Click on the hamburger icon (depend the screensize)
|
||||
//await page.waitForSelector(hamburgerIconBtnSelector),
|
||||
//await page.click(hamburgerIconBtnSelector),
|
||||
|
||||
// Click on the plus icon
|
||||
await page.waitForSelector(plusIconBtnSelector),
|
||||
await page.hover(plusIconBtnSelector),
|
||||
await page.click(plusIconBtnSelector),
|
||||
|
||||
// Click on the create channel menu item
|
||||
await page.waitForSelector(createChannelMenuItemSelector),
|
||||
await page.hover(createChannelMenuItemSelector),
|
||||
await page.click(createChannelMenuItemSelector),
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 1000)),
|
||||
|
||||
// Wait for the popup to appear
|
||||
await page.waitForSelector(popupSelector),
|
||||
|
||||
// Filling the channel name
|
||||
await page.waitForSelector(inputChannelNameSelector),
|
||||
await page.focus(inputChannelNameSelector),
|
||||
await page.keyboard.type(config.channels_for_create[0].name),
|
||||
|
||||
// Filling the channel description
|
||||
await page.waitForSelector(inputChannelDescriptionSelector),
|
||||
await page.focus(inputChannelDescriptionSelector),
|
||||
await page.keyboard.type(config.channels_for_create[0].description),
|
||||
|
||||
// Click the channel visibility select
|
||||
// await page.waitForSelector(selectChannelVisibilitySelector),
|
||||
// await page.click(selectChannelVisibilitySelector),
|
||||
|
||||
// FIXME: Select the channel visibility
|
||||
// await page.waitForSelector(selectChannelVisibilityItemSelector),
|
||||
// await page.click(selectChannelVisibilityItemSelector),
|
||||
|
||||
// Click the create button
|
||||
await page.waitForSelector(createButtonSelector),
|
||||
await page.click(createButtonSelector),
|
||||
|
||||
await page.waitForSelector(createButtonSelector),
|
||||
]);
|
||||
|
||||
return page;
|
||||
}
|
||||
@@ -0,0 +1,55 @@
|
||||
import { Browser, Page } from "puppeteer";
|
||||
|
||||
const usernameInputSelector = { console: "#userfield", local: "#username" };
|
||||
const passwordInputSelector = { console: "#passwordfield", local: "#password" };
|
||||
const loginButtonSelector = { console: "#sign_in_button", local: "#login_btn" };
|
||||
|
||||
export async function login(
|
||||
url: string,
|
||||
browser: Browser,
|
||||
credentials: { email: string; password: string },
|
||||
opts: { withConsole: boolean } = { withConsole: false }
|
||||
): Promise<Page> {
|
||||
const context = await browser.createIncognitoBrowserContext();
|
||||
const page = await context.newPage();
|
||||
await page.setViewport({ width: 1920, height: 1080 });
|
||||
|
||||
await Promise.all([
|
||||
// Go to the url
|
||||
await page.goto(url),
|
||||
|
||||
// Username
|
||||
await page.waitForSelector(
|
||||
opts?.withConsole
|
||||
? usernameInputSelector.console
|
||||
: usernameInputSelector.local
|
||||
),
|
||||
await page.focus(
|
||||
opts?.withConsole
|
||||
? usernameInputSelector.console
|
||||
: usernameInputSelector.local
|
||||
),
|
||||
await page.keyboard.type(credentials.email ?? ""),
|
||||
|
||||
// Password
|
||||
await page.waitForSelector(
|
||||
opts?.withConsole
|
||||
? passwordInputSelector.console
|
||||
: passwordInputSelector.local
|
||||
),
|
||||
await page.focus(
|
||||
opts?.withConsole
|
||||
? passwordInputSelector.console
|
||||
: passwordInputSelector.local
|
||||
),
|
||||
await page.keyboard.type(credentials.password ?? ""),
|
||||
|
||||
await page.click(
|
||||
opts?.withConsole
|
||||
? loginButtonSelector.console
|
||||
: loginButtonSelector.local
|
||||
),
|
||||
]);
|
||||
|
||||
return page;
|
||||
}
|
||||
@@ -0,0 +1,60 @@
|
||||
import { Browser, Page } from "puppeteer";
|
||||
|
||||
const signInBtnSelector = { local: "#create_btn" };
|
||||
const firstNameInputSelector = { local: "#first_name_create" };
|
||||
const lastNameInputSelector = { local: "#last_name_create" };
|
||||
const emailInputSelector = { local: "#email_create" };
|
||||
const passwordInputSelector = { local: "#password_create" };
|
||||
const signInContinueBtnSelector = { local: "#continue_btn" };
|
||||
const signedInSelector = { local: ".channels_view" };
|
||||
|
||||
export async function signIn(
|
||||
url: string,
|
||||
browser: Browser,
|
||||
credentials: {
|
||||
email: string;
|
||||
password: string;
|
||||
first_name?: string;
|
||||
last_name?: string;
|
||||
},
|
||||
_opts: { withConsole?: boolean } = { withConsole: false }
|
||||
): Promise<Page> {
|
||||
const context = await browser.createIncognitoBrowserContext();
|
||||
const page = await context.newPage();
|
||||
await page.setViewport({ width: 1920, height: 1080 });
|
||||
|
||||
await Promise.all([
|
||||
// Click on the sign in button
|
||||
await page.goto(url),
|
||||
await page.waitForSelector(signInBtnSelector.local),
|
||||
await page.click(signInBtnSelector.local),
|
||||
|
||||
// First name
|
||||
await page.waitForSelector(firstNameInputSelector.local),
|
||||
await page.focus(firstNameInputSelector.local),
|
||||
await page.keyboard.type(credentials.first_name ?? ""),
|
||||
|
||||
// Last name
|
||||
await page.waitForSelector(lastNameInputSelector.local),
|
||||
await page.focus(lastNameInputSelector.local),
|
||||
await page.keyboard.type(credentials.last_name ?? ""),
|
||||
|
||||
// Email
|
||||
await page.waitForSelector(emailInputSelector.local),
|
||||
await page.focus(emailInputSelector.local),
|
||||
await page.keyboard.type(credentials.email),
|
||||
|
||||
// Password
|
||||
await page.waitForSelector(passwordInputSelector.local),
|
||||
await page.focus(passwordInputSelector.local),
|
||||
await page.keyboard.type(credentials.password),
|
||||
|
||||
// Continue
|
||||
await page.waitForSelector(signInContinueBtnSelector.local),
|
||||
await page.click(signInContinueBtnSelector.local),
|
||||
|
||||
await new Promise((resolve) => setTimeout(resolve, 5000)),
|
||||
]);
|
||||
|
||||
return page;
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
import puppeteer from "puppeteer";
|
||||
|
||||
import config from "../config";
|
||||
|
||||
import { createChannel } from "../steps/create-channel";
|
||||
|
||||
import { createSomeFakeUsers } from "../utils/create-some-fake-users";
|
||||
|
||||
describe("Create channel", () => {
|
||||
it("should be defined after creating a channel", async () => {
|
||||
const { headless, slowMo, executablePath, args } = config;
|
||||
const browser = await puppeteer.launch({
|
||||
headless,
|
||||
slowMo,
|
||||
executablePath,
|
||||
args,
|
||||
});
|
||||
|
||||
const page = await createChannel(
|
||||
config.twake_url,
|
||||
browser,
|
||||
createSomeFakeUsers(1)[0],
|
||||
{
|
||||
withConsole: config.console,
|
||||
}
|
||||
);
|
||||
|
||||
expect(page).toBeDefined();
|
||||
|
||||
await page.close();
|
||||
await browser.close();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,31 @@
|
||||
import puppeteer from "puppeteer";
|
||||
|
||||
import config from "../config";
|
||||
|
||||
import { login } from "../steps/login";
|
||||
|
||||
describe("Login", () => {
|
||||
it("should be defined after login", async () => {
|
||||
const { headless, slowMo, executablePath, args } = config;
|
||||
const browser = await puppeteer.launch({
|
||||
headless,
|
||||
slowMo,
|
||||
executablePath,
|
||||
args,
|
||||
});
|
||||
|
||||
const page = await login(
|
||||
config.twake_url,
|
||||
browser,
|
||||
config.accounts_for_login[0],
|
||||
{
|
||||
withConsole: config.console,
|
||||
}
|
||||
);
|
||||
|
||||
expect(page).toBeDefined();
|
||||
|
||||
await page.close();
|
||||
await browser.close();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,31 @@
|
||||
import puppeteer from "puppeteer";
|
||||
|
||||
import config from "../config";
|
||||
|
||||
import { signIn } from "../steps/signin";
|
||||
|
||||
describe("Sign in", () => {
|
||||
it("should be defined after sign in", async () => {
|
||||
const { headless, slowMo, executablePath, args } = config;
|
||||
const browser = await puppeteer.launch({
|
||||
headless,
|
||||
slowMo,
|
||||
executablePath,
|
||||
args,
|
||||
});
|
||||
|
||||
const page = await signIn(
|
||||
config.twake_url,
|
||||
browser,
|
||||
config.accounts_for_sign_in[0],
|
||||
{
|
||||
withConsole: config.console,
|
||||
}
|
||||
);
|
||||
|
||||
expect(page).toBeDefined();
|
||||
|
||||
await page.close();
|
||||
await browser.close();
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,23 @@
|
||||
import { faker } from "@faker-js/faker";
|
||||
|
||||
export function createSomeFakeChannels(nbOfChannels: number = 1) {
|
||||
let channels: {
|
||||
icon: string;
|
||||
name: string;
|
||||
description?: string;
|
||||
visibility: "public" | "private";
|
||||
is_default: boolean;
|
||||
}[] = [];
|
||||
|
||||
for (let i = 0; i < nbOfChannels; i++) {
|
||||
channels.push({
|
||||
icon: ":smile:",
|
||||
name: faker.commerce.department(),
|
||||
description: faker.lorem.sentence(),
|
||||
visibility: "private",
|
||||
is_default: false,
|
||||
});
|
||||
}
|
||||
|
||||
return channels;
|
||||
}
|
||||
@@ -0,0 +1,21 @@
|
||||
import { faker } from "@faker-js/faker";
|
||||
|
||||
export function createSomeFakeUsers(nbOfUsers: number = 1) {
|
||||
let users: {
|
||||
email: string;
|
||||
password: string;
|
||||
first_name?: string;
|
||||
last_name?: string;
|
||||
}[] = [];
|
||||
|
||||
for (let i = 0; i < nbOfUsers; i++) {
|
||||
users.push({
|
||||
first_name: faker.name.firstName(),
|
||||
last_name: faker.name.lastName(),
|
||||
email: faker.internet.email().toLocaleLowerCase(),
|
||||
password: faker.internet.password(),
|
||||
});
|
||||
}
|
||||
|
||||
return users;
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
import { Page } from "puppeteer";
|
||||
|
||||
import config from "../config";
|
||||
|
||||
export const screenshot = async (context: string, page: Page) => {
|
||||
const currentDate = new Date().toLocaleTimeString();
|
||||
await page.screenshot({
|
||||
path: `${config.screenshot_path}/${context}-${currentDate}.png`,
|
||||
});
|
||||
};
|
||||
@@ -0,0 +1,17 @@
|
||||
{
|
||||
"compilerOptions": {
|
||||
"experimentalDecorators": true,
|
||||
"emitDecoratorMetadata": true,
|
||||
"module": "commonjs",
|
||||
"esModuleInterop": true,
|
||||
"allowSyntheticDefaultImports": true,
|
||||
"target": "es6",
|
||||
"noImplicitAny": true,
|
||||
"moduleResolution": "node",
|
||||
"sourceMap": true,
|
||||
"outDir": "dist",
|
||||
"baseUrl": ".",
|
||||
"resolveJsonModule": true
|
||||
},
|
||||
"include": ["src/**/*"]
|
||||
}
|
||||
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user