From 1ef9f6c64f6e0a59ceb3b94ab98db1bd4037f57a Mon Sep 17 00:00:00 2001 From: Michaela Date: Thu, 16 Sep 2021 18:57:19 +0200 Subject: [PATCH 01/27] Add tests for recent lessons and quizzes sections --- .../__mocks__/useLearnerResources.js | 3 + .../views/HomePage/__tests__/HomePage.spec.js | 78 +++++++++++++++++++ .../learn/assets/src/views/HomePage/index.vue | 2 + 3 files changed, 83 insertions(+) diff --git a/kolibri/plugins/learn/assets/src/composables/__mocks__/useLearnerResources.js b/kolibri/plugins/learn/assets/src/composables/__mocks__/useLearnerResources.js index 7132a190c09..44251e2c171 100644 --- a/kolibri/plugins/learn/assets/src/composables/__mocks__/useLearnerResources.js +++ b/kolibri/plugins/learn/assets/src/composables/__mocks__/useLearnerResources.js @@ -33,11 +33,14 @@ const MOCK_DEFAULTS = { classes: [], + activeClassesLessons: [], + activeClassesQuizzes: [], resumableClassesQuizzes: [], resumableClassesResources: [], resumableNonClassesContentNodes: [], getClass: jest.fn(), getResumableContentNode: jest.fn(), + getClassLessonLink: jest.fn(), getClassQuizLink: jest.fn(), getClassResourceLink: jest.fn(), getTopicContentNodeLink: jest.fn(), diff --git a/kolibri/plugins/learn/assets/src/views/HomePage/__tests__/HomePage.spec.js b/kolibri/plugins/learn/assets/src/views/HomePage/__tests__/HomePage.spec.js index d1d6b615d20..c8f383a4ab9 100644 --- a/kolibri/plugins/learn/assets/src/views/HomePage/__tests__/HomePage.spec.js +++ b/kolibri/plugins/learn/assets/src/views/HomePage/__tests__/HomePage.spec.js @@ -47,6 +47,14 @@ function getContinueLearningSection(wrapper) { return wrapper.find('[data-test="continueLearning"]'); } +function getRecentLessonsSection(wrapper) { + return wrapper.find('[data-test="recentLessons"]'); +} + +function getRecentQuizzesSection(wrapper) { + return wrapper.find('[data-test="recentQuizzes"]'); +} + describe(`HomePage`, () => { beforeEach(() => { jest.clearAllMocks(); @@ -266,4 +274,74 @@ describe(`HomePage`, () => { }); }); }); + + describe(`"Recent lessons" section`, () => { + it(`the section is not displayed for a guest user`, () => { + const wrapper = makeWrapper(); + expect(getRecentLessonsSection(wrapper).exists()).toBe(false); + }); + + it(`the section is not displayed for a signed in user + who has no active lessons`, () => { + useUser.mockImplementation(() => useUserMock({ isUserLoggedIn: true })); + const wrapper = makeWrapper(); + expect(getRecentLessonsSection(wrapper).exists()).toBe(false); + }); + + it(`active lessons are displayed for a signed in user who has some`, () => { + useUser.mockImplementation(() => useUserMock({ isUserLoggedIn: true })); + useLearnerResources.mockImplementation(() => + useLearnerResourcesMock({ + activeClassesLessons: [ + { id: 'lesson-1', title: 'Lesson 1', is_active: true }, + { id: 'lesson-2', title: 'Lesson 2', is_active: true }, + ], + getClassLessonLink() { + return { path: '/class-lesson' }; + }, + }) + ); + const wrapper = makeWrapper(); + expect(getRecentLessonsSection(wrapper).exists()).toBe(true); + const links = getRecentLessonsSection(wrapper).findAll('a'); + expect(links.length).toBe(2); + expect(links.at(0).text()).toBe('Lesson 1'); + expect(links.at(1).text()).toBe('Lesson 2'); + }); + }); + + describe(`"Recent quizzes" section`, () => { + it(`the section is not displayed for a guest user`, () => { + const wrapper = makeWrapper(); + expect(getRecentQuizzesSection(wrapper).exists()).toBe(false); + }); + + it(`the section is not displayed for a signed in user + who has no active quizzes`, () => { + useUser.mockImplementation(() => useUserMock({ isUserLoggedIn: true })); + const wrapper = makeWrapper(); + expect(getRecentQuizzesSection(wrapper).exists()).toBe(false); + }); + + it(`active quizzes are displayed for a signed in user who has some`, () => { + useUser.mockImplementation(() => useUserMock({ isUserLoggedIn: true })); + useLearnerResources.mockImplementation(() => + useLearnerResourcesMock({ + activeClassesQuizzes: [ + { id: 'quiz-1', title: 'Quiz 1', active: true }, + { id: 'quiz-2', title: 'Quiz 2', active: true }, + ], + getClassQuizLink() { + return { path: '/class-quiz' }; + }, + }) + ); + const wrapper = makeWrapper(); + expect(getRecentQuizzesSection(wrapper).exists()).toBe(true); + const links = getRecentQuizzesSection(wrapper).findAll('a'); + expect(links.length).toBe(2); + expect(links.at(0).text()).toBe('Quiz 1'); + expect(links.at(1).text()).toBe('Quiz 2'); + }); + }); }); diff --git a/kolibri/plugins/learn/assets/src/views/HomePage/index.vue b/kolibri/plugins/learn/assets/src/views/HomePage/index.vue index eda5251f655..7afe3e760cf 100644 --- a/kolibri/plugins/learn/assets/src/views/HomePage/index.vue +++ b/kolibri/plugins/learn/assets/src/views/HomePage/index.vue @@ -20,6 +20,7 @@ :lessons="activeClassesLessons" displayClassName recent + data-test="recentLessons" /> - + @@ -48,6 +46,7 @@ import { computed } from 'kolibri.lib.vueCompositionApi'; import { get } from '@vueuse/core'; + import useChannels from '../../composables/useChannels'; import useDeviceSettings from '../../composables/useDeviceSettings'; import useLearnerResources from '../../composables/useLearnerResources'; import useUser from '../../composables/useUser'; @@ -75,6 +74,7 @@ setup() { const { isUserLoggedIn } = useUser(); const { canAccessUnassignedContent } = useDeviceSettings(); + const { channels } = useChannels(); const { classes, activeClassesLessons, @@ -105,9 +105,19 @@ () => get(isUserLoggedIn) && get(activeClassesQuizzes) && get(activeClassesQuizzes).length > 0 ); + const hasChannels = computed(() => { + return get(channels) && get(channels).length > 0; + }); + const displayExploreChannels = computed(() => { + return ( + get(hasChannels) && + (!get(isUserLoggedIn) || (!get(canResumeClasses) && get(canAccessUnassignedContent))) + ); + }); return { isUserLoggedIn, + channels, classes, activeClassesLessons, activeClassesQuizzes, @@ -116,6 +126,7 @@ canResumeClasses, continueLearningFromClasses, continueLearningOnYourOwn, + displayExploreChannels, }; }, }; diff --git a/kolibri/plugins/learn/assets/src/views/cards/BaseChannelCard.vue b/kolibri/plugins/learn/assets/src/views/cards/BaseChannelCard.vue new file mode 100644 index 00000000000..e581b030519 --- /dev/null +++ b/kolibri/plugins/learn/assets/src/views/cards/BaseChannelCard.vue @@ -0,0 +1,99 @@ + + + + + + + diff --git a/kolibri/plugins/learn/assets/src/views/cards/LessonCard/index.vue b/kolibri/plugins/learn/assets/src/views/cards/LessonCard/index.vue index 48f47f6e410..b218e75d052 100644 --- a/kolibri/plugins/learn/assets/src/views/cards/LessonCard/index.vue +++ b/kolibri/plugins/learn/assets/src/views/cards/LessonCard/index.vue @@ -1,6 +1,9 @@ diff --git a/kolibri/plugins/learn/assets/src/views/cards/QuizCard/index.vue b/kolibri/plugins/learn/assets/src/views/cards/QuizCard/index.vue index ddaad30e31b..fa90199de58 100644 --- a/kolibri/plugins/learn/assets/src/views/cards/QuizCard/index.vue +++ b/kolibri/plugins/learn/assets/src/views/cards/QuizCard/index.vue @@ -1,6 +1,9 @@