chore: start settings tests having isolated users

This commit is contained in:
Ben Furber
2024-06-28 11:03:15 +01:00
committed by benfurber
parent 39b14ee2bb
commit 7856acb26f
2 changed files with 56 additions and 76 deletions

View File

@@ -121,53 +121,10 @@ export const expectedMember = {
}, },
} }
export const expectedMachineBuilder = {
_authID: 'wwtBAo7TrkSQ9nAaBN3D93I1sCM2',
_deleted: false,
_id: 'settings_machine_new',
about: "We're mechanics and our jobs are making machines",
profileType: 'machine-builder',
userName: 'settings_machine_new',
verified: true,
coverImages: [
{
contentType: 'image/png',
fullPath:
'uploads/v3_users/settings_machine_new/images/profile-cover-2.png',
name: 'profile-cover-2.png',
size: 30658,
type: 'image/png',
},
],
links: [
{
label: ExternalLinkLabel.BAZAR,
url: 'http://settings_machine_bazarlink.com',
},
],
location: {
administrative: '',
country: 'Singapore',
countryCode: 'sg',
latlng: { lng: '103.8194992', lat: '1.357107' },
name: 'Drongo Trail, Bishan, Central, Singapore, 578774, Singapore',
postcode: '578774',
value: 'Singapore',
},
mapPinDescription: 'Informative workshop on machines every week',
machineBuilderXp: ['electronics', 'welding'],
isContableByPublic: false,
}
export const expectedCommunityBuilder = { export const expectedCommunityBuilder = {
_authID: 'vWAbQvq21UbvhGldakIy1x4FpeF2',
_deleted: false,
_id: 'settings_community_new',
about: 'An enthusiastic community that makes the world greener!', about: 'An enthusiastic community that makes the world greener!',
mapPinDescription: 'Fun, vibrant and full of amazing people', mapPinDescription: 'Fun, vibrant and full of amazing people',
profileType: 'community-builder', profileType: 'community-builder',
userName: 'settings_community_new',
verified: true,
coverImages: [ coverImages: [
{ {
contentType: 'image/jpeg', contentType: 'image/jpeg',
@@ -180,7 +137,7 @@ export const expectedCommunityBuilder = {
], ],
links: [ links: [
{ {
label: 'forum', label: 'website',
url: 'http://www.settings_community_new-forum.org', url: 'http://www.settings_community_new-forum.org',
}, },
], ],

View File

@@ -4,7 +4,11 @@ import { form } from '../../../../src/pages/UserSettings/labels'
import { SingaporeStubResponse } from '../fixtures/searchResults' import { SingaporeStubResponse } from '../fixtures/searchResults'
import * as settingsData from '../fixtures/settings' import * as settingsData from '../fixtures/settings'
import { UserMenuItem } from '../support/commandsUi' import { UserMenuItem } from '../support/commandsUi'
import { DbCollectionName, setIsPreciousPlastic } from '../utils/TestUtils' import {
DbCollectionName,
generateNewUserDetails,
setIsPreciousPlastic,
} from '../utils/TestUtils'
import type { IUser } from '../../../../src/models/user.models' import type { IUser } from '../../../../src/models/user.models'
@@ -22,6 +26,16 @@ interface IMapPin {
} }
type ILink = IUser['links'][0] & { index: number } type ILink = IUser['links'][0] & { index: number }
const locationStub = {
administrative: '',
country: 'Singapore',
countryCode: 'sg',
latlng: { lng: '103.8194992', lat: '1.357107' },
name: 'Drongo Trail, Bishan, Central, Singapore, 578774, Singapore',
postcode: '578774',
value: 'Singapore',
}
describe('[Settings]', () => { describe('[Settings]', () => {
beforeEach(() => { beforeEach(() => {
cy.interceptAddressSearchFetch(SingaporeStubResponse) cy.interceptAddressSearchFetch(SingaporeStubResponse)
@@ -250,13 +264,20 @@ describe('[Settings]', () => {
}) })
describe('[Focus Machine Builder]', () => { describe('[Focus Machine Builder]', () => {
const expected = settingsData.expectedMachineBuilder
it('[Edit a new profile]', () => { it('[Edit a new profile]', () => {
cy.login('settings_machine_new@test.com', 'test1234') const user = generateNewUserDetails()
const bazarUrl = 'http://settings_machine_bazarlink.com'
const coverImage = 'images/profile-cover-2.png'
const description = "We're mechanics and our jobs are making machines"
const machineBuilderXp = ['electronics', 'welding']
const mapPinDescription = 'Informative workshop on machines every week'
const profileType = 'machine-builder'
cy.signUpNewUser(user)
cy.step('Go to User Settings') cy.step('Go to User Settings')
cy.visit('/settings') cy.visit('/settings')
selectFocus(expected.profileType) selectFocus(profileType)
cy.step("Can't save without required fields being populated") cy.step("Can't save without required fields being populated")
cy.get('[data-cy=save]').click() cy.get('[data-cy=save]').click()
@@ -264,26 +285,26 @@ describe('[Settings]', () => {
cy.step('Populate profile') cy.step('Populate profile')
setInfo({ setInfo({
username: expected.userName, username: user.username,
description: expected.about, description,
coverImage: 'images/profile-cover-2.png', coverImage,
}) })
cy.step('Choose Expertise') cy.step('Choose Expertise')
cy.get('[data-cy=electronics]').click() cy.get(`[data-cy=${machineBuilderXp[0]}]`).click()
cy.get('[data-cy=welding]').click() cy.get(`[data-cy=${machineBuilderXp[1]}]`).click()
cy.step('Update Contact Links') cy.step('Update Contact Links')
addContactLink({ addContactLink({
index: 0, index: 0,
label: ExternalLinkLabel.BAZAR, label: ExternalLinkLabel.BAZAR,
url: `http://settings_machine_bazarlink.com`, url: bazarUrl,
}) })
setWorkspaceMapPin({ setWorkspaceMapPin({
description: expected.mapPinDescription, description: mapPinDescription,
searchKeyword: 'singapo', searchKeyword: 'singapo',
locationName: expected.location.value, locationName: locationStub.value,
}) })
cy.step('Opts out of public contact') cy.step('Opts out of public contact')
@@ -294,32 +315,26 @@ describe('[Settings]', () => {
cy.get('[data-cy=errors-container]').should('not.exist') cy.get('[data-cy=errors-container]').should('not.exist')
cy.get('[data-cy=save]').should('not.be.disabled') cy.get('[data-cy=save]').should('not.be.disabled')
cy.queryDocuments( cy.visit(`u/${user.username}`)
DbCollectionName.users, cy.contains(user.username)
'userName', cy.contains(description)
'==', // To-do: Finish adding the expectations of the settings set in this test
expected.userName,
).then((docs) => {
cy.log('queryDocs', docs)
expect(docs.length).to.equal(1)
cy.wrap(null)
.then(() => docs[0])
.should('eqSettings', expected)
})
}) })
}) })
describe('[Focus Community Builder]', () => { describe('[Focus Community Builder]', () => {
const expected = settingsData.expectedCommunityBuilder const expected = settingsData.expectedCommunityBuilder
it('[Edit a new profile]', () => { it.only('[Edit a new profile]', () => {
cy.login('settings_community_new@test.com', 'test1234') const user = generateNewUserDetails()
cy.signUpNewUser(user)
cy.step('Go to User Settings') cy.step('Go to User Settings')
cy.visit('/settings') cy.visit('/settings')
selectFocus(expected.profileType) selectFocus(expected.profileType)
setInfo({ setInfo({
username: expected.userName, username: user.username,
description: expected.about, description: expected.about,
coverImage: 'images/profile-cover-1.jpg', coverImage: 'images/profile-cover-1.jpg',
}) })
@@ -340,18 +355,26 @@ describe('[Settings]', () => {
}) })
cy.get('[data-cy=save]').click() cy.get('[data-cy=save]').click()
cy.get('[data-cy=errors-container]').should('not.exist')
cy.get('[data-cy=save]').should('not.be.disabled') cy.get('[data-cy=save]').should('not.be.disabled')
cy.pause()
cy.queryDocuments( cy.queryDocuments(
DbCollectionName.users, DbCollectionName.users,
'userName', 'userName',
'==', '==',
expected.userName, user.username,
).then((docs) => { ).then((docs) => {
cy.log('queryDocs', docs) cy.log('queryDocs', docs)
expect(docs.length).to.equal(1) expect(docs.length).to.equal(1)
cy.wrap(null) expect(docs[0]).to.containSubset({
.then(() => docs[0]) about: expected.about,
.should('eqSettings', expected) // coverimage
// links
mapPinDescription: expected.mapPinDescription,
location: locationStub,
})
}) })
}) })
}) })