Skip to content

Commit

Permalink
fix(test): adjust duplication test and remove source courses list
Browse files Browse the repository at this point in the history
- due to change in the UI for duplication page
- source course button needs to be removed
  • Loading branch information
bivanalhar committed Aug 8, 2024
1 parent e5317ff commit 8c9f8cd
Show file tree
Hide file tree
Showing 7 changed files with 12 additions and 39 deletions.
13 changes: 0 additions & 13 deletions app/controllers/course/object_duplications_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ class Course::ObjectDuplicationsController < Course::ComponentController
helper Course::Achievement::AchievementsHelper

def new
load_source_courses_data
load_destination_courses_data
load_items_data
load_destination_instances_data
Expand All @@ -25,18 +24,6 @@ def authorize_duplication

private

def load_source_courses_data
ActsAsTenant.without_tenant do
# Workaround to get Courses where current user is allowed to duplicate contents from
# without having to use accessible_by, which can take up to 5 minutes with includes
course_copiers = CourseUser.where(user: current_user).
where(role: CourseUser::MANAGER_ROLES.to_a) +
CourseUser.where(user: current_user).
where(role: :observer)
@source_courses = Course.includes(:instance).find(course_copiers.map(&:course_id))
end
end

def load_destination_courses_data
ActsAsTenant.without_tenant do
# Workaround to get Courses where current user plays one of manager roles
Expand Down
2 changes: 0 additions & 2 deletions app/views/course/object_duplications/data.json.jbuilder

This file was deleted.

5 changes: 0 additions & 5 deletions app/views/course/object_duplications/new.json.jbuilder
Original file line number Diff line number Diff line change
@@ -1,11 +1,6 @@
# frozen_string_literal: true
json.currentHost current_tenant.host

json.sourceCourses @source_courses do |course|
json.(course, :id, :title)
json.host course.instance.host
end

json.destinationCourses @destination_courses do |course|
json.(course, :id, :title)
json.path course_path(course)
Expand Down
1 change: 0 additions & 1 deletion client/app/api/course/Duplication.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ export default class DuplicationAPI extends BaseCourseAPI {
* currentHost: string,
* destinationCourses: Array.<courseShape>,
* destinationInstances: Array.<instanceShape>,
* sourceCourses: courseListingShape,
* sourceCourse: sourceCourseShape,
* assessmentComponent: Array.<categoryShape>,
* surveyComponent: Array.<surveyShape>,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ const styles = {
};

class ItemsSelectorMenu extends Component {
renderSidebarItem(panelKey, titleKey, count) {
renderSidebarItem(panelKey, titleKey, count, className) {
const { dispatch, enabledComponents } = this.props;
if (!enabledComponents.includes(panelKey)) {
return null;
Expand All @@ -58,6 +58,7 @@ class ItemsSelectorMenu extends Component {
return (
<ListItem
button
className={className}
onClick={() => dispatch(actions.setItemSelectorPanel(panelKey))}
>
<ListItemAvatar>
Expand Down Expand Up @@ -105,34 +106,39 @@ class ItemsSelectorMenu extends Component {
panels.ASSESSMENTS,
'course_assessments_component',
assessmentsComponentCount,
'items-selector-menu-assessment',
)}
{unduplicableObjectTypes.includes('SURVEY')
? null
: this.renderSidebarItem(
panels.SURVEYS,
'course_survey_component',
counts[SURVEY],
'items-selector-menu-survey',
)}
{unduplicableObjectTypes.includes('ACHIEVEMENT')
? null
: this.renderSidebarItem(
panels.ACHIEVEMENTS,
'course_achievements_component',
counts[ACHIEVEMENT],
'items-selector-menu-achievement',
)}
{unduplicableObjectTypes.includes('MATERIAL')
? null
: this.renderSidebarItem(
panels.MATERIALS,
'course_materials_component',
counts[FOLDER] + counts[MATERIAL],
'items-selector-menu-material',
)}
{unduplicableObjectTypes.includes('VIDEO')
? null
: this.renderSidebarItem(
panels.VIDEOS,
'course_videos_component',
videosComponentCount,
'items-selector-menu-video',
)}
<ListItem style={styles.duplicateButton}>
<DuplicateButton />
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ import PropTypes from 'prop-types';

import { duplicationModes } from 'course/duplication/constants';
import { fetchObjectsList } from 'course/duplication/operations';
import {
courseListingShape,
sourceCourseShape,
} from 'course/duplication/propTypes';
import { sourceCourseShape } from 'course/duplication/propTypes';
import { actions } from 'course/duplication/store';
import Page from 'lib/components/core/layouts/Page';
import LoadingIndicator from 'lib/components/core/LoadingIndicator';
Expand Down Expand Up @@ -229,7 +226,6 @@ Duplication.propTypes = {
currentHost: PropTypes.string.isRequired,
currentCourseId: PropTypes.number,
sourceCourse: sourceCourseShape.isRequired,
sourceCourses: courseListingShape,

dispatch: PropTypes.func.isRequired,
intl: PropTypes.object,
Expand All @@ -248,7 +244,6 @@ export default Object.assign(
currentHost: duplication.currentHost,
currentCourseId: duplication.currentCourseId,
sourceCourse: duplication.sourceCourse,
sourceCourses: duplication.sourceCourses,
}))(injectIntl(Duplication)),
{ handle },
);
15 changes: 4 additions & 11 deletions spec/features/course/duplication_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@
expect(find_sidebar).to have_text(I18n.t('layouts.duplication.title'))
end

context 'when I am a manager in another course' do
context 'when I am a manager in one specific course' do
let(:source_course) { create(:course) }
let!(:course_user) { create(:course_manager, course: source_course, user: user) }
let(:assessment_title1) { SecureRandom.hex }
Expand All @@ -58,17 +58,14 @@
end

scenario 'I can duplicate objects from that course' do
visit course_duplication_path(course)

find('.source-course-dropdown').click
find("[role='option']", text: source_course.title).click
visit course_duplication_path(source_course)

find("input[value='OBJECT']", visible: false).click

find('.destination-course-dropdown').click
find("[role='option']", text: course.title).click

find('.items-selector-menu span span', text: 'Assessments').click
find('.items-selector-menu-assessment', text: 'Assessments').click
find('label', text: assessment_title1).click
click_on 'Duplicate Items'
click_on 'Duplicate'
Expand All @@ -78,18 +75,14 @@
end

scenario 'I can duplicate the whole course' do
visit course_duplication_path(course)

find('.source-course-dropdown').click
find("[role='option']", text: source_course.title).click
visit course_duplication_path(source_course)

fill_in 'new_title', with: ''
fill_in 'new_title', with: new_course_title

click_on 'Duplicate Course'
click_on 'Continue'

expect(page).not_to have_css('.source-course-dropdown')
wait_for_job
duplicated_course = Course.find_by(title: new_course_title)
expect(duplicated_course).to be_present
Expand Down

0 comments on commit 8c9f8cd

Please sign in to comment.