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

Added seed data for settings tests #732

Merged
merged 3 commits into from
Nov 1, 2019
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
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cypress/fixtures/images/profile-cover-1.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added cypress/fixtures/images/profile-cover-2.jpg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 10 additions & 0 deletions cypress/fixtures/seed/auth.json
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,16 @@
"salt": "xIhcGQ/uTEffoA==",
"createdAt": "1570194592093",
"providerUserInfo": []
},
{
"localId": "l9N5HFHzSjQvtP9g9MyFnPpkFmM2",
"displayName": "settings_workplace_new",
"email": "settings_workplace_new@test.com",
"emailVerified": true,
"passwordHash": "C0VFp8QQ68YbdydOYRq/Mlp5HPpfv8XdFB8kVe1WiJHOKYagP1hbMyMSjrrN8F8rseF7F2LhMH74Jq1p88d+ZA==",
"salt": "xIhcGQ/uTEffoA==",
"createdAt": "1570194592093",
"providerUserInfo": []
}
]
}
9 changes: 9 additions & 0 deletions cypress/fixtures/seed/users.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,14 @@
"_created": "2018-01-24T14:46:42.038Z",
"_modified": "2018-01-24T14:46:42.038Z",
"verified": true
},
{
"_authID": "l9N5HFHzSjQvtP9g9MyFnPpkFmM2",
"_id": "settings_workplace_new",
"userName": "settings_workplace_new",
"_deleted": false,
"_created": "2018-01-24T14:46:42.038Z",
"_modified": "2018-01-24T14:46:42.038Z",
"verified": true
}
]
4 changes: 3 additions & 1 deletion cypress/integration/academy.spec.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import { Page } from '../utils/test-utils'

