From e5a01f7a573e6105ebb56e626a52323b910a8d28 Mon Sep 17 00:00:00 2001 From: zmagod Date: Fri, 27 Oct 2017 16:37:42 +0200 Subject: [PATCH 1/4] adds integration tests for about sciNote modal --- .../Navigation/components/InfoDropdown.jsx | 94 +++++++++++++------ app/javascript/src/config/locales/messages.js | 3 +- .../src/services/api/configurations_api.js | 6 ++ app/javascript/src/services/api/endpoints.js | 3 + config/routes.rb | 2 +- config/routes/confirmations.rb | 2 + .../navigation/addons_versions_modal.feature | 21 +++++ features/settings_page/profile.feature | 2 +- features/step_definitions/shared_steps.rb | 6 +- yarn.lock | 2 +- 10 files changed, 106 insertions(+), 35 deletions(-) create mode 100644 app/javascript/src/services/api/configurations_api.js create mode 100644 config/routes/confirmations.rb create mode 100644 features/navigation/addons_versions_modal.feature diff --git a/app/javascript/src/components/Navigation/components/InfoDropdown.jsx b/app/javascript/src/components/Navigation/components/InfoDropdown.jsx index df063f0c6..4e81ed3d0 100644 --- a/app/javascript/src/components/Navigation/components/InfoDropdown.jsx +++ b/app/javascript/src/components/Navigation/components/InfoDropdown.jsx @@ -1,4 +1,5 @@ -import React from "react"; +// @flow +import React, { Component } from "react"; import { FormattedMessage } from "react-intl"; import { NavDropdown, MenuItem } from "react-bootstrap"; import { @@ -8,35 +9,68 @@ import { PREMIUM_LINK, CONTACT_US_LINK } from "../../../config/routes"; +import { getSciNoteInfo } from "../../../services/api/configurations_api"; -const InfoDropdown = () => - -   - - - - - } - id="nav-info-dropdown" - > - - - - - - - - - - - - - - - - ; +type State = { + modalOpen: boolean, + scinoteVersion: string, + addons: Array +}; + +class InfoDropdown extends Component<*, State> { + constructor(props: any) { + super(props); + this.state = { modalOpen: false, scinoteVersion: "", addons: [] }; + (this: any).showAboutUsModal = this.showAboutUsModal.bind(this); + } + + showAboutUsModal(): void { + getSciNoteInfo().then(response => { + const { scinoteVersion, addons } = response; + (this: any).setState({ + scinoteVersion, + addons, + modalOpen: true + }); + }); + } + + render() { + return ( + +   + + + + + } + id="nav-info-dropdown" + > + + + + + + + + + + + + + + + + + + + + + ); + } +} export default InfoDropdown; diff --git a/app/javascript/src/config/locales/messages.js b/app/javascript/src/config/locales/messages.js index 4f6cd1389..c1258cdf4 100644 --- a/app/javascript/src/config/locales/messages.js +++ b/app/javascript/src/config/locales/messages.js @@ -204,7 +204,8 @@ export default { tutorials: "Tutorials", release_notes: "Release notes", premium: "Premium", - contact_us: "Contact us" + contact_us: "Contact us", + about_scinote: "About sciNote" }, user_account_dropdown: { greeting: "Hi, {name}", diff --git a/app/javascript/src/services/api/configurations_api.js b/app/javascript/src/services/api/configurations_api.js new file mode 100644 index 000000000..0797ea244 --- /dev/null +++ b/app/javascript/src/services/api/configurations_api.js @@ -0,0 +1,6 @@ +// @flow +import axiosInstance from "./config"; +import { ABOUT_SCINOTE_PATH } from "./endpoints"; + +export const getSciNoteInfo = (): Promise<*> => + axiosInstance.get(ABOUT_SCINOTE_PATH).then(({ data }) => data); diff --git a/app/javascript/src/services/api/endpoints.js b/app/javascript/src/services/api/endpoints.js index 83a2ac416..edaa3d752 100644 --- a/app/javascript/src/services/api/endpoints.js +++ b/app/javascript/src/services/api/endpoints.js @@ -42,3 +42,6 @@ export const INVITE_USERS_PATH = "/client_api/users/invite_users"; // settings export const SETTINGS_TEAMS = "/settings/teams"; + +// scinote configurations +export const ABOUT_SCINOTE_PATH = "/client_api/about_scinote"; diff --git a/config/routes.rb b/config/routes.rb index b00d30ee1..77bea4053 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,7 +18,7 @@ Rails.application.routes.draw do get '/settings/*all', to: 'client_api/settings#index' namespace :client_api, defaults: { format: 'json' } do - %i(activities teams notifications users).each do |path| + %i(activities teams notifications users confirmations).each do |path| draw path end end diff --git a/config/routes/confirmations.rb b/config/routes/confirmations.rb new file mode 100644 index 000000000..8cb5cbcf2 --- /dev/null +++ b/config/routes/confirmations.rb @@ -0,0 +1,2 @@ +# scinote configurations routes +get '/about_scinote', to: 'configurations_controller#about_scinote' diff --git a/features/navigation/addons_versions_modal.feature b/features/navigation/addons_versions_modal.feature new file mode 100644 index 000000000..139004d33 --- /dev/null +++ b/features/navigation/addons_versions_modal.feature @@ -0,0 +1,21 @@ +Feature: Addon versions + As a sciNote User + I want know what addon are activated + So that I know what features are enabled + + Background: + Given the "BioSistemika Process" team exists + Given the following users are registered + | email | password | password_confirmation | full_name | initials | + | admin@myorg.com | mypassword1234 | mypassword1234 | Karli Novak | KN | + And "admin@myorg.com" is in "BioSistemika Process" team as a "admin" + And is signed in with "admin@myorg.com", "mypassword1234" + + @javascript + Scenario: Open the sciNote addons modal + Given I'm on the profile page + And I click "#nav-info-dropdown" icon + And I click "About sciNote" link within ".dropdown.open" + Then I should see "About sciNote" + And I should see "sciNote core version" + And I should see "Addon versions" diff --git a/features/settings_page/profile.feature b/features/settings_page/profile.feature index ff968c9b6..b1571f500 100644 --- a/features/settings_page/profile.feature +++ b/features/settings_page/profile.feature @@ -15,7 +15,7 @@ Background: Scenario: Successful navigate to profile page Given I'm on the home page of "BioSistemika Process" team And I click on Avatar - And I click "Settings" link within "user-account-dropdown" + And I click "Settings" link within "#user-account-dropdown" Then I should see "My Profile" @javascript diff --git a/features/step_definitions/shared_steps.rb b/features/step_definitions/shared_steps.rb index 87b792bf6..c4abd72b7 100644 --- a/features/step_definitions/shared_steps.rb +++ b/features/step_definitions/shared_steps.rb @@ -15,7 +15,7 @@ Given(/^I click "(.+)" link$/) do |link| end Given(/^I click "(.+)" link within "(.+)"$/) do |link, element| - within("##{element}") do + within(element) do click_link link end end @@ -92,3 +92,7 @@ Then(/^I should see "([^"]*)" in "([^"]*)" input field$/) do |text, container_id container = page.find_by_id(container_id) expect(container).to have_xpath("//input[@value='#{text}']") end + +Given("I click {string} icon") do |id| + find(:css, id).click +end diff --git a/yarn.lock b/yarn.lock index d2b42b099..d3498b4ff 100644 --- a/yarn.lock +++ b/yarn.lock @@ -4865,7 +4865,7 @@ prop-types-extra@^1.0.1: dependencies: warning "^3.0.0" -prop-types@^15.5.10: +prop-types@^15.5.10, prop-types@^15.5.6: version "15.6.0" resolved "https://registry.yarnpkg.com/prop-types/-/prop-types-15.6.0.tgz#ceaf083022fc46b4a35f69e13ef75aed0d639856" dependencies: From 2118b317623fb011769e78769f6a29f696898afe Mon Sep 17 00:00:00 2001 From: zmagod Date: Thu, 2 Nov 2017 13:23:57 +0100 Subject: [PATCH 2/4] adds about sciNote modal --- .../client_api/configurations_controller.rb | 23 ++++++++++++ .../components/AboutScinoteModal.jsx | 35 +++++++++++++++++++ .../Navigation/components/InfoDropdown.jsx | 23 +++++++++--- app/javascript/src/config/locales/messages.js | 5 ++- config/routes.rb | 2 +- config/routes/configurations.rb | 2 ++ config/routes/confirmations.rb | 2 -- 7 files changed, 83 insertions(+), 9 deletions(-) create mode 100644 app/controllers/client_api/configurations_controller.rb create mode 100644 app/javascript/src/components/Navigation/components/AboutScinoteModal.jsx create mode 100644 config/routes/configurations.rb delete mode 100644 config/routes/confirmations.rb diff --git a/app/controllers/client_api/configurations_controller.rb b/app/controllers/client_api/configurations_controller.rb new file mode 100644 index 000000000..30c623ba3 --- /dev/null +++ b/app/controllers/client_api/configurations_controller.rb @@ -0,0 +1,23 @@ +module ClientApi + class ConfigurationsController < ApplicationController + + def about_scinote + respond_to do |format| + format.json do + render json: { + scinoteVersion: Scinote::Application::VERSION, + addons: list_all_addons + }, status: :ok + end + end + end + + private + + def list_all_addons + Rails::Engine.subclasses + .select { |c| c.name.start_with?('Scinote') } + .map(&:parent) + end + end +end diff --git a/app/javascript/src/components/Navigation/components/AboutScinoteModal.jsx b/app/javascript/src/components/Navigation/components/AboutScinoteModal.jsx new file mode 100644 index 000000000..665b4cf2a --- /dev/null +++ b/app/javascript/src/components/Navigation/components/AboutScinoteModal.jsx @@ -0,0 +1,35 @@ +// @flow +import React from "react"; +import type { Node } from "react"; +import { FormattedMessage } from "react-intl"; +import { Modal } from "react-bootstrap"; + +type Props = { + showModal: boolean, + scinoteVersion: string, + addons: Array, + onModalClose: Function +}; + +export default (props: Props): Node => { + const { showModal, scinoteVersion, addons, onModalClose } = props; + return ( + + + + + + + + + + +

