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
42 changes: 42 additions & 0 deletions buildship_app_tests/basic_workflows/1_create_basic_workflow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
async function run({ page }) {
await page.locator('body').click();
await page.locator('div:nth-child(2) > .MuiButtonBase-root').first().click();
await page.getByRole('link', { name: 'Untitled Workflow' }).getByRole('button').click();
await page.getByRole('menuitem', { name: 'Settings' }).click();
await page.locator('div').filter({ hasText: 'DisplaySet how this workflow is displayed to usersWorkflow nameUser-facing name ' }).nth(2).click();
await page.getByLabel('Workflow name').dblclick();
await page.getByLabel('Workflow name').fill('helloworld');
await page.getByRole('button', { name: 'Save' }).click();
await page.getByRole('button', { name: 'Add Trigger' }).click();
await page.getByRole('button', { name: 'Rest API Call' }).click();
await page.getByRole('button', { name: 'Add Trigger' }).click();
await page.getByPlaceholder('Value').click();
await page.getByPlaceholder('Value').fill('/helloworld');
await page.locator('.MuiStack-root > div > div > div:nth-child(2) > .MuiStack-root').click();
await page.getByRole('button', { name: 'Return' }).click();
await page.getByRole('button', { name: 'Add Node' }).click();
await page.getByLabel('​', { exact: true }).click();
await page.getByRole('option', { name: 'OK (200)' }).click();
await page.getByLabel('Value', { exact: true }).click();
await page.getByLabel('Value', { exact: true }).fill('helloworld');
await page.getByRole('button', { name: 'Ship' }).click();
await page.waitForResponse(res => res.url().includes("/deploy-workflow") && res.status() === 200)

const url = await page.url()

const projectId = url?.split("/")?.[4]

const uniqueId = projectId?.split("-")?.[1]

const deployedURL = `https://${uniqueId}.buildship.run/helloworld`

return deployedURL
}

async function validate({ page, fetch, expect }) {
const data = await run({ page })

const res = await (await fetch(data)).text()

expect(res).toBe("helloworld")
}
28 changes: 28 additions & 0 deletions buildship_app_tests/basic_workflows/2_delete_basic_workflow.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
async function run({ page }) {
await page.locator('.MuiBackdrop-root').click();
await page.getByRole('link', { name: 'helloworld' }).click();
await page.getByRole('link', { name: 'helloworld' }).getByRole('button').click();
await page.getByRole('menuitem', { name: 'Delete' }).click();
await page.getByPlaceholder('helloworld').click();
await page.getByPlaceholder('helloworld').fill('helloworld');
await page.getByRole('button', { name: 'Delete' }).click();
await page.waitForResponse(res => res.url().includes("/delete-workflow") && res.status() === 200)

const url = await page.url()

const projectId = url?.split("/")?.[4]

const uniqueId = projectId?.split("-")?.[1]

const unDeployedURL = `https://${uniqueId}.buildship.run/helloworld`

return unDeployedURL
}

async function validate({ page, fetch, expect }) {
const data = await run({ page })

const res = await fetch(data)

expect(res?.status).not.toBe(200)
}
91 changes: 80 additions & 11 deletions lib/davatar.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,42 @@
/**
* Using strict mode
*/
"use strict";

const {
getTextColor,
getBackgroundColor,
generateInitials,
} = require("./helpers/mainFunctions");
const {
checkImageSize,
checkImageText,
} = require("./helpers/validationFunctions");
const { createCanvas } = require("canvas");
/**
* A set of functions used to create an avatar
* @namespace helpers
*/

/**
* A set of functions used to validate the input of the avatar
* @namespace helpers/validationFunctions
*/

/**
* A set of functions used to generate the main content of the avatar
* @namespace helpers/mainFunctions
*/

/**
* The main Davatar class
* @class
* @memberof helpers
*/
class Davatar {
/**
* Method used to generate an avatar
* @method
* @memberof helpers
* @param {object} [options={}] - Options of the generated avatar
* @param {number} [size=64] - Size of the avatar
* @param {string} text - Text used to generate the avatar
* @param {string} [textColor=getTextColor()] - Color of the text in the avatar
* @param {string} [backgroundColor=getBackgroundColor()] - Color of the background of the avatar
* @param {string} [fontFamily=Arial] - Font family of the text used
* @param {number} [fontWeight=100] - Font weight of the text used
* @returns {string} A string representing a data url of the generated avatar
*/
generate({
size = 64,
text,
Expand All @@ -20,18 +45,62 @@ class Davatar {
fontFamily = "Arial",
fontWeight = 100,
} = {}) {
/**
* Checks the size of the avatar
* @constant
* @memberof helpers
* @param {number} [size=64] - Size of the avatar
* @returns {boolean} True if the size is valid, false otherwise
*/
const checkSize = checkImageSize(size);
/**
* Checks the text of the avatar
* @constant
* @memberof helpers
* @param {string} text - Text used to generate the avatar
* @returns {boolean} True if the text is valid, false otherwise
*/
const checkText = checkImageText(text);
if (checkSize && checkText) {
/**
* The height fix for the text
* @constant
* @memberof helpers
* @type {number}
*/
const HEIGHT_FIX = 4.6875;
/**
* The final text used for the avatar
* @constant
* @memberof helpers
* @type {string}
*/
const finalText = generateInitials(text);
/**
* Creates a canvas
* @constant
* @memberof helpers
* @type {Canvas}
*/
const canvas = createCanvas(size, size);
/**
* The context of the canvas
* @constant
* @memberof helpers
* @type {CanvasRenderingContext2D}
*/
const ctx = canvas.getContext("2d");

ctx.fillStyle = backgroundColor;
ctx.fillRect(0, 0, size, size);

const measureText = ctx.measureText(finalText);
/**
* The emHeightAscent of the text
* @constant
* @memberof helpers
* @type {boolean}
*/
const emHeightAscent = measureText.emHeightAscent === undefined;

const textX = size / 2;
Expand All @@ -52,4 +121,4 @@ class Davatar {
}
}

exports.davatar = new Davatar();
exports.davatar = new Davatar();