describe('[Academy]', () => {
describe('[List instructions]', () => {
it('[By Everyone]', () => {
cy.visit('/academy')
cy.visit(Page.ACADEMY)
cy.step('Load instructions from another github repo')
const githubDoc = 'https://onearmy.github.io/academy/intro'
cy.get('iframe').should('have.attr', 'src').and('equal', githubDoc)
Expand Down
11 changes: 5 additions & 6 deletions cypress/integration/common.spec.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
import { UserMenuItem } from '../support/commands'

describe('[Common]', () =>{
it('[Default Page]', () => {
cy.step('The home page is /how-to')
Expand Down Expand Up @@ -65,19 +67,16 @@ describe('[Common]', () =>{
cy.get('[data-cy=user-menu-list]').should('not.exist')

cy.step('Go to Profile')
cy.toggleUserMenuOn()
cy.get('[data-cy=menu-item]').contains('Profile').click()
cy.clickMenuItem(UserMenuItem.Profile)
cy.url().should('include', `/u/${username}`)

cy.step('Go to Settings')
cy.toggleUserMenuOn()
cy.get('[data-cy=menu-item]').contains('Settings').click()
cy.clickMenuItem(UserMenuItem.Settings)
cy.url().should('include', 'settings')

cy.step('Logout the session')
cy.step('Logout')
cy.toggleUserMenuOn()
cy.get('[data-cy=menu-item]').contains('Log out').click()
cy.clickMenuItem(UserMenuItem.LogOut)
cy.get('[data-cy=login]').should('be.visible')
cy.get('[data-cy=join]').should('be.visible')
})
Expand Down
57 changes: 57 additions & 0 deletions cypress/integration/settings/focus_workplace.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
import { DbCollectionName, Page } from '../../utils/test-utils'
import { UserMenuItem } from '../../support/commands'

describe('[Settings]', () => {
const freshSettings = {
_authID: 'l9N5HFHzSjQvtP9g9MyFnPpkFmM2',
_id: 'settings_workplace_new',
userName: 'settings_workplace_new',
_deleted: false,
_created: '2018-01-24T14:46:42.038Z',
_modified: '2018-01-24T14:46:42.038Z',
verified: true,
}

describe('[Focus Workplace]', () => {
it('[Editing a new Profile]', () => {
cy.updateDocument(
DbCollectionName.v2_users,
freshSettings.userName,
freshSettings,
)
cy.visit(Page.EVENTS)
cy.login('settings_workplace_new@test.com', 'test1234')
cy.step('Go to User Settings')
cy.clickMenuItem(UserMenuItem.Settings)
cy.get('[data-cy=workspace]').click()
cy.get('[data-cy=shredder]').click()

cy.step('Update Info section')
cy.get('[data-cy=username').clear().type(freshSettings.userName)
cy.get('[data-cy=country]').find('.flag-select').click()
cy.get('[data-cy=country]').find(':text').type('United')
cy.get('[data-cy=country]').contains('United States').click()
cy.get('[data-cy=info-description').clear().type('We have some space to run a workplace')
cy.get('[data-cy=cover-images]').get(':file').uploadFiles([
'images/profile-cover-1.jpg',
'images/profile-cover-2.jpg',
])

cy.step('Update Contact Links')
cy.get('[data-cy=select-link-0]').click()
cy.get('[data-cy=select-link-0]').contains('email').click()
cy.get('[data-cy=input-link-0]').type(`${freshSettings.userName}@test.com`)
cy.get('[data-cy=add-link]').click()
cy.get('[data-cy=select-link-1]').click()
cy.get('[data-cy=select-link-1]').contains('website').click()
cy.get('[data-cy=input-link-1]').type(`www.${freshSettings.userName}.com`)

cy.step('Update Map section')
cy.get('[data-cy=pin-description]').type(`Come in & let's make cool stuff out of plastic!`)
cy.get('[data-cy=location]').find(':text').type('ohio')
cy.get('[data-cy=location]').contains('Columbus').click()

cy.get('[data-cy=save]').click()
})
})
})
69 changes: 57 additions & 12 deletions cypress/support/commands.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ const fbConfig = {
projectId: 'onearmy-test-ci',
storageBucket: 'onearmy-test-ci.appspot.com',
}

export enum UserMenuItem {
Profile = 'Profile',
Settings = 'Settings',
LogOut = 'Log out',
}
firebase.initializeApp(fbConfig)
/**
* Clear all caches before any test is executed
Expand Down Expand Up @@ -41,9 +47,9 @@ declare global {
* @param username
* @param password
*/
completeLogin(username: string, password: string): Promise<void>
completeLogin(username: string, password: string): Chainable<void>

logout(): Promise<void>
logout(): Chainable<void>

deleteDocuments(
collectionName: string,
Expand All @@ -52,6 +58,12 @@ declare global {
value: string,
): Promise<void>

updateDocument(
collectionName: string,
docId: string,
docData: any,
): Promise<void>

queryDocuments(
collectionName: string,
fieldPath: string,
Expand All @@ -63,13 +75,15 @@ declare global {

uploadFiles(filePath: string | string[])

toggleUserMenuOn() : Promise<void>
toggleUserMenuOff() : Promise<void>
toggleUserMenuOn(): Chainable<void>
toggleUserMenuOff(): Chainable<void>

/**
* Trigger form validation
*/
screenClick() : Promise<void>
screenClick(): Chainable<void>

clickMenuItem(menuItem: UserMenuItem): Chainable<void>
}
}
}
Expand All @@ -78,7 +92,6 @@ const attachCustomCommands = (Cypress, fb: typeof firebase) => {
let currentUser: null | firebase.User = null
const firestore = new Firestore(fb.firestore())


fb.auth().onAuthStateChanged(user => {
currentUser = user
})
Expand All @@ -101,7 +114,11 @@ const attachCustomCommands = (Cypress, fb: typeof firebase) => {
},
})
fb.auth().signInWithEmailAndPassword(email, password)
const isPageLoadedAfterLogin = () => cy.get('[data-cy=user-menu]').find('path').should('be.exist')
const isPageLoadedAfterLogin = () =>
cy
.get('[data-cy=user-menu]')
.find('path')
.should('be.exist')
isPageLoadedAfterLogin()
})

Expand Down Expand Up @@ -142,6 +159,20 @@ const attachCustomCommands = (Cypress, fb: typeof firebase) => {
},
)

Cypress.Commands.add(
'updateDocument',
(collectionName: string, docId: string, docData: any) => {
Cypress.log({
displayName: 'updateDocument',
consoleProps: () => {
return { collectionName, docId, docData }
},
})

return firestore.updateDocument(collectionName, docId, docData)
},
)

Cypress.Commands.add('step', (message: string) => {
Cypress.log({
displayName: 'step',
Expand Down Expand Up @@ -188,19 +219,33 @@ const attachCustomCommands = (Cypress, fb: typeof firebase) => {
)

Cypress.Commands.add('toggleUserMenuOn', () => {
Cypress.log({ displayName: 'OPEN_USER_MENU'})
cy.get('[data-cy=user-menu]').find('path').should('be.exist')
Cypress.log({ displayName: 'OPEN_USER_MENU' })
cy.get('[data-cy=user-menu]')
.find('path')
.should('be.exist')
cy.get('[data-cy=user-menu]').click()
})

Cypress.Commands.add('toggleUserMenuOff', () => {
Cypress.log({ displayName: 'CLOSE_USER_MENU'})
cy.get('[data-cy=header]').click({force: true})
Cypress.log({ displayName: 'CLOSE_USER_MENU' })
cy.get('[data-cy=header]').click({ force: true })
})

Cypress.Commands.add('clickMenuItem', (menuItem: UserMenuItem) => {
Cypress.log({
displayName: 'CLICK_MENU_ITEM',
consoleProps: () => {
return { menuItem }
},
})
cy.toggleUserMenuOn()
cy.get('[data-cy=menu-item]').contains(menuItem).click()
})

Cypress.Commands.add('screenClick', () => {
cy.get('[data-cy=header]').click({ force: true})
cy.get('[data-cy=header]').click({ force: true })
})

}

attachCustomCommands(Cypress, firebase)
44 changes: 25 additions & 19 deletions cypress/support/firestore.ts
Original file line number Diff line number Diff line change
@@ -1,15 +1,17 @@
import * as firebase from 'firebase'
import Query = firebase.firestore.Query
import doc = Mocha.reporters.doc

type PromiseCallback = (val?: any) => void

export class Firestore {
static MAX_BATCH_SIZE = 500;
db: firebase.firestore.Firestore;
static MAX_BATCH_SIZE = 500
db: firebase.firestore.Firestore

constructor(firestore: firebase.firestore.Firestore) {
this.db = firestore
}

queryDocuments = (collectionName: string, fieldPath: string, opStr: any, value: string): Promise<any> | Promise<any[]> => {
return this.db.collection(collectionName).where(fieldPath, opStr, value).get()
.then(snapshot => {
Expand All @@ -22,43 +24,47 @@ export class Firestore {
return result[0]
}
return result
}
},
)
};
}

deleteDocuments = (collectionName: string, fieldPath: string, opStr: any, value: string) => {
const query = this.db.collection(collectionName).where(fieldPath, opStr, value).limit(Firestore.MAX_BATCH_SIZE);
const query = this.db.collection(collectionName).where(fieldPath, opStr, value).limit(Firestore.MAX_BATCH_SIZE)
return new Promise((resolve, reject) => {
this.deleteQueryBatch(query, Firestore.MAX_BATCH_SIZE, resolve, reject);
});
};
this.deleteQueryBatch(query, Firestore.MAX_BATCH_SIZE, resolve, reject)
})
}
deleteQueryBatch = (query: Query, batchSize: number, resolve: PromiseCallback, reject: PromiseCallback) => {
query.get()
.then((snapshot) => {
// When there are no documents left, we are done
if (snapshot.size === 0) {
return 0;
return 0
}

// Delete documents in a batch
const batch = this.db.batch();
const batch = this.db.batch()
snapshot.docs.forEach((doc) => {
batch.delete(doc.ref);
});
batch.delete(doc.ref)
})

return batch.commit().then(() => {
return snapshot.size;
});
return snapshot.size
})
}).then((numDeleted) => {
if (numDeleted === 0) {
resolve();
return;
resolve()
return
}

process.nextTick(() => {
this.deleteQueryBatch(query, batchSize, resolve, reject);
});
this.deleteQueryBatch(query, batchSize, resolve, reject)
})
})
.catch(reject);
.catch(reject)
}

