-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
b1d1f3b
commit 2e32017
Showing
4 changed files
with
152 additions
and
245 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -248,9 +248,6 @@ describe('TermsOfService', () => { | |
/I agree to the TOS and privacy policy/i | ||
) | ||
|
||
const customerIntent = screen.getByRole('radio', { name: /Personal use/ }) | ||
await user.click(customerIntent) | ||
|
||
await user.click(selectedTos) | ||
|
||
const submit = await screen.findByRole('button', { name: /Continue/ }) | ||
|
@@ -263,7 +260,7 @@ describe('TermsOfService', () => { | |
businessEmail: '[email protected]', | ||
termsAgreement: true, | ||
marketingConsent: false, | ||
customerIntent: 'PERSONAL', | ||
name: 'Chetney', | ||
}, | ||
}) | ||
) | ||
|
@@ -298,7 +295,7 @@ describe('TermsOfService', () => { | |
'case #1', | ||
{ | ||
validationDescription: | ||
'user has email, signs TOS, submit is now enabled', | ||
'user has email and name, signs TOS, submit is now enabled', | ||
internalUserData: { | ||
email: '[email protected]', | ||
termsAgreement: false, | ||
|
@@ -309,15 +306,15 @@ describe('TermsOfService', () => { | |
}, | ||
[expectPageIsReady], | ||
[expectSubmitIsDisabled], | ||
[expectPrepopulatedFields, { email: '[email protected]', name: 'Chetney' }], | ||
[expectUserSignsTOS], | ||
[expectUserToChooseCustomerIntent], | ||
[expectSubmitIsEnabled], | ||
], | ||
[ | ||
'case #2', | ||
{ | ||
validationDescription: | ||
'user wants to receive emails, signs TOS, submit is now enabled', | ||
'user has email and name, user wants to receive emails, signs TOS, submit is now enabled', | ||
internalUserData: { | ||
email: '[email protected]', | ||
termsAgreement: false, | ||
|
@@ -327,38 +324,18 @@ describe('TermsOfService', () => { | |
}, | ||
}, | ||
[expectPageIsReady], | ||
[expectUserSelectsMarketingWithFoundEmail, { email: '[email protected]' }], | ||
[expectPrepopulatedFields, { email: '[email protected]', name: 'Chetney' }], | ||
[expectSubmitIsDisabled], | ||
[expectUserToChooseCustomerIntent], | ||
[expectUserSignsTOS], | ||
[expectSubmitIsEnabled], | ||
], | ||
[ | ||
'case #3', | ||
{ | ||
validationDescription: | ||
'user has email, user wants to receive emails, signs TOS, submit is now enabled', | ||
internalUserData: { | ||
email: '[email protected]', | ||
termsAgreement: false, | ||
name: 'Chetney', | ||
externalId: '1234', | ||
owners: null, | ||
}, | ||
}, | ||
[expectPageIsReady], | ||
[expectSubmitIsDisabled], | ||
[expectUserSelectsMarketingWithFoundEmail, { email: '[email protected]' }], | ||
[expectUserSelectsMarketing], | ||
[expectSubmitIsDisabled], | ||
[expectUserSignsTOS], | ||
[expectUserToChooseCustomerIntent], | ||
[expectSubmitIsEnabled], | ||
], | ||
[ | ||
'case #4', | ||
'case #3', | ||
{ | ||
validationDescription: | ||
'signs TOS, decides not to, is warned they must sign and cannot submit', | ||
'has prefilled email and name, signs TOS, decides not to, is warned they must sign and cannot submit', | ||
internalUserData: { | ||
email: '[email protected]', | ||
termsAgreement: false, | ||
|
@@ -369,18 +346,18 @@ describe('TermsOfService', () => { | |
}, | ||
[expectPageIsReady], | ||
[expectSubmitIsDisabled], | ||
[expectUserToChooseCustomerIntent], | ||
[expectPrepopulatedFields, { email: '[email protected]', name: 'Chetney' }], | ||
[expectUserSignsTOS], | ||
[expectSubmitIsEnabled], | ||
[expectUserSignsTOS], | ||
[expectSubmitIsDisabled], | ||
[expectUserIsWarnedTOS], | ||
], | ||
[ | ||
'case #5', | ||
'case #4', | ||
{ | ||
validationDescription: | ||
'user checks marketing consent and is required to provide an email, sign TOS (check email validation messages)', | ||
'user checks marketing consent and is required to provide an email, provide a name, sign TOS (check email validation messages)', | ||
internalUserData: { | ||
termsAgreement: false, | ||
name: 'Chetney', | ||
|
@@ -391,21 +368,20 @@ describe('TermsOfService', () => { | |
}, | ||
[expectPageIsReady], | ||
[expectSubmitIsDisabled], | ||
[expectEmailRequired], | ||
[expectUserTextEntryEmailField, { email: 'chetney' }], | ||
[expectUserIsWarnedForValidEmail], | ||
[expectSubmitIsDisabled], | ||
[expectUserTextEntryEmailField, { email: '@cr.com' }], | ||
[expectUserTextEntryEmailField, { email: '@hello.com' }], | ||
[expectUserIsNotWarnedForValidEmail], | ||
[expectSubmitIsDisabled], | ||
[expectUserTextEntryNameField], | ||
[expectUserSelectsMarketing], | ||
[expectSubmitIsDisabled], | ||
[expectUserToChooseCustomerIntent], | ||
[expectUserSignsTOS], | ||
[expectSubmitIsEnabled], | ||
], | ||
[ | ||
'case #6', | ||
'case #5', | ||
{ | ||
validationDescription: | ||
'user checks marketing consent and does not provide an email, sign TOS (check email validation messages)', | ||
|
@@ -418,29 +394,28 @@ describe('TermsOfService', () => { | |
}, | ||
}, | ||
[expectPageIsReady], | ||
[expectEmailRequired], | ||
[expectSubmitIsDisabled], | ||
[expectUserSignsTOS], | ||
[expectSubmitIsDisabled], | ||
[expectUserToChooseCustomerIntent], | ||
], | ||
[ | ||
'case #7', | ||
'case #6', | ||
{ | ||
validationDescription: 'server unknown error notification', | ||
isUnknownError: true, | ||
internalUserData: { | ||
termsAgreement: false, | ||
email: '[email protected]', | ||
name: 'Chetney', | ||
email: '', | ||
name: '', | ||
externalId: '1234', | ||
owners: null, | ||
}, | ||
}, | ||
[expectPageIsReady], | ||
[expectUserTextEntryEmailField, { email: '[email protected]' }], | ||
[expectUserTextEntryNameField], | ||
[expectUserSignsTOS], | ||
[expectClickSubmit], | ||
[expectUserToChooseCustomerIntent], | ||
[ | ||
expectRendersServerFailureResult, | ||
{ | ||
|
@@ -456,22 +431,23 @@ describe('TermsOfService', () => { | |
], | ||
], | ||
[ | ||
'case #8', | ||
'case #7', | ||
{ | ||
validationDescription: 'server failure error notification', | ||
isUnAuthError: true, | ||
internalUserData: { | ||
termsAgreement: false, | ||
email: '[email protected]', | ||
name: 'Chetney', | ||
email: '', | ||
name: '', | ||
externalId: '1234', | ||
owners: null, | ||
}, | ||
}, | ||
[expectPageIsReady], | ||
[expectUserTextEntryEmailField, { email: '[email protected]' }], | ||
[expectUserTextEntryNameField], | ||
[expectUserSignsTOS], | ||
[expectClickSubmit], | ||
[expectUserToChooseCustomerIntent], | ||
[ | ||
expectRendersServerFailureResult, | ||
{ | ||
|
@@ -481,27 +457,28 @@ describe('TermsOfService', () => { | |
], | ||
], | ||
[ | ||
'case #9', | ||
'case #8', | ||
{ | ||
validationDescription: | ||
'server validation error notification (saveTerms)', | ||
isValidationError: true, | ||
internalUserData: { | ||
termsAgreement: false, | ||
email: '[email protected]', | ||
name: 'Chetney', | ||
email: '', | ||
name: '', | ||
externalId: '1234', | ||
owners: null, | ||
}, | ||
}, | ||
[expectPageIsReady], | ||
[expectUserTextEntryEmailField, { email: '[email protected]' }], | ||
[expectUserTextEntryNameField], | ||
[expectUserSignsTOS], | ||
[expectClickSubmit], | ||
[expectUserToChooseCustomerIntent], | ||
[expectRendersServerFailureResult, 'validation error'], | ||
], | ||
[ | ||
'case #10', | ||
'case #9', | ||
{ | ||
validationDescription: | ||
'redirects to main root if user has already synced a provider', | ||
|
@@ -526,33 +503,6 @@ describe('TermsOfService', () => { | |
}, | ||
[expectRedirectTo, '/gh/codecov/cool-repo'], | ||
], | ||
[ | ||
'case #11', | ||
{ | ||
validationDescription: 'provide no customer intent, does not submit', | ||
internalUserData: { | ||
termsAgreement: true, | ||
name: 'Chetney', | ||
externalId: '1234', | ||
email: '', | ||
owners: [ | ||
{ | ||
avatarUrl: 'http://roland.com/avatar-url', | ||
integrationId: null, | ||
name: null, | ||
ownerid: 2, | ||
stats: null, | ||
service: 'github', | ||
username: 'roland', | ||
}, | ||
], | ||
}, | ||
}, | ||
[expectPageIsReady], | ||
[expectSubmitIsDisabled], | ||
[expectUserSignsTOS], | ||
[expectSubmitIsDisabled], | ||
], | ||
])( | ||
'form validation, %s', | ||
( | ||
|
@@ -693,33 +643,43 @@ async function expectPageIsReady() { | |
expect(welcome).toBeInTheDocument() | ||
} | ||
|
||
async function expectUserToChooseCustomerIntent(user: UserEvent) { | ||
const customerIntent = screen.getByRole('radio', { name: /Personal use/ }) | ||
|
||
await user.click(customerIntent) | ||
async function expectPrepopulatedFields( | ||
user: UserEvent, | ||
args: { email: string; name: string } | ||
) { | ||
await waitFor(() => { | ||
const emailInput = screen.getByLabelText( | ||
/Enter your email/i | ||
) as HTMLInputElement | ||
expect(emailInput).toHaveValue(args.email) | ||
}) | ||
await waitFor(() => { | ||
const nameInput = screen.getByLabelText( | ||
/Enter your name/i | ||
) as HTMLInputElement | ||
expect(nameInput).toHaveValue(args.name) | ||
}) | ||
} | ||
|
||
async function expectUserSignsTOS(user: UserEvent) { | ||
const selectedTos = screen.getByLabelText( | ||
/I agree to the TOS and privacy policy/i | ||
) | ||
|
||
await user.click(selectedTos) | ||
async function expectUserTextEntryNameField(user: UserEvent) { | ||
const nameInput = screen.getByLabelText(/Enter your name/i) | ||
await user.type(nameInput, 'My name') | ||
} | ||
|
||
async function expectUserSelectsMarketingWithFoundEmail( | ||
async function expectUserTextEntryEmailField( | ||
user: UserEvent, | ||
args: { email: string } | ||
) { | ||
const selectedMarketing = screen.getByLabelText( | ||
/I would like to receive updates via email/i | ||
) | ||
const emailIsInTheLabelOfSelectedMarketing = screen.getByText( | ||
new RegExp(args.email, 'i') | ||
const emailInput = screen.getByLabelText(/Enter your email/i) | ||
await user.type(emailInput, args.email) | ||
} | ||
|
||
async function expectUserSignsTOS(user: UserEvent) { | ||
const selectedTos = screen.getByLabelText( | ||
/I agree to the TOS and privacy policy/i | ||
) | ||
expect(emailIsInTheLabelOfSelectedMarketing).toBeInTheDocument() | ||
|
||
await user.click(selectedMarketing) | ||
await user.click(selectedTos) | ||
} | ||
|
||
async function expectUserSelectsMarketing(user: UserEvent) { | ||
|
@@ -730,15 +690,6 @@ async function expectUserSelectsMarketing(user: UserEvent) { | |
await user.click(selectedMarketing) | ||
} | ||
|
||
async function expectUserTextEntryEmailField( | ||
user: UserEvent, | ||
args: { email: string } | ||
) { | ||
const emailInput = screen.getByLabelText(/Contact email/i) | ||
|
||
await user.type(emailInput, args.email) | ||
} | ||
|
||
async function expectSubmitIsDisabled() { | ||
const submit = screen.getByRole('button', { name: /Continue/ }) | ||
expect(submit).toBeDisabled() | ||
|
@@ -770,17 +721,6 @@ async function expectClickSubmit(user: UserEvent) { | |
await user.click(submit) | ||
} | ||
|
||
async function expectEmailRequired(user: UserEvent) { | ||
const selectedMarketing = screen.getByLabelText( | ||
/I would like to receive updates via email/i | ||
) | ||
|
||
await user.click(selectedMarketing) | ||
|
||
const emailRequired = screen.getByText(/Contact email/i) | ||
expect(emailRequired).toBeInTheDocument() | ||
} | ||
|
||
async function expectRendersServerFailureResult( | ||
user: UserEvent, | ||
expectedError = {} | ||
|
Oops, something went wrong.