Skip to content

Commit

Permalink
refactor(testcafe): Update some function with new selectors
Browse files Browse the repository at this point in the history
chore: Add homedir as a dependancy
  • Loading branch information
CozyKourai committed Feb 8, 2019
1 parent 1e20262 commit 9842701
Show file tree
Hide file tree
Showing 7 changed files with 65 additions and 44 deletions.
6 changes: 5 additions & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ jobs:
env:
- COZY_APP_SLUG=drive
addons:
firefox: latest
apt:
sources:
- google-chrome
packages:
- google-chrome-stable fluxbox
before_install:
- scripts/transifex.sh
- scripts/decrypt.sh
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,7 @@
"fastclick": "1.0.6",
"filesize": "3.6.1",
"hammerjs": "2.0.8",
"homedir": "^0.6.0",
"intersection-observer": "0.5.0",
"justified-layout": "2.1.1",
"kd-tree-javascript": "1.0.3",
Expand Down
33 changes: 18 additions & 15 deletions testcafe/tests/drive_sharing.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,25 @@ test('Drive : from Drive, go in a folder, upload a file, and share it', async t
await drivePage.uploadFiles([`../data/${file}`])
await drivePage.shareFolderPublicLink()

data.sharingLink = await drivePage.copyBtnShareByLink.getAttribute(
'data-test-data'
)
console.log(`SHARING_LINK : ` + data.sharingLink)
const link = await drivePage.copyBtnShareByLink.getAttribute('data-test-url')
if (link) {
data.sharingLink = link
console.log(`SHARING_LINK : ` + data.sharingLink)
}
})

