Skip to content

OpenProject is the leading open source project management software for product, project and portfolio management. A powerful Jira alternative with agile planning, issue tracking, roadmaps, Gantt charts, time tracking, collaboration features, and more. Available on premises or in the cloud. ⭐ Star us on GitHub

Add feature test for "show model" page

Henriette Dinger1b0d7aaafe9e
diff --git a/modules/ifc_models/spec/factories/ifc_model_factory.rb b/modules/ifc_models/spec/factories/ifc_model_factory.rb
index 4554f5ad121..f6174bf3802 100644
--- a/modules/ifc_models/spec/factories/ifc_model_factory.rb
+++ b/modules/ifc_models/spec/factories/ifc_model_factory.rb
@@ -29,17 +29,40 @@
FactoryBot.define do
factory :ifc_model, class: ::IFCModels::IFCModel do
title { 'My IFC model' }
+ project factory: :project
uploader factory: :user
+ is_default { true }
ifc_attachment do
- FileHelpers.mock_uploaded_file name: "model.ifc", content_type: 'application/binary', binary: true
+ Rack::Test::UploadedFile.new(
+ File.join(Rails.root, "modules/ifc_models/spec/fixtures/files/minimal.ifc"),
+ 'application/binary'
+ )
end
factory :ifc_model_converted do
+ title { 'My IFC model' }
+ project factory: :project
+ uploader factory: :user
+ is_default { true }
+ ifc_attachment do
+ Rack::Test::UploadedFile.new(
+ File.join(Rails.root, "modules/ifc_models/spec/fixtures/files/minimal.ifc"),
+ 'application/binary'
+ )
+ end
+
xkt_attachment do
- FileHelpers.mock_uploaded_file name: "model.xkt", content_type: 'application/binary', binary: true
+ Rack::Test::UploadedFile.new(
+ File.join(Rails.root, "modules/ifc_models/spec/fixtures/files/minimal.xkt"),
+ 'application/binary'
+ )
end
+
metadata_attachment do
- FileHelpers.mock_uploaded_file name: "model.json", content_type: 'application/json', binary: true
+ Rack::Test::UploadedFile.new(
+ File.join(Rails.root, "modules/ifc_models/spec/fixtures/files/minimal.json"),
+ 'application/json'
+ )
end
end
end
diff --git a/modules/ifc_models/spec/features/model_viewer_spec.rb b/modules/ifc_models/spec/features/model_viewer_spec.rb
new file mode 100644
index 00000000000..f0d5a6078a9
--- /dev/null
+++ b/modules/ifc_models/spec/features/model_viewer_spec.rb
@@ -0,0 +1,106 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2020 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2017 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+
+require 'spec_helper'
+
+require_relative '../support/pages/ifc_models/show'
+
+describe 'model viewer', type: :feature, js: true do
+ let(:project) { FactoryBot.create :project }
+ let(:role) { FactoryBot.create(:role, permissions: %i[view_ifc_models manage_ifc_models]) }
+ let(:view_role) { FactoryBot.create(:role, permissions: %i[view_ifc_models]) }
+ let(:no_permissions_role) { FactoryBot.create(:role, permissions: %i[]) }
+
+ let(:user) { FactoryBot.create :user,
+ member_in_project: project,
+ member_through_role: role }
+
+ let(:view_user) { FactoryBot.create :user,
+ member_in_project: project,
+ member_through_role: view_role }
+
+ let(:user_without_permissions) { FactoryBot.create :user,
+ member_in_project: project,
+ member_through_role: no_permissions_role }
+
+ let(:model) { FactoryBot.create(:ifc_model_converted,
+ project: project,
+ uploader: user) }
+
+ let(:show_model_page) { Pages::IfcModels::Show.new(project, model.id) }
+
+ context 'with all permissions' do
+ before do
+ login_as(user)
+ end
+
+ it 'loads and shows the viewer correctly' do
+ show_model_page.visit!
+ show_model_page.finished_loading
+
+ show_model_page.model_viewer_visible true
+ show_model_page.model_viewer_shows_a_toolbar true
+ show_model_page.page_shows_a_toolbar true
+ show_model_page.sidebar_shows_viewer_menu true
+ end
+ end
+
+ context 'with only viewing permissions' do
+ before do
+ login_as(view_user)
+ end
+
+ it 'loads and shows the viewer correctly' do
+ show_model_page.visit!
+ show_model_page.finished_loading
+
+ show_model_page.model_viewer_visible true
+ show_model_page.model_viewer_shows_a_toolbar true
+ show_model_page.page_shows_a_toolbar false
+ show_model_page.sidebar_shows_viewer_menu true
+ end
+ end
+
+ context 'without any permissions' do
+ before do
+ login_as(user_without_permissions)
+ end
+
+ it 'shows no viewer' do
+ show_model_page.visit!
+
+ expected = '[Error 403] You are not authorized to access this page.'
+ expect(page).to have_selector('.notification-box.-error', text: expected)
+
+ show_model_page.model_viewer_visible false
+ show_model_page.model_viewer_shows_a_toolbar false
+ show_model_page.page_shows_a_toolbar false
+ show_model_page.sidebar_shows_viewer_menu false
+ end
+ end
+end
diff --git a/modules/ifc_models/spec/services/ifc_models/set_attributes_service_spec.rb b/modules/ifc_models/spec/services/ifc_models/set_attributes_service_spec.rb
index 019f76f3753..6957a1db7a2 100644
--- a/modules/ifc_models/spec/services/ifc_models/set_attributes_service_spec.rb
+++ b/modules/ifc_models/spec/services/ifc_models/set_attributes_service_spec.rb
@@ -73,7 +73,6 @@ describe IFCModels::SetAttributesService, type: :model do
describe 'call' do
let(:call_attributes) do
{
- is_default: true,
project_id: project.id
}
end
diff --git a/modules/ifc_models/spec/support/pages/ifc_models/show.rb b/modules/ifc_models/spec/support/pages/ifc_models/show.rb
new file mode 100644
index 00000000000..190737d7e5c
--- /dev/null
+++ b/modules/ifc_models/spec/support/pages/ifc_models/show.rb
@@ -0,0 +1,86 @@
+#-- copyright
+# OpenProject is an open source project management software.
+# Copyright (C) 2012-2020 the OpenProject GmbH
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License version 3.
+#
+# OpenProject is a fork of ChiliProject, which is a fork of Redmine. The copyright follows:
+# Copyright (C) 2006-2017 Jean-Philippe Lang
+# Copyright (C) 2010-2013 the ChiliProject Team
+#
+# This program is free software; you can redistribute it and/or
+# modify it under the terms of the GNU General Public License
+# as published by the Free Software Foundation; either version 2
+# of the License, or (at your option) any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# See docs/COPYRIGHT.rdoc for more details.
+#++
+
+require 'support/pages/page'
+
+module Pages
+ module IfcModels
+ class Show < ::Pages::Page
+ attr_accessor :project, :id
+
+ def initialize(project, id)
+ self.project = project
+ self.id = id
+ end
+
+ def path
+ ifc_models_project_ifc_model_path(project, id)
+ end
+
+ def finished_loading
+ expect(page).to have_no_selector('.xeokit-busy-modal', visible: true)
+ end
+
+ def model_viewer_visible(visible)
+ selector = '.ifc-model-viewer--model-canvas'
+ expect(page).to (visible ? have_selector(selector) : have_no_selector(selector))
+ end
+
+ def model_viewer_shows_a_toolbar(visible)
+ selector = '.xeokit-btn'
+
+ if visible
+ within ('.ifc-model-viewer--toolbar-container') do
+ expect(page).to have_selector(selector, count: 8)
+ end
+ else
+ expect(page).to have_no_selector(selector)
+ expect(page).to have_no_selector('.ifc-model-viewer--toolbar-container')
+ end
+ end
+
+ def sidebar_shows_viewer_menu(visible)
+ selector = '.xeokit-tab'
+ tabs = ['Models', 'Objects', 'Classes', 'Storeys']
+
+ tabs.each do |tab|
+ expect(page).to (visible ? have_selector(selector, text: tab) : have_no_selector(selector, text: tab))
+ end
+ end
+
+ def page_shows_a_toolbar(visible)
+ selector = '.toolbar-item'
+ buttons = ['Edit', 'Delete']
+
+ buttons.each do |button|
+ expect(page).to (visible ? have_selector(selector, text: button) : have_no_selector(selector, text: button))
+ end
+ end
+ end
+ end
+end