updateDocument = (collectionName: string, docId: string, docData: any) => {
return this.db.collection(collectionName).doc(docId).set(docData)
}
}
24 changes: 16 additions & 8 deletions cypress/utils/test-utils.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,21 @@
export enum Page {
HOME_PAGE = '/how-to'
HOME_PAGE = '/how-to',
ACADEMY = '/academy',
EVENTS = '/events',
SETTINGS = '/settings',
}

export const generatedId = (length: number) => {
let result = '';
const characters = 'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789';
const charactersLength = characters.length;
for ( let i = 0; i < length; i++ ) {
result += characters.charAt(Math.floor(Math.random() * charactersLength));
let result = ''
const characters =
'ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789'
const charactersLength = characters.length
for (let i = 0; i < length; i++) {
result += characters.charAt(Math.floor(Math.random() * charactersLength))
}
return result;
}
return result
}

export enum DbCollectionName {
v2_users = 'v2_users',
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -128,11 +128,11 @@
"prod:copy": "cp .env .env-default && cp ./.env-prod ./.env",
"prod:restore": "cp .env-default .env && rm .env-default",
"start:ci": "cross-env SITE_VARIANT=test-ci PORT=3456 npm run start",
"cy:run": "cross-env TZ='Europe/London' cypress run --browser electron",
"cy:open": "cross-env TZ='Europe/London' npx cypress open --browser electron",
"cy:test": "start-test start:ci 3456 cy:run",
"cy:test:record": "start-test start:ci 3456 cy:run:record",
"cy:run": "cross-env TZ='Europe/London' cypress run",
"cy:run:record": "npm run cy:run --record --key 62585f33-d688-47b7-acb3-6d1dca832065",
"cy:open": "cross-env TZ='Europe/London' npx cypress open",
"cy:run:debug": "DEBUG=cypress:* cy:run"
},
"eslintConfig": {},
Expand Down
Loading