{scinoteVersion}

+ + + + {addons.map((addon: string): Node =>

{addon}

)} +
+
+ ); +}; diff --git a/app/javascript/src/components/Navigation/components/InfoDropdown.jsx b/app/javascript/src/components/Navigation/components/InfoDropdown.jsx index 4e81ed3d0..e01328f56 100644 --- a/app/javascript/src/components/Navigation/components/InfoDropdown.jsx +++ b/app/javascript/src/components/Navigation/components/InfoDropdown.jsx @@ -11,6 +11,8 @@ import { } from "../../../config/routes"; import { getSciNoteInfo } from "../../../services/api/configurations_api"; +import AboutScinoteModal from "./AboutScinoteModal"; + type State = { modalOpen: boolean, scinoteVersion: string, @@ -20,21 +22,26 @@ type State = { class InfoDropdown extends Component<*, State> { constructor(props: any) { super(props); - this.state = { modalOpen: false, scinoteVersion: "", addons: [] }; - (this: any).showAboutUsModal = this.showAboutUsModal.bind(this); + this.state = { showModal: false, scinoteVersion: "", addons: [] }; + (this: any).showAboutSciNoteModal = this.showAboutSciNoteModal.bind(this); + (this: any).closeModal = this.closeModal.bind(this); } - showAboutUsModal(): void { + showAboutSciNoteModal(): void { getSciNoteInfo().then(response => { const { scinoteVersion, addons } = response; (this: any).setState({ scinoteVersion, addons, - modalOpen: true + showModal: true }); }); } + closeModal(): void { + (this: any).setState({ showModal: false }); + } + render() { return ( { - + + ); diff --git a/app/javascript/src/config/locales/messages.js b/app/javascript/src/config/locales/messages.js index c1258cdf4..88cef0ad6 100644 --- a/app/javascript/src/config/locales/messages.js +++ b/app/javascript/src/config/locales/messages.js @@ -6,7 +6,10 @@ export default { update: "Update", edit: "Edit", loading: "Loading ...", - upload: "Upload" + upload: "Upload", + about_scinote: "About sciNote", + core_version: "sciNote core version", + addon_versions: "Addon versions" }, page_title: { root: "SciNote", diff --git a/config/routes.rb b/config/routes.rb index 77bea4053..8d430a8f6 100644 --- a/config/routes.rb +++ b/config/routes.rb @@ -18,7 +18,7 @@ Rails.application.routes.draw do get '/settings/*all', to: 'client_api/settings#index' namespace :client_api, defaults: { format: 'json' } do - %i(activities teams notifications users confirmations).each do |path| + %i(activities teams notifications users configurations).each do |path| draw path end end diff --git a/config/routes/configurations.rb b/config/routes/configurations.rb new file mode 100644 index 000000000..198449f22 --- /dev/null +++ b/config/routes/configurations.rb @@ -0,0 +1,2 @@ +# scinote configurations routes +get '/about_scinote', to: 'configurations#about_scinote' diff --git a/config/routes/confirmations.rb b/config/routes/confirmations.rb deleted file mode 100644 index 8cb5cbcf2..000000000 --- a/config/routes/confirmations.rb +++ /dev/null @@ -1,2 +0,0 @@ -# scinote configurations routes -get '/about_scinote', to: 'configurations_controller#about_scinote' From 605674bf6b1838d4c786626ea8a60bae4d2dce18 Mon Sep 17 00:00:00 2001 From: zmagod Date: Thu, 2 Nov 2017 13:36:21 +0100 Subject: [PATCH 3/4] adds controller spec --- .../client_api/configurations_controller_spec.rb | 10 ++++++++++ 1 file changed, 10 insertions(+) create mode 100644 spec/controllers/client_api/configurations_controller_spec.rb diff --git a/spec/controllers/client_api/configurations_controller_spec.rb b/spec/controllers/client_api/configurations_controller_spec.rb new file mode 100644 index 000000000..a3c409138 --- /dev/null +++ b/spec/controllers/client_api/configurations_controller_spec.rb @@ -0,0 +1,10 @@ +require 'rails_helper' + +describe ClientApi::ConfigurationsController, type: :controller do + login_user + + describe '#about_scinote' do + let(:subject) { get :about_scinote, format: :json } + it { is_expected.to be_success } + end +end From f2246292590975fc5a8aea84ad14612c0019fe64 Mon Sep 17 00:00:00 2001 From: zmagod Date: Thu, 9 Nov 2017 09:00:00 +0100 Subject: [PATCH 4/4] fixes failing team.feature:19 scenario --- features/step_definitions/shared_steps.rb | 1 + 1 file changed, 1 insertion(+) diff --git a/features/step_definitions/shared_steps.rb b/features/step_definitions/shared_steps.rb index 2ba585890..4c122148b 100644 --- a/features/step_definitions/shared_steps.rb +++ b/features/step_definitions/shared_steps.rb @@ -120,5 +120,6 @@ Then(/^I change "([^"]*)" with "([^"]*)" in "([^"]*)" textarea field$/) do |old_ end Then(/^I should see "([^"]*)" on "([^"]*)" element$/) do |text, element| + wait_for_ajax expect(find(element)).to have_content(text) end