From 3c15be10976c630f84356c34909590eb23817fd0 Mon Sep 17 00:00:00 2001 From: Deepanshu Dhruw Date: Fri, 17 Nov 2023 16:29:09 +0530 Subject: [PATCH 1/5] added doc strings --- lib/davatar.js | 91 ++++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 80 insertions(+), 11 deletions(-) diff --git a/lib/davatar.js b/lib/davatar.js index e9d2567..bdee031 100644 --- a/lib/davatar.js +++ b/lib/davatar.js @@ -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, @@ -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; @@ -52,4 +121,4 @@ class Davatar { } } -exports.davatar = new Davatar(); +exports.davatar = new Davatar(); \ No newline at end of file From f426bf92fef15515aae48a1c98dc4b1d3621f6ee Mon Sep 17 00:00:00 2001 From: devblin Date: Wed, 22 Nov 2023 13:28:24 +0530 Subject: [PATCH 2/5] test --- buildship_app_tests/test1.js | 31 +++++++++++++++++++++++++++++++ buildship_app_tests/test2.js | 31 +++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+) create mode 100644 buildship_app_tests/test1.js create mode 100644 buildship_app_tests/test2.js diff --git a/buildship_app_tests/test1.js b/buildship_app_tests/test1.js new file mode 100644 index 0000000..84f7ed7 --- /dev/null +++ b/buildship_app_tests/test1.js @@ -0,0 +1,31 @@ +const { chromium } = require("playwright"); + +async function run() { + const browser = await chromium.launch(); + const page = await browser.newPage(); + await page + .locator("div:nth-child(2) > .MuiButtonBase-root") + .first() + .click(); + await page + .getByRole("banner") + .locator("div") + .filter({ hasText: "Untitled Workflow" }) + .getByRole("button") + .click(); + await page.getByText("Settings").click(); + await page.getByLabel("Workflow name").click({ clickCount: 3 }); + await page.getByLabel("Workflow name").fill("WorkflowToBeDeleted"); + await page.getByRole("button", { name: "Save" }).click(); + await page + .getByRole("link", { name: "WorkflowToBeDeleted" }) + .getByRole("button") + .click(); + await page.getByText("Delete", { exact: true }).click(); + await page.getByPlaceholder("WorkflowToBeDeleted").click(); + await page + .getByPlaceholder("WorkflowToBeDeleted") + .fill("WorkflowToBeDeleted"); + await page.getByRole("button", { name: "Delete" }).click(); + await browser.close(); +} \ No newline at end of file diff --git a/buildship_app_tests/test2.js b/buildship_app_tests/test2.js new file mode 100644 index 0000000..84f7ed7 --- /dev/null +++ b/buildship_app_tests/test2.js @@ -0,0 +1,31 @@ +const { chromium } = require("playwright"); + +async function run() { + const browser = await chromium.launch(); + const page = await browser.newPage(); + await page + .locator("div:nth-child(2) > .MuiButtonBase-root") + .first() + .click(); + await page + .getByRole("banner") + .locator("div") + .filter({ hasText: "Untitled Workflow" }) + .getByRole("button") + .click(); + await page.getByText("Settings").click(); + await page.getByLabel("Workflow name").click({ clickCount: 3 }); + await page.getByLabel("Workflow name").fill("WorkflowToBeDeleted"); + await page.getByRole("button", { name: "Save" }).click(); + await page + .getByRole("link", { name: "WorkflowToBeDeleted" }) + .getByRole("button") + .click(); + await page.getByText("Delete", { exact: true }).click(); + await page.getByPlaceholder("WorkflowToBeDeleted").click(); + await page + .getByPlaceholder("WorkflowToBeDeleted") + .fill("WorkflowToBeDeleted"); + await page.getByRole("button", { name: "Delete" }).click(); + await browser.close(); +} \ No newline at end of file From d42cbb93fd706c846ab344acc3217a0f35598aab Mon Sep 17 00:00:00 2001 From: devblin Date: Fri, 1 Dec 2023 16:38:41 +0530 Subject: [PATCH 3/5] one more tedt --- buildship_app_tests/test2.js | 57 +++++++++++++++++------------------- 1 file changed, 27 insertions(+), 30 deletions(-) diff --git a/buildship_app_tests/test2.js b/buildship_app_tests/test2.js index 84f7ed7..11b3b59 100644 --- a/buildship_app_tests/test2.js +++ b/buildship_app_tests/test2.js @@ -1,31 +1,28 @@ -const { chromium } = require("playwright"); - -async function run() { - const browser = await chromium.launch(); - const page = await browser.newPage(); - await page - .locator("div:nth-child(2) > .MuiButtonBase-root") - .first() - .click(); - await page - .getByRole("banner") - .locator("div") - .filter({ hasText: "Untitled Workflow" }) - .getByRole("button") - .click(); - await page.getByText("Settings").click(); - await page.getByLabel("Workflow name").click({ clickCount: 3 }); - await page.getByLabel("Workflow name").fill("WorkflowToBeDeleted"); - await page.getByRole("button", { name: "Save" }).click(); - await page - .getByRole("link", { name: "WorkflowToBeDeleted" }) - .getByRole("button") - .click(); - await page.getByText("Delete", { exact: true }).click(); - await page.getByPlaceholder("WorkflowToBeDeleted").click(); - await page - .getByPlaceholder("WorkflowToBeDeleted") - .fill("WorkflowToBeDeleted"); - await page.getByRole("button", { name: "Delete" }).click(); - await browser.close(); +async function run({ page }) { + await page.getByRole('link', { name: 'expression-editor' }).click(); + await page.getByRole('button', { name: 'Ship' }).click(); + + const url = await page.url() + + const projectId = url?.split("/")?.[4] + + const uniqueId = projectId?.split("-")?.[1] + + const deployedURL = `https://${uniqueId}.buildship.run/expression-editor` + + return deployedURL +} + +async function validate({ page, fetch, expect }) { + const url = await run({ page }) + + const res = await (await fetch(url, { + method: 'POST', + headers: { + 'Content-Type': 'application/json', + }, + body: JSON.stringify({ array: [1, 2, 3, 4] }) + })).json() + + expect(res).toBe(["ODD", "EVEN", "ODD", "EVEN"]) } \ No newline at end of file From 5ffdae5b9f087f17b3fee413c31283a87beaba0f Mon Sep 17 00:00:00 2001 From: devblin Date: Fri, 1 Dec 2023 16:40:01 +0530 Subject: [PATCH 4/5] one more tedt --- buildship_app_tests/test1.js | 72 +++++++++++++++++++++--------------- 1 file changed, 42 insertions(+), 30 deletions(-) diff --git a/buildship_app_tests/test1.js b/buildship_app_tests/test1.js index 84f7ed7..f4d57b6 100644 --- a/buildship_app_tests/test1.js +++ b/buildship_app_tests/test1.js @@ -1,31 +1,43 @@ -const { chromium } = require("playwright"); - -async function run() { - const browser = await chromium.launch(); - const page = await browser.newPage(); - await page - .locator("div:nth-child(2) > .MuiButtonBase-root") - .first() - .click(); - await page - .getByRole("banner") - .locator("div") - .filter({ hasText: "Untitled Workflow" }) - .getByRole("button") - .click(); - await page.getByText("Settings").click(); - await page.getByLabel("Workflow name").click({ clickCount: 3 }); - await page.getByLabel("Workflow name").fill("WorkflowToBeDeleted"); - await page.getByRole("button", { name: "Save" }).click(); - await page - .getByRole("link", { name: "WorkflowToBeDeleted" }) - .getByRole("button") - .click(); - await page.getByText("Delete", { exact: true }).click(); - await page.getByPlaceholder("WorkflowToBeDeleted").click(); - await page - .getByPlaceholder("WorkflowToBeDeleted") - .fill("WorkflowToBeDeleted"); - await page.getByRole("button", { name: "Delete" }).click(); - await browser.close(); +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 run1({ page }) + + const res = await (await fetch(data)).text() + + expect(res).toBe("helloworld") } \ No newline at end of file From 25ed54ddb1e64ab4e13cdea7b0de21c41a59a9a6 Mon Sep 17 00:00:00 2001 From: devblin Date: Mon, 4 Dec 2023 15:25:58 +0530 Subject: [PATCH 5/5] test --- .../1_create_basic_workflow.js} | 3 +- .../2_delete_basic_workflow.js | 28 +++++++++++++++++++ buildship_app_tests/test2.js | 28 ------------------- 3 files changed, 29 insertions(+), 30 deletions(-) rename buildship_app_tests/{test1.js => basic_workflows/1_create_basic_workflow.js} (98%) create mode 100644 buildship_app_tests/basic_workflows/2_delete_basic_workflow.js delete mode 100644 buildship_app_tests/test2.js diff --git a/buildship_app_tests/test1.js b/buildship_app_tests/basic_workflows/1_create_basic_workflow.js similarity index 98% rename from buildship_app_tests/test1.js rename to buildship_app_tests/basic_workflows/1_create_basic_workflow.js index f4d57b6..4ec7340 100644 --- a/buildship_app_tests/test1.js +++ b/buildship_app_tests/basic_workflows/1_create_basic_workflow.js @@ -33,9 +33,8 @@ async function run({ page }) { return deployedURL } - async function validate({ page, fetch, expect }) { - const data = await run1({ page }) + const data = await run({ page }) const res = await (await fetch(data)).text() diff --git a/buildship_app_tests/basic_workflows/2_delete_basic_workflow.js b/buildship_app_tests/basic_workflows/2_delete_basic_workflow.js new file mode 100644 index 0000000..1290df6 --- /dev/null +++ b/buildship_app_tests/basic_workflows/2_delete_basic_workflow.js @@ -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) +} \ No newline at end of file diff --git a/buildship_app_tests/test2.js b/buildship_app_tests/test2.js deleted file mode 100644 index 11b3b59..0000000 --- a/buildship_app_tests/test2.js +++ /dev/null @@ -1,28 +0,0 @@ -async function run({ page }) { - await page.getByRole('link', { name: 'expression-editor' }).click(); - await page.getByRole('button', { name: 'Ship' }).click(); - - const url = await page.url() - - const projectId = url?.split("/")?.[4] - - const uniqueId = projectId?.split("-")?.[1] - - const deployedURL = `https://${uniqueId}.buildship.run/expression-editor` - - return deployedURL -} - -async function validate({ page, fetch, expect }) { - const url = await run({ page }) - - const res = await (await fetch(url, { - method: 'POST', - headers: { - 'Content-Type': 'application/json', - }, - body: JSON.stringify({ array: [1, 2, 3, 4] }) - })).json() - - expect(res).toBe(["ODD", "EVEN", "ODD", "EVEN"]) -} \ No newline at end of file