Skip to content

Commit

Permalink
[SDPA-2747] Event page e2e test (#429)
Browse files Browse the repository at this point in the history
* [SDPA-2747] Add Event Page e2e test.

* [SDPA-2747] Update test script to read as per ticket.

* [SDPA-2747] Fix script bugs.

* [SDPA-2747] Fix CR issues.
  • Loading branch information
alan-cole authored and dylankelly committed Jul 12, 2019
1 parent 95cf0c7 commit f4ee9fc
Show file tree
Hide file tree
Showing 9 changed files with 250 additions and 1 deletion.
3 changes: 3 additions & 0 deletions packages/ripple-test-tools/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@ module.exports = (on, config) => {
createGrantPage (data) {
return new TideAdmin().createGrantPage(data)
},
createEventPage (data) {
return new TideAdmin().createEventPage(data)
},
createUser (user) {
return new TideAdmin().createUser(user)
},
Expand Down
31 changes: 31 additions & 0 deletions packages/ripple-test-tools/page-models.js
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,37 @@ const adminPageModels = {
department: dataSel('edit-field-node-department')
}
},
eventPage: {
description: dataSel('edit-field-event-description-wrapper'),
tabs: {
bodyContent: hrefSel('#edit-group-body-content'),
eventAuthor: hrefSel('#edit-group-event-author')
},
bodyContent: {
body: dataSel('edit-body-wrapper'),
startDate: dataSel('edit-field-event-details-0-subform-field-paragraph-date-range-0-value-date'),
startTime: dataSel('edit-field-event-details-0-subform-field-paragraph-date-range-0-value-time'),
endDate: dataSel('edit-field-event-details-0-subform-field-paragraph-date-range-0-end-value-date'),
endTime: dataSel('edit-field-event-details-0-subform-field-paragraph-date-range-0-end-value-time'),
streetAddress: dataSel('edit-field-event-details-0-subform-field-paragraph-location-0-address-address-line1'),
suburb: dataSel('edit-field-event-details-0-subform-field-paragraph-location-0-address-locality'),
state: dataSel('edit-field-event-details-0-subform-field-paragraph-location-0-address-administrative-area'),
postalCode: dataSel('edit-field-event-details-0-subform-field-paragraph-location-0-address-postal-code'),
price: dataSel('edit-field-event-details-0-subform-field-paragraph-event-price-from-0-value'),
priceTo: dataSel('edit-field-event-details-0-subform-field-paragraph-event-price-to-0-value'),
eventRequirements: dataSel('edit-field-event-details-0-subform-field-event-requirements-0-target-id'),
bookUrl: dataSel('edit-field-event-details-0-subform-field-paragraph-link-0-uri'),
linkText: dataSel('edit-field-event-details-0-subform-field-paragraph-link-0-title'),
eventCategory: dataSel('edit-field-event-category-0-target-id'),
audience: dataSel('edit-field-audience-0-target-id'),
websiteUrl: dataSel('edit-field-node-link-0-uri')
},
eventAuthor: {
fullName: dataSel('edit-field-node-author-0-value'),
emailAddress: dataSel('edit-field-node-email-0-value'),
contactPhone: dataSel('edit-field-node-phone-0-value')
}
},
jwt: {
expiry: dataSel('edit-jwt-exp'),
key: dataSel('edit-jwt-key')
Expand Down
66 changes: 66 additions & 0 deletions packages/ripple-test-tools/tide-admin.js
Original file line number Diff line number Diff line change
Expand Up @@ -453,6 +453,72 @@ module.exports = class TideAdmin {
return Promise.resolve(nodeId)
}

async createEventPage (testData) {
if (!testData) return null
// create browser and page
const page = await this.setup()
const ePage = this.pageModels['eventPage']

// Login
await this.login()

// Create Event page
await page.goto(`${this.backendURL}/node/add/event`)
await page.waitForSelector('#drupal-live-announce', this.options.wait)
await page.type(this.pageModels.common.title, testData.title)
await page.type(this.pageModels.common.summary, testData.summary)
await page.type(this.pageModels.common.topic, testData.topic)
await page.click(this.pageModels.common.primarySite(testData.siteNumber))
await page.click(this.pageModels.common.siteCheckbox(testData.siteNumber))
await utils.setWysiwygText(ePage.description, testData.description, page)

// Body content tab
await page.click(ePage.tabs.bodyContent)
await utils.setWysiwygText(ePage.bodyContent.body, testData.bodyContent.body, page)
await utils.addWysiwygMediaEmbed(ePage.bodyContent.body, 'image', 1, page)
await page.type(ePage.bodyContent.startDate, testData.bodyContent.startDate)
await page.type(ePage.bodyContent.startTime, testData.bodyContent.startTime)
await page.type(ePage.bodyContent.endDate, testData.bodyContent.endDate)
await page.type(ePage.bodyContent.endTime, testData.bodyContent.endTime)
await page.type(ePage.bodyContent.streetAddress, testData.bodyContent.streetAddress)
await page.type(ePage.bodyContent.suburb, testData.bodyContent.suburb)
await page.type(ePage.bodyContent.state, testData.bodyContent.state)
await page.type(ePage.bodyContent.postalCode, testData.bodyContent.postalCode)
await page.type(ePage.bodyContent.price, testData.bodyContent.price)
await page.type(ePage.bodyContent.priceTo, testData.bodyContent.priceTo)
await page.type(ePage.bodyContent.eventRequirements, testData.bodyContent.eventRequirements)
await page.type(ePage.bodyContent.bookUrl, testData.bodyContent.bookUrl)
await page.type(ePage.bodyContent.linkText, testData.bodyContent.linkText)
await page.type(ePage.bodyContent.eventCategory, testData.bodyContent.eventCategory)
await page.type(ePage.bodyContent.audience, testData.bodyContent.audience)
await page.type(ePage.bodyContent.websiteUrl, testData.bodyContent.websiteUrl)

// Event content tab
await page.click(ePage.tabs.eventAuthor)
await page.type(ePage.eventAuthor.fullName, testData.eventAuthor.fullName)
await page.type(ePage.eventAuthor.emailAddress, testData.eventAuthor.emailAddress)
await page.type(ePage.eventAuthor.contactPhone, testData.eventAuthor.contactPhone)

// Set moderation state to published
await page.select(this.pageModels.common.moderationState, 'published')

// Submit
await this.submitPage()

// get nodeid
await page.waitForSelector('#drupal-live-announce', this.options.wait)
const nodeId = await page.$eval('.tabs__tab .is-active', el =>
el
.getAttribute('data-drupal-link-system-path')
.split('/')
.pop()
)
await this.close()

// Return nodeId
return Promise.resolve(nodeId)
}

async createUser (user) {
if (!user) return null

Expand Down
24 changes: 23 additions & 1 deletion packages/ripple-test-tools/util.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,31 @@ const setWysiwygText = async (selector, content, page) => {
}, content)
}

const addWysiwygMediaEmbed = async (selector, bundle, index, page) => {
await page.waitForSelector(selector)
await page.waitFor(1000)
await page.waitForSelector(selector + ' .cke_button__tide_media')
await page.click(selector + ' .cke_button__tide_media')
await page.waitFor(1000)

// Get iFrame
const elementHandle = await page.$('iframe#entity_browser_iframe_tide_media_browser_iframe')
const frame = await elementHandle.contentFrame()

await frame.select('#edit-bundle', bundle)
await frame.click(dataSel('edit-submit-tide-media-browser'))
await page.waitFor(1000)
await frame.click(`.view-tide-media-browser .views-table tbody > tr:nth-child(${index}) .views-field-entity-browser-select .form-checkbox`)
await frame.click(dataSel('edit-submit'))
await page.waitFor(1000)
await page.click('.ui-dialog-buttonpane .button--primary.form-submit')
await page.waitFor(1000)
}

module.exports = {
dataSel,
valueSel,
hrefSel,
setWysiwygText
setWysiwygText,
addWysiwygMediaEmbed
}
31 changes: 31 additions & 0 deletions test/e2e/fixtures/Pages/Event/event.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
{
"title": "2-BE-event-1",
"summary": "Tell me, O muse, of that ingenious hero who travelled far and wide after he had sacked the famous town of Troy. Many cities did he visit, and many were the nations with whose manners and customs END",
"topic": "\"Education (10)\"",
"siteNumber": 4,
"description": "Now Neptune had gone off to the Ethiopians, who are at the world's end, and lie in two halves, the one looking West and the other East. He had gone there to accept a hecatomb of sheep and oxen, and was enjoying himself at his festival; but the other gods met in the house of Olympian Jove, and the sire of gods and men spoke first.",
"bodyContent": {
"body": "So now all who escaped death in battle or by shipwreck had got safely home except Ulysses, and he, though he was longing to return to his wife and country, was detained by the goddess Calypso, who had got him into a large cave and wanted to marry him. But as years went by, there came a time when the gods settled that he should go back to Ithaca; even then, however, when he was among his own people, his troubles were not yet over; nevertheless all the gods had now begun to pity him except Neptune, who still persecuted him without ceasing and would not let him get home.",
"startDate": "20/05/2019",
"startTime": "11:02:20am",
"endDate": "13/05/2020",
"endTime": "11:11:11am",
"streetAddress": "45 Collins St",
"suburb": "Melbourne",
"state": "VIC",
"postalCode": "3000",
"price": "34.33",
"priceTo": "89.95",
"eventRequirements": "Accessible venue (84)",
"bookUrl": "http://examplebook.com",
"linkText": "External Link",
"eventCategory": "Film and cinema (78)",
"audience": "Individual (80)",
"websiteUrl": "https://www.weatherzone.com.au/vic/central/healesville"
},
"eventAuthor": {
"fullName": "Full Name",
"emailAddress": "[email protected]",
"contactPhone": "12345678"
}
}
26 changes: 26 additions & 0 deletions test/e2e/integration/Events/Events.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
Feature: Events

As a citizen I can view information for all available content on an event page
Prerequisite: Events Simple Test 1-BE-event-1

# Before hook
# - Logs into backend
# - Creates eventpage from fixture data @pageData and saves node id as @nodeId

# After hook
# - Deletes node id @nodeId

Scenario: Event Page loads correctly
When I have navigated to the created page
Then the page title should be "2-BE-event-1"
And the Description should be "Now Neptune had gone off to the Ethiopians, who are at the world's end, and lie in two halves, the one looking West and the other East. He had gone there to accept a hecatomb of sheep and oxen, and was enjoying himself at his festival; but the other gods met in the house of Olympian Jove, and the sire of gods and men spoke first."
And the Dates should be "20 May 2019 11:02 am - 13 May 2020 11:11 am"
And the Address should be "45 Collins St, Melbourne, VIC 3000"
And the Price should be "34.33 - 89.95"
And the Web url should be "https://www.weatherzone.com.au/vic/central/healesville"
And the Requirements should be "Accessible venue"
And the Body should be "So now all who escaped death in battle or by shipwreck had got safely home except Ulysses, and he, though he was longing to return to his wife and country, was detained by the goddess Calypso, who had got him into a large cave and wanted to marry him. But as years went by, there came a time when the gods settled that he should go back to Ithaca; even then, however, when he was among his own people, his troubles were not yet over; nevertheless all the gods had now begun to pity him except Neptune, who still persecuted him without ceasing and would not let him get home."
And the Image is asserted to be present
And the Booking Url link should be "http://examplebook.com"
And the Booking Text should be "External Link"
And the Booking Button should open in a new window
14 changes: 14 additions & 0 deletions test/e2e/integration/Events/Events/hooks.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/* global before, after, cy */

before(function () {
cy.fixture('Pages/Event/event').as('pageData')
cy.get('@pageData').then(data => {
cy.task('createEventPage', data).as('nodeId')
})
})

after(function () {
if (this.nodeId) {
cy.task('deleteNode', this.nodeId)
}
})
47 changes: 47 additions & 0 deletions test/e2e/integration/Events/Events/step_definition.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
/* global cy */

import { Then } from 'cypress-cucumber-preprocessor/steps'

Then(`the Description should be {string}`, (description) => {
cy.get('.tide-event-content .rpl-col:nth-child(1) .rpl-markup .rpl-markup__inner').should('contain', description)
})

Then(`the Dates should be {string}`, (dates) => {
cy.get(`.tide-event-content .rpl-list .rpl-list__list-item:nth-child(1) .rpl-list__text`).should('contain', dates)
})

Then(`the Address should be {string}`, (address) => {
cy.get(`.tide-event-content .rpl-list .rpl-list__list-item:nth-child(2) .rpl-list__text`).should('contain', address)
})

Then(`the Price should be {string}`, (price) => {
cy.get(`.tide-event-content .rpl-list .rpl-list__list-item:nth-child(3) .rpl-list__text`).should('contain', price)
})

Then(`the Web url should be {string}`, (webUrl) => {
cy.get(`.tide-event-content .rpl-list .rpl-list__list-item:nth-child(4) .rpl-list__text`).should('contain', webUrl)
})

Then(`the Requirements should be {string}`, (requirements) => {
cy.get(`.tide-event-content .rpl-list .rpl-list__list-item:nth-child(5) .rpl-list__text`).should('contain', requirements)
})

Then(`the Body should be {string}`, (body) => {
cy.get('.tide-event-content .rpl-col:nth-child(3) .rpl-markup .rpl-markup__inner').should('contain', body)
})

Then(`the Image is asserted to be present`, () => {
cy.get('.tide-event-content .embedded-entity--media--image').should('exist')
})

Then(`the Booking Url link should be {string}`, (value) => {
cy.get('.tide-event-content .rpl-button').should('have.attr', 'href', value)
})

Then(`the Booking Text should be {string}`, (value) => {
cy.get('.tide-event-content .rpl-button').should('contain', value)
})

Then(`the Booking Button should open in a new window`, () => {
cy.get('.tide-event-content .rpl-button').should('have.attr', 'target', '_blank')
})
9 changes: 9 additions & 0 deletions test/e2e/integration/common/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,15 @@ Given(`I have created a landing page with the json fixture {string}`, (fixture)
})
})

Given(`I have created an event page with the json fixture {string}`, (fixture) => {
cy.fixture(fixture).as('pageData')
cy.get('@pageData').then(data => {
cy.task('createEventPage', data).then((nodeId) => {
cy.wrap(nodeId).as('nodeId')
})
})
})

Given(`I have navigated to the created page`, () => {
cy.get('@nodeId').then(nodeId => {
cy.visit(`/node/${nodeId}`)
Expand Down

0 comments on commit f4ee9fc

Please sign in to comment.