From e4857f2331eb32806d1591235a307bd5e608b599 Mon Sep 17 00:00:00 2001 From: Moros Smith Date: Fri, 26 Apr 2024 13:38:57 -0400 Subject: [PATCH 1/6] break out the agree dialog into it's own file --- resources/js/app.js | 84 ++++++++------------------------- resources/js/lib/agreeDialog.js | 68 ++++++++++++++++++++++++++ 2 files changed, 87 insertions(+), 65 deletions(-) create mode 100644 resources/js/lib/agreeDialog.js diff --git a/resources/js/app.js b/resources/js/app.js index 00b94c9..78192af 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -3,6 +3,8 @@ import './lib/goldenLayout'; import './lib/monaco'; import './lib/lucide'; import version from "./lib/version"; +import agreeDialog from './lib/agreeDialog'; +agreeDialog let sharedFlag = (window.location.pathname.indexOf("/s/") === 0); @@ -548,73 +550,25 @@ console.log((version != pgetinkerVersion)); let agreedToTerms = window.localStorage.getItem("pgetinkerAgreedToTerms"); agreedToTerms = (agreedToTerms == null) ? false : JSON.parse(agreedToTerms); -if(agreedToTerms) +if(!agreedToTerms) { - SetupLayout(); + agreeDialog() + .then(() => + { + SetupLayout(); + window.localStorage.setItem("pgetinkerAgreedToTerms", JSON.stringify(true)); + }) + .catch(() => + { + window.localStorage.removeItem("pgetinkerCode"); + window.localStorage.removeItem("pgetinkerTheme"); + window.localStorage.removeItem("pgetinkerLayout"); + window.localStorage.removeItem("pgetinkerVersion"); + window.location.pathname = "/disagree"; + }); } else { - let agreeDialog = document.createElement('div'); - agreeDialog.setAttribute("class", "dialog first-time"); - agreeDialog.innerHTML = ` -
-
Welome to PGEtinker!
-
-

Hello and Welcome

-

- It would appear to be the first time you've - visited this site, at least from this browser. - In order for PGEtinker to function we require - your permission to do some things. -

-

Terms, in Plain English

-

- You agree that PGEtinker has permission to: -

-
    -
  • - Store information in your browser to be used within - the confines of the PGEtinker online application. - It's for stuff like persiting your layout, your - theme, and other options so when you come back - it's the way you left it. -
  • -
  • - Compile and display the code you provide. -
  • -
  • - Retain and review the code you have provided - for the purposes of diagnosing problems with the - PGEtinker online application. -
  • -
  • - Share your code worldwide. This only applies if you - use the "Share" functionality. -
  • -
-
- -
`; - - agreeDialog.querySelector("button.cancel").addEventListener("click", (event) => - { - window.localStorage.removeItem("pgetinkerCode"); - window.localStorage.removeItem("pgetinkerTheme"); - window.localStorage.removeItem("pgetinkerLayout"); - window.location.pathname = "/disagree"; - }); - - agreeDialog.querySelector("button.ok").addEventListener("click", (event) => - { - SetupLayout(); - - window.localStorage.setItem("pgetinkerAgreedToTerms", JSON.stringify(true)); - agreeDialog.remove(); - }); - - document.body.appendChild(agreeDialog); + SetupLayout(); } - + diff --git a/resources/js/lib/agreeDialog.js b/resources/js/lib/agreeDialog.js new file mode 100644 index 0000000..2007866 --- /dev/null +++ b/resources/js/lib/agreeDialog.js @@ -0,0 +1,68 @@ +export default function agreeDialog() +{ + return new Promise((resolve, reject) => + { + let agreeDialog = document.createElement("div"); + + agreeDialog.classList.toggle("dialog", true); + agreeDialog.classList.toggle("first-time", true); + + agreeDialog.innerHTML = ` +
+
Welome to PGEtinker!
+
+

Hello and Welcome

+

