Skip to content

Commit

Permalink
Updated tests and missing instance
Browse files Browse the repository at this point in the history
  • Loading branch information
dougmartin committed Jul 20, 2023
1 parent d47e9f0 commit bc5345f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 2 deletions.
9 changes: 7 additions & 2 deletions rails/spec/libs/materials/data_helpers_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@ class DataHelpersTestController < ApplicationController
is_locked: false,
teacher_copyable: true,
teacher_resources_url: host + '/teacher-resources',
teacher_guide_url: host + '/teacher-guide'
teacher_guide_url: host + '/teacher-guide',
rubric_doc_url: host + '/rubric-doc'
)
}
let(:materials) { [material_a] }
Expand Down Expand Up @@ -159,22 +160,26 @@ class DataHelpersTestController < ApplicationController
expect(external_edit_iframe[:url]).not_to be_empty
end

it "should return values for teacher resource and teacher guide if a teacher is logged in" do
it "should return values for teacher resource, teacher guide and rubric if a teacher is logged in" do
sign_in teacher_user.user
links = controller.send(:links_for_material, material_a)
teacher_resources = links[:teacher_resources]
teacher_guide = links[:teacher_guide]
rubric_doc = links[:rubric_doc]
expect(teacher_resources).not_to be_empty
expect(teacher_guide).not_to be_empty
expect(rubric_doc).not_to be_empty
end

it "should not return values for teacher resource and teacher guide to guests" do
sign_in guest
links = controller.send(:links_for_material, material_a)
teacher_resources = links[:teacher_resources]
teacher_guide = links[:teacher_guide]
rubric_doc = links[:rubric_doc]
expect(teacher_resources).to be_nil
expect(teacher_guide).to be_nil
expect(rubric_doc).to be_nil
end
end

Expand Down
9 changes: 9 additions & 0 deletions react-components/src/library/components/resource-lightbox.js
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,14 @@ var ResourceLightbox = Component({
})
},

handleRubricDocClick: function (e) {
const resource = this.state.resource
gtag('event', 'click', {
'category': 'Rubric Doc Link',
'resource': resource.name
})
},

handleAddToCollectionClick: function (e) {
const resource = this.state.resource
gtag('event', 'click', {
Expand Down Expand Up @@ -380,6 +388,7 @@ var ResourceLightbox = Component({
return (
<span>
{Portal.currentUser.isTeacher && resource.has_teacher_edition ? <a className='teacherEditionLink portal-pages-secondary-button' href={MakeTeacherEditionLink(resource.external_url)} target='_blank' onClick={this.handleTeacherEditionClick}>Teacher Edition</a> : null}
{links.rubric_doc ? <a className='portal-pages-secondary-button' href={links.rubric_doc.url} target='_blank' onClick={this.handleRubricDocClick}>{links.rubric_doc.text}</a> : null}
{links.teacher_resources && showTeacherResourcesButton ? <a className='teacherResourcesLink portal-pages-secondary-button' href={links.teacher_resources.url} target='_blank' onClick={this.handleTeacherResourcesClick}>{links.teacher_resources.text}</a> : null}
{links.assign_material ? <a id={'assign-button'} className='portal-pages-secondary-button' href={`javascript: ${links.assign_material.onclick}`} onClick={this.handleAssignClick}>{links.assign_material.text}</a> : null}
{links.assign_collection ? <a className='portal-pages-secondary-button' href={`${links.assign_collection.url}`} onClick={this.handleAddToCollectionClick} target='_blank'>{links.assign_collection.text}</a> : null}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,10 @@ describe('When I try to render search material info', () => {
url: "http://example.com/teacher_guide",
text: "teacher_guide text"
},
rubric_doc: {
url: "http://example.com/rubric_doc",
text: "rubric_doc text"
},
assign_material: {
url: "http://example.com/assign_material",
text: "assign_material text"
Expand Down Expand Up @@ -134,6 +138,9 @@ describe('When I try to render search material info', () => {
<div style="float:right;margin-right:5px">
<a href="http://example.com/teacher_guide" class="button">teacher_guide text</a>
</div>
<div style="float:right;margin-right:5px">
<a href="http://example.com/rubric_doc" class="button">rubric_doc text</a>
</div>
<div style="float:right;margin-right:5px">
<a href="http://example.com/assign_material" class="button">assign_material text</a>
</div>
Expand Down

0 comments on commit bc5345f

Please sign in to comment.