Skip to content

Commit

Permalink
feat(tools/risk-form-filler): create script
Browse files Browse the repository at this point in the history
  • Loading branch information
JeremyFriesenGitHub committed Dec 7, 2024
1 parent e93e90d commit 06e2389
Show file tree
Hide file tree
Showing 18 changed files with 1,171 additions and 0 deletions.
15 changes: 15 additions & 0 deletions tools/risk-form-filler/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# Workflow Execution Guide

To run the script, use either one of these commands in the CLI to run a specific workflow:

1. `pnpm nx run risk-form-filler:online` --> for submitting online events
2. `pnpm nx run risk-form-filler:in-person` --> for submitting in-person events
3. `pnpm nx run risk-form-filler:hybrid` --> for submitting hybrid events

This will compile and automatically run a workflow for that specifc type of form.

Be sure to change the input for that according workflow (for instance, change your hybrid input answers in src/input/hybrid-input.ts to something that is to your liking)

Note that although these forms automate answers, please make a review to ensure that all the information on the form is filled completely and accurate before submission.

Don't forget to end your session by pressing `CTRL C`.
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: {},
},
]
})()
19 changes: 19 additions & 0 deletions tools/risk-form-filler/helpers/get-user-confirmation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
import process from 'node:process'

import readline from 'node:readline'

export async function getUserConfirmation(prompt: string): Promise<boolean> {
const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
})

const answer = await new Promise<string>((resolve) => {
rl.question(prompt, (response) => {
rl.close()
resolve(response.trim().toLowerCase())
})
})

return answer === 'yes' || answer === 'y'
}
36 changes: 36 additions & 0 deletions tools/risk-form-filler/helpers/validation.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
export function validateDate(date: string): boolean {
const dateRegex = /^\d{4}\/\d{2}\/\d{2}$/
if (!dateRegex.test(date)) {
return false
}

const [year, month, day] = date.split('/').map(Number)
if (year < 1900 || year > 2100 || month < 1 || month > 12 || day < 1 || day > 31) {
return false
}
if (month === 2) {
const isLeapYear = (year % 4 === 0 && year % 100 !== 0) || year % 400 === 0
if (day > 29 || (day === 29 && !isLeapYear)) {
return false
}
}
if ([4, 6, 9, 11].includes(month) && day > 30) {
return false
}

return true
}

export function validateTime(time: string): boolean {
const timeRegex = /^(?:[01]\d|2[0-3]):[0-5]\d (?:AM|PM)$/
return timeRegex.test(time)
}

export function validateStudentID(studentId: number): boolean {
return studentId >= 100000000 && studentId <= 111111111
}

export function validateCarletonEmail(email: string): boolean {
const emailParts = email.split('@')
return emailParts.length === 2 && emailParts[1] === 'cmail.carleton.ca'
}
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"
}
}
}
}
45 changes: 45 additions & 0 deletions tools/risk-form-filler/src/defs/hybrid-input-defs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
export interface ScheduleHybridParams {
primaryOrganizer: {
firstName: string
lastName: string
studentID: number
email: string
phone: string
}

secondaryOrganizer: {
firstName: string
lastName: string
studentID: number
email: string
phone: string
}

eventDetails: {
title: string
date: string // Format: 'YYYY/MM/DD'
startTime: string // Format: 'HH:MM AM/PM'
endTime: string // Format: 'HH:MM AM/PM'
description: string
location: string
expectedAttendees: number
}

onlineInformation: {
platform: string
topics: string
location: string
numberOfOrganizers: number
organizersAttendingOnline: number
}

riskManagement: {
speakerTopics: string
speakers: string
speakerSites: string
specialCircumstances: string
risks: string
cleanUpCrew: string
additionalRemarks: string
}
}
37 changes: 37 additions & 0 deletions tools/risk-form-filler/src/defs/in-person-input-defs.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
export interface ScheduleInPersonParams {
primaryOrganizer: {
firstName: string
lastName: string
studentID: number
email: string
phone: string
}

secondaryOrganizer: {
firstName: string
lastName: string
studentID: number
email: string
phone: string
}

eventDetails: {
title: string
date: string // Format: 'YYYY/MM/DD'
startTime: string // Format: 'HH:MM AM/PM'
endTime: string // Format: 'HH:MM AM/PM'
description: string
location: string
expectedAttendees: string
}

riskManagement: {
speakerTopics: string
speakers: string
speakerSites: string
specialCircumstances: string
risks: string
cleanUpCrew: string
additionalRemarks: string
}
}
41 changes: 41 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,41 @@
export interface ScheduleOnlineParams {
primaryOrganizer: {
firstName: string
lastName: string
studentID: number
email: string
phone: string
}

secondaryOrganizer: {
firstName: string
lastName: string
studentID: number
email: string
phone: string
}

eventDetails: {
title: string
date: string // Format: 'YYYY/MM/DD'
startTime: string // Format: 'HH:MM AM/PM'
endTime: string // Format: 'HH:MM AM/PM'
description: string
expectedAttendees: number
}

onlineInformation: {
platform: string
topics: string
location: string
numberOfOrganizers: number
organizersAttendingOnline: number
}

speakerAndResources: {
topics: string
speakers: string
speakerSites: string
additionalRemarks: string
}
}
37 changes: 37 additions & 0 deletions tools/risk-form-filler/src/hybrid.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
import type { ScheduleHybridParams } from './input/schedule-hybrid-params'

