Skip to content

Commit

Permalink
chore(tools): create script to spam submissions
Browse files Browse the repository at this point in the history
This commit is to be removed when merging into main.
  • Loading branch information
JeremyFriesenGitHub committed Dec 8, 2024
1 parent b2d72fd commit 552f6f9
Show file tree
Hide file tree
Showing 9 changed files with 188 additions and 0 deletions.
16 changes: 16 additions & 0 deletions tools/risk-form-filler/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import playwright from 'eslint-plugin-playwright'
import baseConfigPromise from '../../eslint.config.js'

export default (async () => {
const baseConfig = await baseConfigPromise

return [
playwright.configs['flat/recommended'],
...baseConfig,
{
files: ['**/*.ts', '**/*.js'],
// Override or add rules here
rules: {},
},
]
})()
8 changes: 8 additions & 0 deletions tools/risk-form-filler/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
{
"name": "risk-form-filler",
"type": "module",
"description": "",
"license": "",
"sideEffects": false,
"scripts": {}
}
45 changes: 45 additions & 0 deletions tools/risk-form-filler/playwright.config.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
// TODO: Investigate node global process usage

import { fileURLToPath } from 'node:url'
import { nxE2EPreset } from '@nx/playwright/preset'

import { defineConfig, devices } from '@playwright/test'

const __filename = fileURLToPath(import.meta.url)

// // For CI, you may want to set BASE_URL to the deployed application.
// const baseURL = process.env.BASE_URL || 'http://127.0.0.1:3000'

/**
* Read environment variables from file.
* https://github.com/motdotla/dotenv
*/
// require('dotenv').config();

/**
* See https://playwright.dev/docs/test-configuration.
*/
export default defineConfig({
...nxE2EPreset(__filename, { testDir: './src' }),
/* Shared settings for all the projects below. See https://playwright.dev/docs/api/class-testoptions. */
retries: 2,
use: {
// baseURL,
/* Collect trace when retrying the failed test. See https://playwright.dev/docs/trace-viewer */
trace: 'on-first-retry',
},
/* Run your local dev server before starting the tests */
// webServer: {
// command: 'pnpm nx start risk-form-filler',
// // url: 'http://127.0.0.1:3000',
// // reuseExistingServer: !process.env.CI,
// cwd: workspaceRoot,
// timeout: 120 * 1000,
// },
projects: [
{
name: 'chromium (desktop)',
use: { ...devices['Desktop Chrome'] },
},
],
})
28 changes: 28 additions & 0 deletions tools/risk-form-filler/project.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
{
"name": "risk-form-filler",
"$schema": "../../node_modules/nx/schemas/project-schema.json",
"sourceRoot": "tools/risk-form-filler",
"projectType": "application",
"tags": [],
"// targets": "to see all targets run: nx show project risk-form-filler --web",
"targets": {
"online": {
"command": "npx tsx src/input/online-input.ts",
"options": {
"cwd": "tools/risk-form-filler"
}
},
"in-person": {
"command": "npx tsx src/input/in-person-input.ts",
"options": {
"cwd": "tools/risk-form-filler"
}
},
"hybrid": {
"command": "npx tsx src/input/hybrid-input.ts",
"options": {
"cwd": "tools/risk-form-filler"
}
}
}
}
6 changes: 6 additions & 0 deletions tools/risk-form-filler/src/defs/online-input-defs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
export interface ScheduleOnlineParams {
name: string
email: string
subject: string
message: string
}
20 changes: 20 additions & 0 deletions tools/risk-form-filler/src/input/online-input.ts

Large diffs are not rendered by default.

9 changes: 9 additions & 0 deletions tools/risk-form-filler/src/online.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
import type { ScheduleOnlineParams } from './input/schedule-online-params'

import type { FormsLayout } from './pom'

export async function scheduleOnline(params: ScheduleOnlineParams, formLayout: FormsLayout) {
await formLayout.goto()
await formLayout.fillContactPage(formLayout, params.name, params.email, params.subject, params.message)
await formLayout.submitButton.click()
}
38 changes: 38 additions & 0 deletions tools/risk-form-filler/src/pom.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import type { Locator, Page } from '@playwright/test'

export class FormsLayout {
// Page object
readonly page: Page

// textboxes
readonly nameTextBox: Locator
readonly emailTextBox: Locator
readonly subjectTextBox: Locator
readonly messageTextBox: Locator

// buttons
readonly submitButton: Locator

constructor(page: Page) {
this.page = page

this.nameTextBox = page.getByPlaceholder('Your Name')
this.emailTextBox = page.getByPlaceholder('Your Email')
this.subjectTextBox = page.getByPlaceholder('Subject')
this.messageTextBox = page.getByPlaceholder('Your Message')

this.submitButton = page.getByRole('button', { name: 'Send Message' })
}

// goto
async goto() {
await this.page.goto('http://localhost:3000/#contactpage')
}

async fillContactPage(formLayout: FormsLayout, NAME: string, EMAIL: string, SUBJECT: string, MESSAGE: string) {
await formLayout.nameTextBox.fill(NAME)
await formLayout.emailTextBox.fill(EMAIL)
await formLayout.subjectTextBox.fill(SUBJECT)
await formLayout.messageTextBox.fill(MESSAGE)
}
}
18 changes: 18 additions & 0 deletions tools/risk-form-filler/tsconfig.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
{
"extends": "../../tsconfig.base.json",
"compilerOptions": {
"moduleResolution": "node",
"outDir": "../../dist/out-tsc",
"esModuleInterop": true
},
"include": [
"**/*.ts",
"**/*.js",
"playwright.config.ts",
"src/**/*.spec.ts",
"src/**/*.spec.js",
"src/**/*.test.ts",
"src/**/*.test.js",
"src/**/*.d.ts"
]
}

0 comments on commit 552f6f9

Please sign in to comment.