Skip to content
This repository has been archived by the owner on Sep 16, 2022. It is now read-only.

Added test for courses page and lesson content #175

Merged
merged 6 commits into from
Apr 12, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,13 @@ jobs:
- run:
name: Prepare project with anu_lms in the codebase
working_directory: anu_drupal
# TODO: When install dev-dependencies from main composer.json.
# Moving the project to Drupal.org will remove the need to do this.
command: |
composer config repositories.systemseed/anu_lms path ../anu_lms && \
composer config minimum-stability dev && \
composer require "systemseed/anu_lms:*@dev" && \
composer require --dev drupal/core-dev:^9 && \
composer require --dev drupal/core-dev:^9 drupal/pathauto && \
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How should we install on local for running tests? I tried composer -- require systemseed/anu_lms:dev-js-tests --prefer-source and it did NOT download pathauto. I had to manually install it.

Copy link
Contributor Author

@rodrigoaguilera rodrigoaguilera Apr 12, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not a simple issue. Drupalci somehow downloads the dev-dependencies of a module for testing. We are trying to emulate what drupalci does which I believe is not open source.

I think this situation will be different with the change from drupalci to gitlabci. It will draw inspiration and code from drupalspoons.
https://gitlab.com/drupalspoons/webmasters/-/tree/master/#local-development

So the main idea is that we shouldn't be installing anu_lms as part of another project (such as basilio) to develop it but anu_lms should spawn its own drupal site, therefore the dev-dependencies will be downloaded since it will be a composer install in the root of the anu_lms project.
This means that composer -- require systemseed/anu_lms:dev-js-tests --prefer-source can't be used for the development of anu_lms as it will NEVER pull the dev dependencies. Only when anu_lms is the root project.

This line in the circleci is just a patch before deciding to move to drupal.org. Added a comment to clarify

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting info, thanks for sharing the details @rodrigoaguilera !

composer require --dev dealerdirect/phpcodesniffer-composer-installer && \
composer require --dev phpspec/prophecy-phpunit:^2
- run:
Expand All @@ -52,4 +54,4 @@ jobs:
- run:
name: Run Drupal tests
working_directory: anu_drupal
command: php -S localhost:8888 -t web/ & chromedriver --whitelisted-ips --verbose & sleep 1 && vendor/bin/phpunit -c web/core/phpunit.xml.dist web/modules/contrib/anu_lms/tests
command: php -S localhost:8888 -t web/ & chromedriver --whitelisted-ips & sleep 1 && vendor/bin/phpunit -c web/core/phpunit.xml.dist web/modules/contrib/anu_lms/tests
15 changes: 8 additions & 7 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,16 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Upcoming release]
- Added "Anu LMS Demo content" module.
- Added path alias patterns for Anu LMS content types.
- Fixed no lesson error for quizzes.
- Added "Anu LMS Demo content" module.
- Added path alias patterns for Anu LMS content types.
- Added js-enabled basic testing.
- Fixed no lesson error for quizzes.

## [2.5.0-alpha]
- Move progress tracking to frontend and make progress available offline.
- Add new DownloadCoursePopup component that offers to download courses with or without audio (for courses with audios)
- Add a new isCompletedByUser helper method to lesson service.
- Track the date when a lesson is completed.
- Move progress tracking to frontend and make progress available offline.
- Add new DownloadCoursePopup component that offers to download courses with or without audio (for courses with audios)
- Add a new isCompletedByUser helper method to lesson service.
- Track the date when a lesson is completed.

## [2.4.13]
- Fixed checkbox text wrap, so it is readable and go in multiple lines if text is longer
Expand Down
3 changes: 3 additions & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@
"drupal/xls_serialization": "^1.2",
"drupal/features": "^3.12"
},
"require-dev": {
"drupal/pathauto": "^1.9"
},
"suggest": {
"drupal/pwa": "Allows using Anu LMS offline."
},
Expand Down
2 changes: 1 addition & 1 deletion js/dist/lesson.min.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion js/dist/lesson.min.js.map

Large diffs are not rendered by default.

19 changes: 16 additions & 3 deletions js/src/components/ContentNavigation.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,25 +102,38 @@ const ContentNavigation = ({
<Button
{...buttonProps}
onClick={() => history.push({ pathname: `/section-${currentIndex + 2}` })}
data-test="anu-lms-navigation-next"
>
{disabled ? completeAnswer : Drupal.t('Next', {}, { context: 'ANU LMS' })}
</Button>
)}

{noNextLesson && nextIsLesson && (
<Button {...buttonProps} onClick={updateProgressAndRedirect}>
<Button
{...buttonProps}
onClick={updateProgressAndRedirect}
data-test="anu-lms-navigation-next"
>
{disabled ? completeAnswer : Drupal.t('Next', {}, { context: 'ANU LMS' })}
</Button>
)}