import type { HybridFormLayout } from './pom'

export async function scheduleHybrid(params: ScheduleHybridParams, formLayout: HybridFormLayout) {
await formLayout.goto()
await formLayout.hybridButton.click()

await formLayout.fillContacts(formLayout, params.primaryOrganizer.firstName, params.primaryOrganizer.lastName, params.primaryOrganizer.studentID.toString(), params.primaryOrganizer.email, params.primaryOrganizer.phone, params.secondaryOrganizer.firstName, params.secondaryOrganizer.lastName, params.secondaryOrganizer.studentID.toString(), params.secondaryOrganizer.email, params.secondaryOrganizer.phone)

await formLayout.eventLocationTextBox.fill(params.eventDetails.location)
await formLayout.eventLocationRadioButton.check()
await formLayout.expectedAttendeesTextBox.fill(params.eventDetails.expectedAttendees.toString())
await formLayout.hybridRegistrationRadioButton.check()
await formLayout.foodRadioButton.check()
await formLayout.healthInsuranceRadioButton.check()
await formLayout.photoIdRadioButton.check()

await formLayout.fillEventDetails(formLayout, params.eventDetails.title, params.eventDetails.date, params.eventDetails.startTime, params.eventDetails.endTime, params.eventDetails.description, params.eventDetails.expectedAttendees.toString())
await formLayout.fillOnlineInformation(formLayout, params.onlineInformation.platform, params.onlineInformation.topics, params.onlineInformation.location, params.onlineInformation.numberOfOrganizers.toString(), params.onlineInformation.organizersAttendingOnline.toString())

await formLayout.alcoholRadioButton.check()

await formLayout.fillRiskManagement(formLayout, params.riskManagement.speakerTopics, params.riskManagement.speakers, params.riskManagement.speakerSites)
await formLayout.fillEmergencyResponse(formLayout, params.riskManagement.specialCircumstances, params.riskManagement.risks)

await formLayout.transportationRadioButton.check()
await formLayout.outOfProvinceRadioButton.check()
await formLayout.garbageRadioButton.check()
await formLayout.cleanupRadioButton.check()
await formLayout.cleanupTextBox.fill(params.riskManagement.cleanUpCrew)
await formLayout.overnightRadioButton.check()

await formLayout.fillLogistics(formLayout)

await formLayout.rightsTextBox.fill(params.riskManagement.additionalRemarks)
}
34 changes: 34 additions & 0 deletions tools/risk-form-filler/src/in-person.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import type { ScheduleInPersonParams } from './input/schedule-in-person-params'
import type { InPersonFormLayout } from './pom'

export async function scheduleInPerson(params: ScheduleInPersonParams, formLayout: InPersonFormLayout) {
await formLayout.goto()
await formLayout.inPersonButton.click()

await formLayout.fillContacts(formLayout, params.primaryOrganizer.firstName, params.primaryOrganizer.lastName, params.primaryOrganizer.studentID.toString(), params.primaryOrganizer.email, params.primaryOrganizer.phone, params.secondaryOrganizer.firstName, params.secondaryOrganizer.lastName, params.secondaryOrganizer.studentID.toString(), params.secondaryOrganizer.email, params.secondaryOrganizer.phone)

await formLayout.eventLocationTextBox.fill(params.eventDetails.location)
await formLayout.eventLocationRadioButton.check()
await formLayout.expectedAttendeesTextBox.fill(params.eventDetails.expectedAttendees.toString())
await formLayout.foodRadioButton.check()
await formLayout.healthInsuranceRadioButton.check()
await formLayout.photoIdRadioButton.check()

await formLayout.fillEventDetails(formLayout, params.eventDetails.title, params.eventDetails.date, params.eventDetails.startTime, params.eventDetails.endTime, params.eventDetails.description, params.eventDetails.expectedAttendees.toString())

await formLayout.alcoholRadioButton.check()

await formLayout.fillRiskManagement(formLayout, params.riskManagement.speakerTopics, params.riskManagement.speakers, params.riskManagement.speakerSites)
await formLayout.fillEmergencyResponse(formLayout, params.riskManagement.specialCircumstances, params.riskManagement.risks)

await formLayout.transportationRadioButton.check()
await formLayout.outOfProvinceRadioButton.check()
await formLayout.garbageRadioButton.check()
await formLayout.cleanupRadioButton.check()
await formLayout.cleanupTextBox.fill(params.riskManagement.cleanUpCrew)
await formLayout.overnightRadioButton.check()

await formLayout.fillLogistics(formLayout)

await formLayout.rightsTextBox.fill(params.riskManagement.additionalRemarks)
}
Loading

0 comments on commit 06e2389

Please sign in to comment.