Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(e2e): add storage mode e2e tests #5926

Merged
merged 4 commits into from
Mar 16, 2023
Merged
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
1 change: 1 addition & 0 deletions .github/workflows/playwright.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ jobs:
- name: Build
env:
NODE_OPTIONS: '--max-old-space-size=4096 --openssl-legacy-provider'
REACT_APP_FORMSG_SDK_MODE: 'test'
run: npm run build
- name: Run Playwright tests
run: npx playwright test
Expand Down
8 changes: 4 additions & 4 deletions __tests__/e2e/constants/field.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,15 +166,15 @@ export const ALL_FIELDS: E2eFieldMetadata[] = [
{
title: 'Birthday',
fieldType: BasicField.Date,
val: format(new Date(), DATE_INPUT_FORMAT),
val: format(new Date(952970366), DATE_INPUT_FORMAT),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this date value 952970366 special?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

image

:)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ok no but on a serious note, I couldn't leave it as the current date because our Storage mode's individual response page also displays the date of submission which would also be the current date. So the expect() for finding the response to this question would certainly always succeed, regardless of whether the response to the question was shown.

dateValidation: {
customMinDate: null,
customMaxDate: null,
selectedDateValidation: null,
},
},
{
title: 'Pi',
title: 'What is the value of pi?',
fieldType: BasicField.Decimal,
ValidationOptions: {
customMin: null,
Expand Down Expand Up @@ -211,7 +211,7 @@ export const ALL_FIELDS: E2eFieldMetadata[] = [
fieldType: BasicField.HomeNo,
val: '61234567',
},
// Hide for now, because it doesn't work unless we spin up localstack.
// TODO: Images don't work unless we spin up localstack.
// {
// title: 'Image',
// fieldType: BasicField.Image,
Expand Down Expand Up @@ -271,7 +271,7 @@ export const ALL_FIELDS: E2eFieldMetadata[] = [
fieldType: BasicField.Section,
},
{
title: 'Name',
title: 'Your name',
fieldType: BasicField.ShortText,
ValidationOptions: {
selectedValidation: null,
Expand Down
19 changes: 19 additions & 0 deletions __tests__/e2e/constants/form.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { FormResponseMode } from 'shared/types'

import { E2eFieldMetadata } from './field'
import { E2eLogic } from './logic'
import { E2eSettingsOptions } from './settings'
Expand All @@ -7,3 +9,20 @@ export type E2eForm = {
formLogics: E2eLogic[]
formSettings: E2eSettingsOptions
}

interface E2eFormResponseModeBase {
responseMode: FormResponseMode
}

interface E2eFormResponseModeEmail extends E2eFormResponseModeBase {
responseMode: FormResponseMode.Email
}

interface E2eFormResponseModeEncrypt extends E2eFormResponseModeBase {
responseMode: FormResponseMode.Encrypt
secretKey: string
}

export type E2eFormResponseMode =
| E2eFormResponseModeEmail
| E2eFormResponseModeEncrypt
2 changes: 2 additions & 0 deletions __tests__/e2e/constants/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,5 +2,7 @@ export * from './field'
export * from './form'
export * from './links'
export * from './logic'
export * from './response'
export * from './settings'
export * from './tests'
export * from './user'
17 changes: 16 additions & 1 deletion __tests__/e2e/constants/links.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,21 @@
export const ROOT_PAGE = `${process.env.APP_URL}`

export const LOGIN_PAGE = `${ROOT_PAGE}/login`

export const DASHBOARD_PAGE = `${ROOT_PAGE}/dashboard`

export const ADMIN_FORM_PAGE_PREFIX = `${ROOT_PAGE}/admin/form`
export const PUBLIC_FORM_PAGE_PREFIX = ROOT_PAGE
export const ADMIN_FORM_PAGE_CREATE = (formId: string) =>
`${ADMIN_FORM_PAGE_PREFIX}/${formId}`
export const ADMIN_FORM_PAGE_SETTINGS = (formId: string) =>
`${ADMIN_FORM_PAGE_CREATE(formId)}/settings`
export const ADMIN_FORM_PAGE_RESPONSES = (formId: string) =>
`${ADMIN_FORM_PAGE_CREATE(formId)}/results`
export const ADMIN_FORM_PAGE_RESPONSES_INDIVIDUAL = (
formId: string,
responseId: string,
) => `${ADMIN_FORM_PAGE_CREATE(formId)}/results/${responseId}`

const PUBLIC_FORM_PAGE_PREFIX = ROOT_PAGE
export const PUBLIC_FORM_PAGE = (formId: string) =>
`${PUBLIC_FORM_PAGE_PREFIX}/${formId}`
16 changes: 16 additions & 0 deletions __tests__/e2e/constants/response.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
import { FormResponseMode } from 'shared/types'

interface FormResponseViewBase {
mode: FormResponseMode
}

interface FormResponseViewEmail extends FormResponseViewBase {
mode: FormResponseMode.Email
}

interface FormResponseViewEncrypt extends FormResponseViewBase {
mode: FormResponseMode.Encrypt
csv: boolean
}

export type FormResponseView = FormResponseViewEmail | FormResponseViewEncrypt
152 changes: 152 additions & 0 deletions __tests__/e2e/constants/tests.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,152 @@
import { BasicField, LogicConditionState, LogicType } from 'shared/types'

import { ALL_FIELDS, E2eFieldMetadata } from './field'
import { E2eLogic } from './logic'

type E2eTestFormDefinition = {
formFields: E2eFieldMetadata[]
formLogics: E2eLogic[]
}

/**
* Test where all fields are shown based on a single field logic
*/
const TEST_ALL_FIELDS_SHOWN_BY_LOGIC_FORMFIELDS: E2eFieldMetadata[] = [
{
title: 'Do you want to hide the fields?',
fieldType: BasicField.YesNo,
val: 'No',
},
// TODO: Attachment fields don't work on storage mode unless we spin up localstack.
...ALL_FIELDS.filter((field) => field.fieldType !== BasicField.Attachment),
]
export const TEST_ALL_FIELDS_SHOWN_BY_LOGIC: E2eTestFormDefinition = {
formFields: TEST_ALL_FIELDS_SHOWN_BY_LOGIC_FORMFIELDS,
formLogics: [
// Single logic block: if "yes", show the fields.
{
conditions: [
{
field: 0,
state: LogicConditionState.Equal,
value: 'No',
},
],
logicType: LogicType.ShowFields,
show: Array.from(
TEST_ALL_FIELDS_SHOWN_BY_LOGIC_FORMFIELDS,
(_, i) => i,
).slice(1),
},
],
}

/**
* Test where a field is hidden based on a single field logic
*/
const TEST_FIELD_HIDDEN_BY_LOGIC_FORMFIELDS: E2eFieldMetadata[] = [
{
title: 'Do you want to show the fields?',
fieldType: BasicField.YesNo,
val: 'No',
},
{
title: 'This field should be hidden',
fieldType: BasicField.ShortText,
ValidationOptions: {
selectedValidation: null,
customVal: null,
},
val: '',
hidden: true,
},
]
export const TEST_FIELD_HIDDEN_BY_LOGIC: E2eTestFormDefinition = {
formFields: TEST_FIELD_HIDDEN_BY_LOGIC_FORMFIELDS,
formLogics: [
// Single logic block: if "yes", show the fields.
{
conditions: [
{
field: 0,
state: LogicConditionState.Equal,
value: 'Yes',
},
],
logicType: LogicType.ShowFields,
show: Array.from(
TEST_FIELD_HIDDEN_BY_LOGIC_FORMFIELDS,
(_, i) => i,
).slice(1),
},
],
}

/**
* Test where submission is disabled via chained logic
*/
const TEST_SUBMISSION_DISABLED_BY_CHAINED_LOGIC_MESSAGE = 'You shall not pass!'
const TEST_SUBMISSION_DISABLED_BY_CHAINED_LOGIC_FORMFIELDS: E2eFieldMetadata[] =
[
{
title: 'Enter a number at least 10',
fieldType: BasicField.Number,
ValidationOptions: {
selectedValidation: null,
customVal: null,
},
val: '10',
},
{
title: 'Favorite food',
fieldType: BasicField.Dropdown,
fieldOptions: ['Rice', 'Chocolate', 'Ice-Cream'],
val: 'Chocolate',
},
{
title: 'Do you want to submit this form?',
fieldType: BasicField.YesNo,
val: 'Yes',
},
]
export const TEST_SUBMISSION_DISABLED_BY_CHAINED_LOGIC: E2eTestFormDefinition & {
preventSubmitMessage: string
} = {
formFields: TEST_SUBMISSION_DISABLED_BY_CHAINED_LOGIC_FORMFIELDS,
formLogics: [
{
conditions: [
{
field: 0,
state: LogicConditionState.Gte,
value: '10',
},
],
logicType: LogicType.ShowFields,
show: [1],
},
{
conditions: [
{
field: 1,
state: LogicConditionState.Either,
value: ['Rice', 'Chocolate'],
},
],
logicType: LogicType.ShowFields,
show: [2],
},
{
conditions: [
{
field: 2,
state: LogicConditionState.Equal,
value: 'Yes',
},
],
logicType: LogicType.PreventSubmit,
message: TEST_SUBMISSION_DISABLED_BY_CHAINED_LOGIC_MESSAGE,
},
],
preventSubmitMessage: TEST_SUBMISSION_DISABLED_BY_CHAINED_LOGIC_MESSAGE,
}
Loading