Commit 88192fd4 by Adam Committed by Awais

Revert "Revert "Adding background image for xseries certificates on dashboard side bar panel""

parent 47e4804b
...@@ -14,6 +14,8 @@ from edx_oauth2_provider.tests.factories import ClientFactory ...@@ -14,6 +14,8 @@ from edx_oauth2_provider.tests.factories import ClientFactory
from opaque_keys.edx import locator from opaque_keys.edx import locator
from provider.constants import CONFIDENTIAL from provider.constants import CONFIDENTIAL
from openedx.core.djangoapps.credentials.models import CredentialsApiConfig
from openedx.core.djangoapps.credentials.tests.mixins import CredentialsDataMixin, CredentialsApiConfigMixin
from openedx.core.djangoapps.programs.tests.mixins import ( from openedx.core.djangoapps.programs.tests.mixins import (
ProgramsApiConfigMixin, ProgramsApiConfigMixin,
ProgramsDataMixin) ProgramsDataMixin)
...@@ -29,7 +31,9 @@ from xmodule.modulestore.tests.factories import CourseFactory ...@@ -29,7 +31,9 @@ from xmodule.modulestore.tests.factories import CourseFactory
class TestProgramListing( class TestProgramListing(
ModuleStoreTestCase, ModuleStoreTestCase,
ProgramsApiConfigMixin, ProgramsApiConfigMixin,
ProgramsDataMixin): ProgramsDataMixin,
CredentialsDataMixin,
CredentialsApiConfigMixin):
""" """
Unit tests for getting the list of programs enrolled by a logged in user Unit tests for getting the list of programs enrolled by a logged in user
...@@ -41,6 +45,7 @@ class TestProgramListing( ...@@ -41,6 +45,7 @@ class TestProgramListing(
Add a student Add a student
""" """
super(TestProgramListing, self).setUp() super(TestProgramListing, self).setUp()
ClientFactory(name=CredentialsApiConfig.OAUTH2_CLIENT_NAME, client_type=CONFIDENTIAL)
ClientFactory(name=ProgramsApiConfig.OAUTH2_CLIENT_NAME, client_type=CONFIDENTIAL) ClientFactory(name=ProgramsApiConfig.OAUTH2_CLIENT_NAME, client_type=CONFIDENTIAL)
self.student = UserFactory() self.student = UserFactory()
self.create_programs_config(xseries_ad_enabled=True, program_listing_enabled=True) self.create_programs_config(xseries_ad_enabled=True, program_listing_enabled=True)
...@@ -139,3 +144,57 @@ class TestProgramListing( ...@@ -139,3 +144,57 @@ class TestProgramListing(
self.assertEqual(response.status_code, 302) self.assertEqual(response.status_code, 302)
self.assertIsInstance(response, HttpResponseRedirect) self.assertIsInstance(response, HttpResponseRedirect)
self.assertIn('login', response.url) # pylint: disable=no-member self.assertIn('login', response.url) # pylint: disable=no-member
def _expected_credetials_data(self):
""" Dry method for getting expected credentials."""
return [
{
"display_name": "Test Program A",
"credential_url": "http://credentials.edx.org/credentials/dummy-uuid-1/"
},
{
"display_name": "Test Program B",
"credential_url": "http://credentials.edx.org/credentials/dummy-uuid-2/"
}
]
@httpretty.activate
def test_get_xseries_certificates_with_data(self):
self.create_programs_config(program_listing_enabled=True)
self.create_credentials_config(is_learner_issuance_enabled=True)
self.client.login(username=self.student.username, password=self.PASSWORD)
# mock programs and credentials apis
self.mock_programs_api()
self.mock_credentials_api(self.student, data=self.CREDENTIALS_API_RESPONSE, reset_url=False)
response = self.client.get(reverse("program_listing_view"))
self.assertEqual(response.status_code, 200)
for certificate in self._expected_credetials_data():
self.assertIn(certificate['display_name'], response.content)
self.assertIn(certificate['credential_url'], response.content)
self.assertIn('images/xseries-certificate-visual.png', response.content)
@httpretty.activate
def test_get_xseries_certificates_without_data(self):
self.create_programs_config(program_listing_enabled=True)
self.create_credentials_config(is_learner_issuance_enabled=True)
self.client.login(username=self.student.username, password=self.PASSWORD)
# mock programs and credentials apis
self.mock_programs_api()
self.mock_credentials_api(self.student, data={"results": []}, reset_url=False)
response = self.client.get(reverse("program_listing_view"))
self.assertEqual(response.status_code, 200)
for certificate in self._expected_credetials_data():
self.assertNotIn(certificate['display_name'], response.content)
self.assertNotIn(certificate['credential_url'], response.content)
...@@ -9,7 +9,7 @@ from django.http import Http404 ...@@ -9,7 +9,7 @@ from django.http import Http404
from edxmako.shortcuts import render_to_response from edxmako.shortcuts import render_to_response
from openedx.core.djangoapps.programs.utils import get_engaged_programs from openedx.core.djangoapps.programs.utils import get_engaged_programs
from openedx.core.djangoapps.programs.models import ProgramsApiConfig from openedx.core.djangoapps.programs.models import ProgramsApiConfig
from student.views import get_course_enrollments from student.views import get_course_enrollments, _get_xseries_credentials
@login_required @login_required
...@@ -35,5 +35,6 @@ def view_programs(request): ...@@ -35,5 +35,6 @@ def view_programs(request):
'programs': programs, 'programs': programs,
'xseries_url': marketing_root if ProgramsApiConfig.current().show_xseries_ad else None, 'xseries_url': marketing_root if ProgramsApiConfig.current().show_xseries_ad else None,
'nav_hidden': True, 'nav_hidden': True,
'show_program_listing': show_program_listing 'show_program_listing': show_program_listing,
'credentials': _get_xseries_credentials(request.user)
}) })
;(function (define) {
'use strict';
define(['backbone',
'jquery',
'underscore',
'gettext',
'text!../../../templates/learner_dashboard/certificate.underscore'
],
function(
Backbone,
$,
_,
gettext,
certificateTpl
) {
return Backbone.View.extend({
el: '.certificates-list',
tpl: _.template(certificateTpl),
initialize: function(data) {
this.context = data.context;
this.render();
},
render: function() {
if (this.context.certificatesData.length > 0) {
this.$el.html(this.tpl(this.context));
}
}
});
}
);
}).call(this, define || RequireJS.define);
...@@ -6,6 +6,7 @@ ...@@ -6,6 +6,7 @@
'underscore', 'underscore',
'gettext', 'gettext',
'js/learner_dashboard/views/explore_new_programs_view', 'js/learner_dashboard/views/explore_new_programs_view',
'js/learner_dashboard/views/certificate_view',
'text!../../../templates/learner_dashboard/sidebar.underscore' 'text!../../../templates/learner_dashboard/sidebar.underscore'
], ],
function( function(
...@@ -14,6 +15,7 @@ ...@@ -14,6 +15,7 @@
_, _,
gettext, gettext,
NewProgramsView, NewProgramsView,
CertificateView,
sidebarTpl sidebarTpl
) { ) {
return Backbone.View.extend({ return Backbone.View.extend({
...@@ -34,6 +36,10 @@ ...@@ -34,6 +36,10 @@
this.newProgramsView = new NewProgramsView({ this.newProgramsView = new NewProgramsView({
context: this.context context: this.context
}); });
this.newCertificateView = new CertificateView({
context: this.context
});
} }
}); });
} }
......
define([
'backbone',
'jquery',
'js/learner_dashboard/views/certificate_view'
], function (Backbone, $, CertificateView) {
'use strict';
describe('Certificate View', function () {
var view = null,
data = {
context: {
certificatesData: [
{
"display_name": "Testing",
"credential_url": "https://credentials.stage.edx.org/credentials/dummy-uuid-1/"
},
{
"display_name": "Testing2",
"credential_url": "https://credentials.stage.edx.org/credentials/dummy-uuid-2/"
}
],
xseriesImage: "/images/testing.png"
}
};
beforeEach(function() {
setFixtures('<div class="certificates-list"></div>');
view = new CertificateView(data);
view.render();
});
afterEach(function() {
view.remove();
});
it('should exist', function() {
expect(view).toBeDefined();
});
it('should load the certificates based on passed in certificates list', function() {
var $certificates = view.$el.find('.certificate-box');
expect($certificates.length).toBe(2);
$certificates.each(function(index, el){
expect($(el).html().trim()).toEqual(data.context.certificatesData[index].display_name);
expect($(el).attr('href')).toEqual(data.context.certificatesData[index].credential_url);
});
expect(view.$el.find('.title').html().trim()).toEqual('XSeries Program Certificates:');
expect(view.$el.find('img').attr('src')).toEqual('/images/testing.png');
});
it('should display no certificate box if certificates list is empty', function() {
var $certificate;
view.remove();
setFixtures('<div class="certificates-list"></div>');
view = new CertificateView({
context: {certificatesData: []}
});
view.render();
$certificate = view.$el.find('.certificate-box');
expect($certificate.length).toBe(0);
});
});
}
);
...@@ -10,7 +10,14 @@ define([ ...@@ -10,7 +10,14 @@ define([
describe('Sidebar View', function () { describe('Sidebar View', function () {
var view = null, var view = null,
context = { context = {
xseriesUrl: 'http://www.edx.org/xseries' xseriesUrl: 'http://www.edx.org/xseries',
certificatesData: [
{
"display_name": "Testing",
"credential_url": "https://credentials.stage.edx.org/credentials/dummy-uuid-1/"
}
],
xseriesImage: '/image/test.png'
}; };
beforeEach(function() { beforeEach(function() {
...@@ -38,17 +45,23 @@ define([ ...@@ -38,17 +45,23 @@ define([
expect($sidebar.find('.program-advertise .ad-link a').attr('href')).toEqual(context.xseriesUrl); expect($sidebar.find('.program-advertise .ad-link a').attr('href')).toEqual(context.xseriesUrl);
}); });
it('should load the certificates based on passed in certificates list', function() {
expect(view.$('.certificate-box').length).toBe(1);
});
it('should not load the xseries advertising if no xseriesUrl passed in', function(){ it('should not load the xseries advertising if no xseriesUrl passed in', function(){
var $ad; var $ad;
view.remove(); view.remove();
view = new SidebarView({ view = new SidebarView({
el: '.sidebar', el: '.sidebar',
context: {} context: {certificatesData: []}
}); });
view.render(); view.render();
$ad = view.$el.find('.program-advertise'); $ad = view.$el.find('.program-advertise');
expect($ad.length).toBe(0); expect($ad.length).toBe(0);
expect(view.$('.certificate-box').length).toBe(0);
}); });
}); });
} }
); );
...@@ -754,7 +754,8 @@ ...@@ -754,7 +754,8 @@
'lms/include/js/spec/markdown_editor_spec.js', 'lms/include/js/spec/markdown_editor_spec.js',
'lms/include/js/spec/learner_dashboard/collection_list_view_spec.js', 'lms/include/js/spec/learner_dashboard/collection_list_view_spec.js',
'lms/include/js/spec/learner_dashboard/sidebar_view_spec.js', 'lms/include/js/spec/learner_dashboard/sidebar_view_spec.js',
'lms/include/js/spec/learner_dashboard/program_card_view_spec.js' 'lms/include/js/spec/learner_dashboard/program_card_view_spec.js',
'lms/include/js/spec/learner_dashboard/certificate_view_spec.js'
]); ]);
}).call(this, requirejs, define); }).call(this, requirejs, define);
...@@ -59,6 +59,7 @@ ...@@ -59,6 +59,7 @@
@import "views/financial-assistance"; @import "views/financial-assistance";
@import 'views/bookmarks'; @import 'views/bookmarks';
@import 'course/auto-cert'; @import 'course/auto-cert';
@import 'xseries_certificates';
@import 'views/program-list'; @import 'views/program-list';
@import 'views/api-access'; @import 'views/api-access';
......
@mixin xseries-certificate-container {
border: 1px solid $gray-l3;
box-sizing: border-box;
padding: $baseline;
background: $gray-l6;
margin-top: $baseline;
.title{
@extend %t-title6;
@extend %t-weight3;
margin-bottom:$baseline;
color: $gray;
}
.certificate-box{
padding-top: $baseline;
display: block;
}
}
...@@ -19,6 +19,11 @@ $pl-button-color: #0079bc; ...@@ -19,6 +19,11 @@ $pl-button-color: #0079bc;
.sidebar{ .sidebar{
@include outer-container; @include outer-container;
@include span-columns(12); @include span-columns(12);
@include float(right);
margin-bottom: $baseline;
.certificate-container{
@include xseries-certificate-container();
}
.program-advertise{ .program-advertise{
padding: $baseline; padding: $baseline;
background-color: $body-bg; background-color: $body-bg;
......
<div class="certificate-container">
<p class="title"><%- gettext('XSeries Program Certificates') %>:</p>
<img src="<%- xseriesImage %>" alt="">
<% _.each(certificatesData, function(certificate){ %>
<a class="certificate-box" href="<%- gettext(certificate.credential_url) %>"><%- gettext(certificate.display_name) %></a>
<% }); %>
</div>
...@@ -12,7 +12,9 @@ from openedx.core.djangolib.js_utils import ( ...@@ -12,7 +12,9 @@ from openedx.core.djangolib.js_utils import (
<%static:require_module module_name="js/learner_dashboard/program_list_factory" class_name="ProgramListFactory"> <%static:require_module module_name="js/learner_dashboard/program_list_factory" class_name="ProgramListFactory">
ProgramListFactory({ ProgramListFactory({
programsData: ${programs | n, dump_js_escaped_json}, programsData: ${programs | n, dump_js_escaped_json},
xseriesUrl: '${xseries_url | n, js_escaped_string}' certificatesData: ${credentials | n, dump_js_escaped_json},
xseriesUrl: '${xseries_url | n, js_escaped_string}',
xseriesImage: '${static.url('images/xseries-certificate-visual.png')}'
}); });
</%static:require_module> </%static:require_module>
</%block> </%block>
......
<div class="program-advertise"></div> <div class="program-advertise"></div>
<div class="certificate-container"></div> <div class="certificates-list"></div>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment