From f46aabb4d3c1dd900a414298eebbcc0fce08a867 Mon Sep 17 00:00:00 2001 From: vjrj Date: Wed, 21 Feb 2018 15:29:25 +0100 Subject: [PATCH] Added feedback --- cucumber/features/feedback.feature | 22 ++++ cucumber/features/general.feature | 1 - cucumber/features/pages.feature | 1 - .../features/steps_definitions/feedback.js | 49 ++++++++ cucumber/features/steps_definitions/helper.js | 2 + imports/ui/components/Feedback/Feedback.js | 106 ++++++++++-------- imports/ui/components/Utils/location.js | 20 ++-- imports/ui/layouts/App/App.js | 8 +- 8 files changed, 148 insertions(+), 61 deletions(-) create mode 100644 cucumber/features/feedback.feature create mode 100644 cucumber/features/steps_definitions/feedback.js diff --git a/cucumber/features/feedback.feature b/cucumber/features/feedback.feature new file mode 100644 index 0000000..d1ffed5 --- /dev/null +++ b/cucumber/features/feedback.feature @@ -0,0 +1,22 @@ +@watch +Feature: Allow users to give feedback + + As a user (authenticated or not) + I want to give feedback about this site + + Scenario: A user can login and give feedback + Given I am on the zones page + And I have an account and I logged in + # Because is not verified + Then I can send feedback with email + When I sign out + Then I can send feedback with email + + Scenario: A anon user can give feedback + Given I am on the fires page + Given I'm not logged + Then I can send feedback with email + + Scenario: A user cannot give feedback in home + Given I am on the home page + Then I cannot send feedback diff --git a/cucumber/features/general.feature b/cucumber/features/general.feature index 3cf078d..b1fd8f9 100644 --- a/cucumber/features/general.feature +++ b/cucumber/features/general.feature @@ -1,6 +1,5 @@ Feature: This app should generate a correct sitemap, etc - @watch Scenario: I verify that a sitemap is generated correctly Given the page sitemap.xml Then I check that exist this list of pages in the sitemap diff --git a/cucumber/features/pages.feature b/cucumber/features/pages.feature index ed3f4fe..552ab8b 100644 --- a/cucumber/features/pages.feature +++ b/cucumber/features/pages.feature @@ -9,7 +9,6 @@ Feature: Test all secundary pages | activeFires | Active Fires | Then I check that all pages works properly - @watch Scenario: Check that all secondary pages work well Given a list of page urls and contents | login | Login | true | diff --git a/cucumber/features/steps_definitions/feedback.js b/cucumber/features/steps_definitions/feedback.js new file mode 100644 index 0000000..f25a3b3 --- /dev/null +++ b/cucumber/features/steps_definitions/feedback.js @@ -0,0 +1,49 @@ +/* global module expect require process client */ + +const { randomText, randomEmail } = require('./helper.js'); + +module.exports = function doSteps() { + this.Given(/^I am on the zones page$/, () => { + client.url(`${process.env.ROOT_URL}/zones`); + if (client.isVisible('#logout')) { + client.click('#logout'); + } + }); + + this.Then(/^I can send feedback without email$/, () => { + client.waitForVisible('#feedback-tab', 10000); + client.click('#feedback-tab'); + client.waitForVisible('#feedback-form', 10000); + client.setValue('#feedbackTextarea', randomText(500)); + client.click('#sendFeedbackBtn'); + client.waitForVisible('.bert-alert', 10000, true); + client.waitUntil(() => client.isVisible('.bert-alert') === false, 10000); + }); + + this.Then(/^I can send feedback with email$/, () => { + client.waitForVisible('#feedback-tab', 10000); + client.click('#feedback-tab'); + client.waitForVisible('#feedback-form', 10000); + client.setValue('input[name="email"]', randomEmail()); + client.setValue('#feedbackTextarea', randomText(500)); + client.click('#sendFeedbackBtn'); + client.waitForVisible('.bert-alert', 10000, true); + client.waitUntil(() => client.isVisible('.bert-alert') === false, 10000); + }); + + this.Given(/^I'm not logged$/, () => { + client.waitForVisible('#react-root', 5000); + if (client.isVisible('#logout')) { + client.click('#logout'); + } + }); + + this.Given(/^I am on the fires page$/, () => { + client.url(`${process.env.ROOT_URL}/fires`); + }); + + this.Then(/^I cannot send feedback$/, () => { + client.waitForVisible('#react-root', 5000); + client.waitUntil(() => client.isVisible('#feedback-tab') === false, 10000); + }); +}; diff --git a/cucumber/features/steps_definitions/helper.js b/cucumber/features/steps_definitions/helper.js index 9961796..7274a40 100644 --- a/cucumber/features/steps_definitions/helper.js +++ b/cucumber/features/steps_definitions/helper.js @@ -8,6 +8,8 @@ function makeid(size) { return text; } +export const randomText = n => makeid(n); + export const randomUsername = () => makeid(7); export const randomPassword = () => randomUsername(); diff --git a/imports/ui/components/Feedback/Feedback.js b/imports/ui/components/Feedback/Feedback.js index c6b8919..26338cb 100644 --- a/imports/ui/components/Feedback/Feedback.js +++ b/imports/ui/components/Feedback/Feedback.js @@ -2,14 +2,16 @@ /* eslint-disable import/no-absolute-path */ /* eslint-disable import/no-absolute-path */ -import React, { Component } from 'react'; +import React, { Component, Fragment } from 'react'; import PropTypes from 'prop-types'; import { Meteor } from 'meteor/meteor'; import { translate } from 'react-i18next'; import { FormGroup, Button, FormControl } from 'react-bootstrap'; import { Bert } from 'meteor/themeteorchef:bert'; import { withTracker } from 'meteor/react-meteor-data'; -import validate from '../../../modules/validate'; +import { isHome } from '/imports/ui/components/Utils/location'; +import { testId } from '/imports/ui/components/Utils/TestUtils'; +import validate from '/imports/modules/validate'; import './Feedback.scss'; @@ -67,50 +69,59 @@ class Feedback extends Component { } render() { + // console.log(`Render Feedback because isHome ${this.props.isHome}, email: '${this.props.emailAddress}'`); + const disabled = this.props.emailVerified && this.props.emailAddress; return ( -
-
(this.formdiv = formdiv)} style={{ display: 'none' }} className="card"> -
(this.form = form)} - className="form card-body" - onSubmit={event => event.preventDefault()} - > - - (this.email = email)} - placeholder={this.t('Tu correo')} - disabled={this.props.emailVerified} - defaultValue={this.props.emailVerified ? this.props.emailAddress : ''} - type="email" - /> - - + { !this.props.isHome && +
+
(this.formdiv = formdiv)} style={{ display: 'none' }} className="card"> + (this.form = form)} + className="form card-body" + onSubmit={event => event.preventDefault()} + > + + (this.email = email)} + placeholder={this.t('Tu correo')} + key={disabled ? 'disabledEmail' : 'enabledEmail'} + disabled={disabled} + defaultValue={disabled ? this.props.emailAddress : ''} + type="email" + /> + + +