//************************
// Public (no authentification)
//************************
fixture`Drive : Access a folder public link`
.page`${TESTCAFE_DRIVE_URL}/`.beforeEach(async t => {
await t.useRole(Role.anonymous())
})
test('Drive : Access a folder public link', async t => {
fixture`Drive : Access a folder public link`.page`${TESTCAFE_DRIVE_URL}/`
.beforeEach(async t => {
await t.useRole(Role.anonymous())
})
.afterEach(async t => {
await publicDrivePage.checkLocalFile('files.zip')
await publicDrivePage.deleteLocalFile('files.zip')
})
test('Drive : Access a folder public link (desktop)', async t => {
await t.navigateTo(data.sharingLink)
await publicDrivePage.waitForLoading()

Expand All @@ -63,14 +68,14 @@ test('Drive : Access a folder public link', async t => {
.click(publicDrivePage.btnPublicDownload)
.click(publicDrivePage.btnPublicCreateCozy)
await publicDrivePage.checkCreateCozy()
})

//there is some errors if I check for file just after cliking the download button, but not if we do it at the end.
await publicDrivePage.checkDownload('files.zip')

//Mobiles Checks
test('Drive : Access a folder public link (mobile)', async t => {
await t.resizeWindowToFitDevice('iPhone 6', {
portraitOrientation: true
})
await t.navigateTo(data.sharingLink)
await publicDrivePage.waitForLoading()
await publicDrivePage.checkActionMenuPublicMobile()
await t
.setNativeDialogHandler(() => true)
Expand All @@ -79,8 +84,6 @@ test('Drive : Access a folder public link', async t => {
.click(publicDrivePage.btnPublicMobileCreateCozy)
await publicDrivePage.checkCreateCozy()

await publicDrivePage.checkDownload('files (1).zip')

await t.resizeWindow(1280, 1024) //Back to desktop
})

Expand Down
31 changes: 20 additions & 11 deletions testcafe/tests/pages/drive-model-public.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,25 +6,26 @@ import {
goBack,
getResponseStatusCode
} from '../helpers/utils'
import osHomedir from 'os-homedir'

import fs from 'fs'
import homedir from 'homedir'

export default class PublicDrivePage {
constructor() {
//loading
this.content_placeholder = Selector(
this.contentPlaceHolder = Selector(
'[class*="fil-content-file-placeholder"]'
)

//Logo
this.logo = Selector('.coz-nav-apps-btns-home')

//Toolbar - Action Menu
this.toolbar_files_public = getElementWithTestId('fil-toolbar-files-public')
this.btnPublicCreateCozy = this.toolbar_files_public
this.toolbarFilesPublic = getElementWithTestId('fil-toolbar-files-public')
this.btnPublicCreateCozy = this.toolbarFilesPublic
.find('[class*="c-btn"]')
.nth(0)
this.btnPublicDownload = this.toolbar_files_public.find(
this.btnPublicDownload = this.toolbarFilesPublic.find(
'[class*="fil-public-download"]'
)
this.btnPublicMoreMenu = Selector('[class*="fil-toolbar-menu"]').find(
Expand All @@ -47,7 +48,7 @@ export default class PublicDrivePage {

async waitForLoading() {
await t
.expect(this.content_placeholder.exists)
.expect(this.contentPlaceHolder.exists)
.notOk('Content placeholder still displayed')
console.log('Loading Ok')
}
Expand All @@ -65,7 +66,7 @@ export default class PublicDrivePage {
.expect(this.btnPublicMobileDownload.exists)
.notOk('Create my Cozy Button (mobile) exists')
isExistingAndVisibile(this.logo, 'Logo')
isExistingAndVisibile(this.toolbar_files_public, 'toolbar_files')
isExistingAndVisibile(this.toolbarFilesPublic, 'toolbarFiles')
isExistingAndVisibile(this.btnPublicDownload, 'Download FolderButton')
isExistingAndVisibile(this.btnPublicCreateCozy, 'Create my Cozy Button')
}
Expand All @@ -74,7 +75,7 @@ export default class PublicDrivePage {
await t //Desktop element don't exists
.expect(this.logo.exists)
.notOk('Logo exists')
.expect(this.toolbar_files_public.exists)
.expect(this.toolbarFilesPublic.exists)
.notOk('toolbar_file exists')
.expect(this.btnPublicDownload.exists)
.notOk('Download Button (desktop) exists')
Expand Down Expand Up @@ -104,14 +105,22 @@ export default class PublicDrivePage {
}

//@param{string} filename : Expected filename
async checkDownload(filename) {
const filePath = `${osHomedir}/Downloads/${filename}`
async checkLocalFile(filename) {
const filepath = `${homedir()}/Downloads/${filename}`
await t
.expect(fs.existsSync(filePath))
.expect(fs.existsSync(filepath))
.ok(`Downloaded ${filename} doesn't exist`)
console.log(`${filename} is downloaded`)
}

async deleteLocalFile(filename) {
const filePath = `${homedir()}/Downloads/${filename}`
fs.unlink(filePath, function(err) {
if (err) throw err
// if no error, file has been deleted successfully
console.log(`${filename} deleted`)
})
}
async checkNotAvailable() {
isExistingAndVisibile(this.errorAvailable)
}
Expand Down
29 changes: 14 additions & 15 deletions testcafe/tests/pages/drive-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -38,15 +38,15 @@ export default class DrivePage {
.child('h2')
.withText('Switch online!') // !FIXME: do not use text
//loading
this.content_placeholder = Selector(
this.contentPlaceHolder = Selector(
'[class*="fil-content-file-placeholder"]'
)
this.alertWrapper = Selector('[class*="c-alert-wrapper"]')

//Toolbar - Action Menu
this.toolbar_files = getElementWithTestId('fil-toolbar-files')
this.btnMoreMenu = this.toolbar_files.find('[class*="dri-btn--more"]')
this.coz_menu_inner = getElementWithTestId('coz-menu-inner')
this.toolbarFiles = getElementWithTestId('fil-toolbar-files')
this.btnMoreMenu = this.toolbarFiles.find('[class*="dri-btn--more"]')
this.cozyMenuInner = getElementWithTestId('coz-menu-inner')
this.btnAddFolder = getElementWithTestId('add-folder-link').parent(
'[class*="coz-menu-item"]'
)()
Expand All @@ -67,19 +67,19 @@ export default class DrivePage {

// Upload
this.btnUpload = getElementWithTestId('uploadButton')
this.divUpload = getElementWithTestId('uploadQueue')
this.divUploadSuccess = getElementWithTestId('uploadQueue-success')
this.divUpload = getElementWithTestId('upload-queue')
this.divUploadSuccess = getElementWithTestId('upload-queue-success')

// Sharing
this.btnShare = this.toolbar_files
this.btnShare = this.toolbarFiles
.child('button')
.withAttribute('data-test-id', 'share-button')
this.modalShare = Selector('[class*="share-modal-content"]')
this.divShareByLink = getElementWithTestId('share-by-link')
this.toggleShareLink = this.divShareByLink.child('[class*="toggle"]')
this.spanLinkCreating = Selector('[class*="share-bylink-header-creating"]')
this.copyBtnShareByLink = Selector('button').withAttribute('data-test-data')
this.btnShareByMe = this.toolbar_files
this.copyBtnShareByLink = Selector('button').withAttribute('data-test-url')
this.btnShareByMe = this.toolbarFiles
.child('button')
.withAttribute('data-test-id', 'share-by-me-button')

Expand All @@ -94,7 +94,7 @@ export default class DrivePage {

async waitForLoading() {
await t
.expect(this.content_placeholder.exists)
.expect(this.contentPlaceHolder.exists)
.notOk('Content placeholder still displayed')
}

Expand Down Expand Up @@ -167,10 +167,10 @@ export default class DrivePage {
}

async openActionMenu() {
isExistingAndVisibile(this.toolbar_files, 'toolbar_files')
isExistingAndVisibile(this.toolbarFiles, 'toolbarFiles')
isExistingAndVisibile(this.btnMoreMenu, `[...] button`)
await t.click(this.btnMoreMenu)
isExistingAndVisibile(this.coz_menu_inner, 'Cozy inner menu')
isExistingAndVisibile(this.cozyMenuInner, 'Cozy inner menu')
}
//@param {String} newFolderName
async addNewFolder(newFolderName) {
Expand Down Expand Up @@ -237,9 +237,8 @@ export default class DrivePage {
await t.expect(rowCountEnd).eql(rowCountStart + 1) //New content line appears
}

//NOT FINISH !!!
async shareFolderPublicLink() {
isExistingAndVisibile(this.toolbar_files, 'toolbar_files')
isExistingAndVisibile(this.toolbarFiles, 'toolbarFiles')
isExistingAndVisibile(this.btnShare, `Share button`)
await t.click(this.btnShare)
isExistingAndVisibile(this.ShareModal, 'Share modal')
Expand All @@ -264,7 +263,7 @@ export default class DrivePage {
}

async unshareFolderPublicLink() {
isExistingAndVisibile(this.toolbar_files, 'toolbar_files')
isExistingAndVisibile(this.toolbarFiles, 'toolbarFiles')
isExistingAndVisibile(this.btnShareByMe, `Share by Me button`)
await t.click(this.btnShareByMe)
isExistingAndVisibile(this.ShareModal, 'Share modal')
Expand Down
4 changes: 2 additions & 2 deletions testcafe/tests/pages/photos-model.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ export default class Page {

// Upload
this.btnUpload = getElementWithTestId('uploadButton')
this.divUpload = getElementWithTestId('uploadQueue')
this.divUploadSuccess = getElementWithTestId('uploadQueue-success')
this.divUpload = getElementWithTestId('upload-queue')
this.divUploadSuccess = getElementWithTestId('upload-queue-success')
this.modalUpload = Selector('[class*="c-alert-wrapper"]', {
visibilityCheck: true
})
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -7096,6 +7096,11 @@ home-or-tmp@^2.0.0:
os-homedir "^1.0.0"
os-tmpdir "^1.0.1"

homedir@^0.6.0:
version "0.6.0"
resolved "https://registry.yarnpkg.com/homedir/-/homedir-0.6.0.tgz#2b21db66bf08a6db38249a3eff52d7d18706af1e"
integrity sha1-KyHbZr8Ipts4JJo+/1LX0YcGrx4=

hoopy@^0.1.2:
version "0.1.4"
resolved "https://registry.yarnpkg.com/hoopy/-/hoopy-0.1.4.tgz#609207d661100033a9a9402ad3dea677381c1b1d"
Expand Down

0 comments on commit 9842701

Please sign in to comment.