+ It would appear to be the first time you've + visited this site, at least from this browser. + In order for PGEtinker to function we require + your permission to do some things. +

+

Terms, in Plain English

+

+ You agree that PGEtinker has permission to: +

+
    +
  • + Store information in your browser to be used within + the confines of the PGEtinker online application. + It's for stuff like persiting your layout, your + theme, and other options so when you come back + it's the way you left it. +
  • +
  • + Compile and display the code you provide. +
  • +
  • + Retain and review the code you have provided + for the purposes of diagnosing problems with the + PGEtinker online application. +
  • +
  • + Share your code worldwide. This only applies if you + use the "Share" functionality. +
  • +
+
+ +
`; + + agreeDialog.querySelector("#i-disagree").addEventListener("click", (event) => + { + reject(); + agreeDialog.remove(); + }); + + agreeDialog.querySelector("#i-agree").addEventListener("click", (event) => + { + resolve(); + agreeDialog.remove(); + }); + + document.body.appendChild(agreeDialog); + }); + +} \ No newline at end of file From 3a271545db87f77e8e3f12358fa625187ef2f192 Mon Sep 17 00:00:00 2001 From: Moros Smith Date: Fri, 26 Apr 2024 13:51:55 -0400 Subject: [PATCH 2/6] break out the share dialog into it's own file --- resources/js/app.js | 44 ++++++--------------------------- resources/js/lib/shareDialog.js | 43 ++++++++++++++++++++++++++++++++ 2 files changed, 50 insertions(+), 37 deletions(-) create mode 100644 resources/js/lib/shareDialog.js diff --git a/resources/js/app.js b/resources/js/app.js index 78192af..1bd5b0b 100644 --- a/resources/js/app.js +++ b/resources/js/app.js @@ -4,7 +4,7 @@ import './lib/monaco'; import './lib/lucide'; import version from "./lib/version"; import agreeDialog from './lib/agreeDialog'; -agreeDialog +import shareDialog from './lib/shareDialog'; let sharedFlag = (window.location.pathname.indexOf("/s/") === 0); @@ -348,32 +348,12 @@ function SetupLayout() code: monacoEditor.getValue() }).then((response) => { - let shareDialog = document.createElement('div'); - - shareDialog.classList.toggle("dialog", "true"); - shareDialog.classList.toggle("share-dialog", "true"); - shareDialog.innerHTML = ` -
-
Share Your Masterpiece!
-
-
- - - -
-
-
`; - - shareDialog.querySelector("button").addEventListener("click", (event) => - { - navigator.clipboard.writeText(response.data.shareURL).catch((reason) => console.log(reason)); - shareDialog.remove(); - }); - - document.body.appendChild(shareDialog); - - compileSuccessHandler(response.data); - + shareDialog(response.data.shareURL) + .finally(() => + { + compileSuccessHandler(response.data); + }); + }).catch((error) => { if(error.response) @@ -508,16 +488,6 @@ function UpdateStatusBar() `; } -// you're welcome dandistine -window.addEventListener("click", (event) => -{ - let shareDialog = document.querySelector(".share-dialog"); - if(shareDialog == null) - return; - - shareDialog.querySelector("button").dispatchEvent(new Event("click")); -}); - window.addEventListener("message", (event) => { if(typeof event.data !== "object") diff --git a/resources/js/lib/shareDialog.js b/resources/js/lib/shareDialog.js new file mode 100644 index 0000000..34deab3 --- /dev/null +++ b/resources/js/lib/shareDialog.js @@ -0,0 +1,43 @@ +export default function shareDialog(shareUrl) +{ + function shareClickAnywhereHandler(event) + { + let shareDialog = document.querySelector(".share-dialog"); + if(shareDialog == null) + return; + + shareDialog.querySelector("button").dispatchEvent(new Event("click")); + } + + return new Promise((resolve) => + { + let shareDialog = document.createElement('div'); + + shareDialog.classList.toggle("dialog", "true"); + shareDialog.classList.toggle("share-dialog", "true"); + shareDialog.innerHTML = ` +
+
Share Your Masterpiece!
+
+
+ + + +
+
+
`; + + shareDialog.querySelector("button").addEventListener("click", (event) => + { + navigator.clipboard.writeText(shareUrl).catch((reason) => console.log(reason)); + shareDialog.remove(); + window.removeEventListener("click", shareClickAnywhereHandler); + resolve(); + }); + + document.body.appendChild(shareDialog); + + // you're welcome dandistine + window.addEventListener("click", shareClickAnywhereHandler); + }); +} From 9dbdf3a6795d5d84228f6c02d55257aa62ae06fc Mon Sep 17 00:00:00 2001 From: Moros Smith Date: Sat, 27 Apr 2024 07:11:15 -0400 Subject: [PATCH 3/6] dusk browser testing --- .env.example | 2 +- composer.json | 1 + composer.lock | 140 ++++++++++++++++++++++++++- resources/views/home.blade.php | 4 +- tests/Browser/QuickTest.php | 101 +++++++++++++++++++ tests/Browser/console/.gitignore | 2 + tests/Browser/screenshots/.gitignore | 2 + tests/Browser/source/.gitignore | 2 + tests/DuskTestCase.php | 46 +++++++++ 9 files changed, 296 insertions(+), 4 deletions(-) create mode 100644 tests/Browser/QuickTest.php create mode 100644 tests/Browser/console/.gitignore create mode 100644 tests/Browser/screenshots/.gitignore create mode 100644 tests/Browser/source/.gitignore create mode 100644 tests/DuskTestCase.php diff --git a/.env.example b/.env.example index b683e3e..ae0abbc 100644 --- a/.env.example +++ b/.env.example @@ -3,7 +3,7 @@ APP_ENV=local APP_KEY= APP_DEBUG=true APP_TIMEZONE=UTC -APP_URL=http://localhost +APP_URL=http://127.0.0.1:8000 APP_LOCALE=en APP_FALLBACK_LOCALE=en diff --git a/composer.json b/composer.json index 69d4388..23db944 100644 --- a/composer.json +++ b/composer.json @@ -13,6 +13,7 @@ }, "require-dev": { "fakerphp/faker": "^1.23", + "laravel/dusk": "^8.2", "laravel/pint": "^1.13", "laravel/sail": "^1.26", "mockery/mockery": "^1.6", diff --git a/composer.lock b/composer.lock index 6427963..6ea7f9a 100644 --- a/composer.lock +++ b/composer.lock @@ -4,7 +4,7 @@ "Read more about it at https://getcomposer.org/doc/01-basic-usage.md#installing-dependencies", "This file is @generated automatically" ], - "content-hash": "398060acfd420c8e7e5eaeafe9cd15eb", + "content-hash": "98754fa2c3a24cebb2869e901a5b34b7", "packages": [ { "name": "brick/math", @@ -5935,6 +5935,78 @@ }, "time": "2020-07-09T08:09:16+00:00" }, + { + "name": "laravel/dusk", + "version": "v8.2.0", + "source": { + "type": "git", + "url": "https://github.com/laravel/dusk.git", + "reference": "773a12dfbd3f84174b0f26fbc2807a414a379a66" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/laravel/dusk/zipball/773a12dfbd3f84174b0f26fbc2807a414a379a66", + "reference": "773a12dfbd3f84174b0f26fbc2807a414a379a66", + "shasum": "" + }, + "require": { + "ext-json": "*", + "ext-zip": "*", + "guzzlehttp/guzzle": "^7.5", + "illuminate/console": "^10.0|^11.0", + "illuminate/support": "^10.0|^11.0", + "php": "^8.1", + "php-webdriver/webdriver": "^1.9.0", + "symfony/console": "^6.2|^7.0", + "symfony/finder": "^6.2|^7.0", + "symfony/process": "^6.2|^7.0", + "vlucas/phpdotenv": "^5.2" + }, + "require-dev": { + "mockery/mockery": "^1.6", + "orchestra/testbench": "^8.19|^9.0", + "phpstan/phpstan": "^1.10", + "phpunit/phpunit": "^10.1|^11.0", + "psy/psysh": "^0.11.12|^0.12" + }, + "suggest": { + "ext-pcntl": "Used to gracefully terminate Dusk when tests are running." + }, + "type": "library", + "extra": { + "laravel": { + "providers": [ + "Laravel\\Dusk\\DuskServiceProvider" + ] + } + }, + "autoload": { + "psr-4": { + "Laravel\\Dusk\\": "src/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "authors": [ + { + "name": "Taylor Otwell", + "email": "taylor@laravel.com" + } + ], + "description": "Laravel Dusk provides simple end-to-end testing and browser automation.", + "keywords": [ + "laravel", + "testing", + "webdriver" + ], + "support": { + "issues": "https://github.com/laravel/dusk/issues", + "source": "https://github.com/laravel/dusk/tree/v8.2.0" + }, + "time": "2024-04-16T15:51:19+00:00" + }, { "name": "laravel/pint", "version": "v1.15.1", @@ -6421,6 +6493,72 @@ }, "time": "2022-02-21T01:04:05+00:00" }, + { + "name": "php-webdriver/webdriver", + "version": "1.15.1", + "source": { + "type": "git", + "url": "https://github.com/php-webdriver/php-webdriver.git", + "reference": "cd52d9342c5aa738c2e75a67e47a1b6df97154e8" + }, + "dist": { + "type": "zip", + "url": "https://api.github.com/repos/php-webdriver/php-webdriver/zipball/cd52d9342c5aa738c2e75a67e47a1b6df97154e8", + "reference": "cd52d9342c5aa738c2e75a67e47a1b6df97154e8", + "shasum": "" + }, + "require": { + "ext-curl": "*", + "ext-json": "*", + "ext-zip": "*", + "php": "^7.3 || ^8.0", + "symfony/polyfill-mbstring": "^1.12", + "symfony/process": "^5.0 || ^6.0 || ^7.0" + }, + "replace": { + "facebook/webdriver": "*" + }, + "require-dev": { + "ergebnis/composer-normalize": "^2.20.0", + "ondram/ci-detector": "^4.0", + "php-coveralls/php-coveralls": "^2.4", + "php-mock/php-mock-phpunit": "^2.0", + "php-parallel-lint/php-parallel-lint": "^1.2", + "phpunit/phpunit": "^9.3", + "squizlabs/php_codesniffer": "^3.5", + "symfony/var-dumper": "^5.0 || ^6.0" + }, + "suggest": { + "ext-SimpleXML": "For Firefox profile creation" + }, + "type": "library", + "autoload": { + "files": [ + "lib/Exception/TimeoutException.php" + ], + "psr-4": { + "Facebook\\WebDriver\\": "lib/" + } + }, + "notification-url": "https://packagist.org/downloads/", + "license": [ + "MIT" + ], + "description": "A PHP client for Selenium WebDriver. Previously facebook/webdriver.", + "homepage": "https://github.com/php-webdriver/php-webdriver", + "keywords": [ + "Chromedriver", + "geckodriver", + "php", + "selenium", + "webdriver" + ], + "support": { + "issues": "https://github.com/php-webdriver/php-webdriver/issues", + "source": "https://github.com/php-webdriver/php-webdriver/tree/1.15.1" + }, + "time": "2023-10-20T12:21:20+00:00" + }, { "name": "phpunit/php-code-coverage", "version": "11.0.3", diff --git a/resources/views/home.blade.php b/resources/views/home.blade.php index 2b9f7e8..98a4e96 100644 --- a/resources/views/home.blade.php +++ b/resources/views/home.blade.php @@ -21,7 +21,7 @@