Skip to content

Commit

Permalink
feat(testcafe): add copy url to Sharing folder scenario
Browse files Browse the repository at this point in the history
  • Loading branch information
CozyKourai committed Feb 1, 2019
1 parent 26ba31d commit 754781e
Show file tree
Hide file tree
Showing 6 changed files with 43 additions and 30 deletions.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,6 @@
"husky": "0.14.3",
"identity-obj-proxy": "3.0.0",
"npm-run-all": "4.1.5",
"openssl-self-signed-certificate": "^1.1.6",
"react": "15.6.2",
"react-addons-test-utils": "15.6.2",
"react-dom": "15.6.2",
Expand Down
12 changes: 2 additions & 10 deletions testcafe/runner-drive.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,11 @@
const createTestCafe = require('testcafe')
const selfSignedSertificate = require('openssl-self-signed-certificate')

const sslOptions = {
key: selfSignedSertificate.key,
cert: selfSignedSertificate.cert
}

async function runRunner() {
const tc = await createTestCafe('localhost', 1337, 1338, sslOptions)
const tc = await createTestCafe()
const runner = await tc.createRunner()
const response = await runner
.src(['testcafe/tests/drive_nav.js', 'testcafe/tests/drive_sharing.js'])
.browsers([
'chrome --allow-insecure-localhost --allow-running-insecure-content --start-maximized'
])
.browsers(['chrome --start-maximized'])

.screenshots(
'reports/screenshots/',
Expand Down
22 changes: 13 additions & 9 deletions testcafe/tests/drive_sharing.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,12 @@ import { Selector, Role } from 'testcafe'
import { driveUser } from './helpers/roles'
import {
TESTCAFE_DRIVE_URL,
FOLDER_DATE_TIME,
isExistingAndVisibile,
getCurrentDateTime
getCurrentDateTime,
FOLDER_DATE_TIME
} from './helpers/utils'
import Data from './helpers/data'
const data = new Data()

import DrivePage from './pages/drive-model'
const drivePage = new DrivePage()
Expand Down Expand Up @@ -36,7 +38,12 @@ test('Drive : from Drive, go in a folder, upload a file, and share it', async t
await t.pressKey('esc') //close action Menu

await drivePage.uploadFiles([`../data/${file}`])
await drivePage.shareFolderPublicLink() //-> Not finish
await drivePage.shareFolderPublicLink()

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

//************************
Expand All @@ -47,9 +54,7 @@ fixture`Drive : Access a folder public link`
await t.useRole(Role.anonymous())
})
test('Drive : Access a folder public link', async t => {
await t.navigateTo(
'http://drive.cozy.tools:8080/public?sharecode=t2dqusHt2GFf'
) //!// FIXME: :use URL from copy-paste
await t.navigateTo(data.sharingLink)
await publicDrivePage.waitForLoading()

await publicDrivePage.checkActionMenuPublicDesktop()
Expand Down Expand Up @@ -101,9 +106,8 @@ fixture`Drive : No Access to an old folder public link`
await t.useRole(Role.anonymous())
})
test('`Drive : No Access to an old folder public link', async t => {
await t.navigateTo(
'http://drive.cozy.tools:8080/public?sharecode=Ueoxcqmt9Ve7'
) //!// FIXME: :use URL from copy-paste
await t.navigateTo(data.sharingLink)

await publicDrivePage.waitForLoading()
await publicDrivePage.checkNotAvailable()
})
Expand Down
5 changes: 5 additions & 0 deletions testcafe/tests/helpers/data.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
export default class Data {
constructor() {
this.sharingLink = ''
}
}
8 changes: 6 additions & 2 deletions testcafe/tests/helpers/utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,10 @@ export function getCurrentDateTime() {

export const FOLDER_DATE_TIME = `Folder_${getCurrentDateTime()}`

export const getClipboardData = ClientFunction(() => {
navigator.clipboard.readText() //chrome only
export const overwriteCopyCommand = ClientFunction(() => {
document.execCommand = command => (window.lastExecutedCommand = command)
})

export const getLastExecutedCommand = ClientFunction(
() => window.lastExecutedCommand
)
25 changes: 17 additions & 8 deletions testcafe/tests/pages/drive-model.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import { Selector, t } from 'testcafe'
import { Selector, t, ClientFunction } from 'testcafe'
import {
getElementWithTestId,
getPageUrl,
isExistingAndVisibile,
getClipboardData
getClipboardData,
overwriteCopyCommand,
getLastExecutedCommand
} from '../helpers/utils'

export default class DrivePage {
Expand Down Expand Up @@ -39,6 +41,7 @@ export default class DrivePage {
this.content_placeholder = Selector(
'[class*="fil-content-file-placeholder"]'
)
this.alertWrapper = Selector('[class*="c-alert-wrapper"]')

//Toolbar - Action Menu
this.toolbar_files = getElementWithTestId('fil-toolbar-files')
Expand Down Expand Up @@ -66,7 +69,6 @@ export default class DrivePage {
this.btnUpload = getElementWithTestId('uploadButton')
this.divUpload = getElementWithTestId('uploadQueue')
this.divUploadSuccess = getElementWithTestId('uploadQueue-success')
this.alertWrapper = Selector('[class*="c-alert-wrapper"]')

// Sharing
this.btnShare = this.toolbar_files
Expand All @@ -75,9 +77,8 @@ export default class DrivePage {
this.modalShare = Selector('[class*="share-modal-content"]')
this.divShareByLink = getElementWithTestId('share-by-link')
this.toggleShareLink = this.divShareByLink.child('[class*="toggle"]')
this.copyBtnShareByLink = getElementWithTestId(
'share-bylink-header-copybtn'
)
this.spanLinkCreating = Selector('[class*="share-bylink-header-creating"]')
this.copyBtnShareByLink = Selector('button').withAttribute('data-test-data')
this.btnShareByMe = this.toolbar_files
.child('button')
.withAttribute('data-test-id', 'share-by-me-button')
Expand Down Expand Up @@ -248,10 +249,18 @@ export default class DrivePage {
.click(this.toggleShareLink)
.expect(this.toggleShareLink.find('input').checked)
.ok('toggle Link is unchecked')
.expect(this.spanLinkCreating.exist)
.notOk('Still creating Link')
isExistingAndVisibile(this.copyBtnShareByLink, 'Copy Link')

await overwriteCopyCommand()

await t
.click(this.copyBtnShareByLink)
.expect(getLastExecutedCommand())
.eql('copy') //check link copy actually happens

// const tests = await getClipboardData()
// console.log(tests)
isExistingAndVisibile(this.alertWrapper, '"successfull" modal alert')
}

async unshareFolderPublicLink() {
Expand Down

0 comments on commit 754781e

Please sign in to comment.