{noNextLesson && !nextIsLesson && !nextIsQuiz && (
<Button {...buttonProps} onClick={updateProgressAndRedirect}>
<Button
{...buttonProps}
onClick={updateProgressAndRedirect}
data-test="anu-lms-navigation-finish"
>
{disabled ? completeAnswer : finishButtonText(currentLesson)}
</Button>
)}

{noNextLesson && nextIsLesson && isIntro && (
<Button {...buttonProps} onClick={updateProgressAndRedirect}>
<Button
{...buttonProps}
onClick={updateProgressAndRedirect}
data-test="anu-lms-navigation-start"
>
{Drupal.t('Start', {}, { context: 'ANU LMS' })}
</Button>
)}
Expand Down
2 changes: 1 addition & 1 deletion js/src/components/List.js
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ const ListElement = ({ items, type }) => (
<StyledIcon fontSize="small">brightness_1</StyledIcon>
</ListItemIcon>

<ListItemText>
<ListItemText data-test="anu-lms-list-item-text">
<StyledTypography component="div" dangerouslySetInnerHTML={{ __html: item }} />
</ListItemText>
</StyledListItem>
Expand Down
4 changes: 3 additions & 1 deletion js/src/components/ParagraphHighlightFullWidth.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,9 @@ const ParagraphHighlightFullWidth = ({ title, text, color }) => {
<LessonGrid>
{title && (
<Box mb={2}>
<Typography className={classes.heading}>{title}</Typography>
<Typography className={classes.heading} data-test="anu-lms-highlight-heading">
{title}
</Typography>
</Box>
)}

Expand Down
7 changes: 6 additions & 1 deletion js/src/pages/lesson/NavigationItem.js
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,12 @@ const LessonNavigationItem = ({
};

return (
<Grid container wrap="nowrap" className={classes.item}>
<Grid
container
wrap="nowrap"
className={classes.item}
data-test={`anu-lms-navigation-item-status${isActive ? '-active' : ''}`}
>
<Grid item container alignItems="center" className={classes.circleWrapper}>
{/* Added to hide edges of the line which goes through lesson circles */}
{isFirstLesson && <Box className={classes.firstLessonBackground} />}
Expand Down
13 changes: 9 additions & 4 deletions modules/anu_lms_demo_content/anu_lms_demo_content.install
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,12 @@ use Drupal\Core\File\FileSystemInterface;
/**
* Implements hook_install().
*/
function anu_lms_demo_content_install() {
function anu_lms_demo_content_modules_installed($modules, $is_syncing) {
// Check for itself. This gives the opportunity for configuration
// to be installed such as pathauto patterns.
if (!in_array('anu_lms_demo_content', $modules)) {
return;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🔥

}
$categories = anu_lms_demo_create_course_categories();
[$first_category, $second_category] = $categories;
[$first_label, $second_label] = anu_lms_demo_create_course_labels();
Expand Down Expand Up @@ -452,7 +457,7 @@ function anu_lms_demo_create_course_for_testing_paragraphs($extra_data = []) {
'value' => 'This course contains all available lesson item types.',
'format' => 'minimal_html',
],
'field_course_finish_button' => ['uri' => 'internal:/anu-demo'],
'field_course_finish_button' => ['uri' => 'internal:/courses/courses-demo'],
'field_course_module' => array_values($default_module),
] + $extra_data;

Expand Down Expand Up @@ -552,7 +557,7 @@ function anu_lms_demo_create_course_for_testing_navigation($extra_data = []) {
'value' => 'This course contains multiple modules, lessons and sections.',
'format' => 'minimal_html',
],
'field_course_finish_button' => ['uri' => 'internal:/anu-demo'],
'field_course_finish_button' => ['uri' => 'internal:/courses/courses-demo'],
'field_course_module' => array_values($modules),
] + $extra_data;

Expand Down Expand Up @@ -592,7 +597,7 @@ function anu_lms_demo_create_courses_page($category_ids = []) {
$courses_page = [
'type' => 'courses_page',
'title' => 'Courses [DEMO]',
'path' => '/anu-demo',
'path' => '/courses/courses-demo',
'field_courses_content' => array_values($paragraphs),
];
anu_lms_demo_content_create_entities([$courses_page], 'node');
Expand Down
86 changes: 84 additions & 2 deletions tests/src/FunctionalJavascript/CoursesTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,10 @@ class CoursesTest extends WebDriverTestBase {
/**
* {@inheritdoc}
*/
protected static $modules = ['anu_lms_demo_content'];
protected static $modules = [
'pathauto',
'anu_lms_demo_content',
];

/**
* {@inheritdoc}
Expand All @@ -37,7 +40,7 @@ public function testCoursesPage() {
$assert = $this->assertSession();

// Get the main page.
$this->drupalGet('anu-demo');
$this->drupalGet('courses/courses-demo');
$categoryTitle = $assert->waitForElementVisible('css', '#anu-application h2');
$this->assertNotEmpty($categoryTitle);
$this->assertEqual($categoryTitle->getText(), 'Getting started [DEMO]');
Expand All @@ -46,6 +49,85 @@ public function testCoursesPage() {
$this->assertNotEmpty($courseTitle);
$this->assertEqual($courseTitle->getText(), 'Learn Anu lesson item types [DEMO]');
$courseTitle->click();

// After clicking on the title it should be inside the course.
$courseTitle = $assert->waitForElementVisible('css', '#anu-application h1');
$this->assertNotEmpty($courseTitle);
$this->assertEqual($courseTitle->getText(), 'Learn Anu lesson item types [DEMO]');

// Check for the second category.
$this->drupalGet('courses/courses-demo');
$anuApp = $assert->waitForElementVisible('css', '#anu-application');
$categoryTitles = $anuApp->findAll('css', 'h2');
$this->assertNotEmpty($categoryTitles);
$this->assertEqual($categoryTitles[1]->getText(), 'Developer guides [DEMO]');

$courseTitles = $anuApp->findAll('css', '#anu-application h3');
$this->assertNotEmpty($courseTitles);
$this->assertEqual($courseTitles[1]->getText(), 'Modules, lessons and sections [DEMO]');
$courseTitles[1]->click();

// After clicking on the title it should be inside the course.
$courseTitle = $assert->waitForElementVisible('css', '#anu-application h1');
$this->assertNotEmpty($courseTitle);
$this->assertEqual($courseTitle->getText(), 'Modules, lessons and sections [DEMO]');
}

/**
* Test lesson content.
*/
public function testLessons() {
$assert = $this->assertSession();
$this->drupalGet('lesson/headings');

// Inside the course. Check the sidebar active element.
$this->assertJsCondition('document.querySelector("#anu-application div[data-test=anu-lms-navigation-item-status-active]").textContent === "Headings"');

$headingThree = $assert->waitForElementVisible('css', '#anu-application h3');
$this->assertNotEmpty($headingThree);
$this->assertEqual($headingThree->getText(), 'Lesson heading - h3');

$assert->waitForElementVisible('css', '[data-test=anu-lms-navigation-next]')->click();
$lessonTitle = $assert->waitForElementVisible('css', '#anu-application h4');
$this->assertNotEmpty($lessonTitle);
$this->assertEqual($lessonTitle->getText(), 'Text');

$linkInBody = $assert->waitForElementVisible('css', 'a[href="https://github.com/systemseed/anu_lms"]');
$this->assertNotEmpty($linkInBody);
$this->assertEqual($linkInBody->getText(), 'Link to GitHub repository.');

$assert->waitForElementVisible('css', '[data-test=anu-lms-navigation-next]')->click();

$assert->waitForElementVisible('css', '#anu-application ul li');
// Check third item.
$this->assertJsCondition('document.querySelector("#anu-application ul li:nth-child(3) div[data-test=anu-lms-list-item-text]").textContent === "Vanilla"');

$assert->waitForElementVisible('css', '[data-test=anu-lms-navigation-next]')->click();

$image = $assert->waitForElementVisible('css', '#anu-application img');
$this->assertNotEmpty($image);
$this->assertEqual($image->getAttribute('alt'), 'Image with caption');

$assert->waitForElementVisible('css', '[data-test=anu-lms-navigation-next]')->click();

// Highlights.
$highlightHeading = $assert->waitForElementVisible('css', '#anu-application p[data-test=anu-lms-highlight-heading]');
$this->assertNotEmpty($highlightHeading);
$this->assertEqual($highlightHeading->getText(), 'Highlight (full width)');

$assert->waitForElementVisible('css', '[data-test=anu-lms-navigation-next]')->click();
// Dividers.
$assert->waitForElementVisible('css', '[data-test=anu-lms-navigation-next]')->click();
// Video.
$assert->waitForElementVisible('css', '[data-test=anu-lms-navigation-next]')->click();
// Checklists.
$assert->waitForElementVisible('css', '[data-test=anu-lms-navigation-next]')->click();
// Tables.
$assert->waitForElementVisible('css', '[data-test=anu-lms-navigation-finish]')->click();

// The course has a redirect configured for the courses page.
// Assert the redirect happened properly.
$assert->addressEquals('courses/courses-demo');
}

}