Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update stylings for footer in awaiting grade quizzes in learning mode #7190

Merged
merged 26 commits into from
Oct 2, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
8f0b645
Add button for awaiting grade quiz
Imran92 Sep 27, 2023
1122e7d
Add disabled button opacity for course theme
Imran92 Sep 27, 2023
3cf618a
Add disabled button opacity in compat themes
Imran92 Sep 27, 2023
7315515
Add stylings for disabled button in footer
Imran92 Sep 27, 2023
20541f4
Change decorations for Quiz restart button
Imran92 Sep 27, 2023
0d61148
Change text from Reset quiz to restart quiz
Imran92 Sep 27, 2023
d3195aa
Update color of reset quiz button
Imran92 Sep 27, 2023
b6210bc
Don't render lesson actions when in quiz awaiting grade
Imran92 Sep 27, 2023
dd1ec86
Show pending grade button when reset is not allowed
Imran92 Sep 27, 2023
66dc7c9
Fix spacing above footer for course theme
Imran92 Sep 27, 2023
036ce14
Fix spacing above footer for all compat themes
Imran92 Sep 27, 2023
940917c
Add semicolons in stylesheet
Imran92 Sep 27, 2023
5a50962
Remove extra specificity
Imran92 Sep 27, 2023
4a9df22
Add changelog
Imran92 Sep 27, 2023
2fe89e1
Merge branch 'trunk' into add/stylings-for-footer-in-awaiting-grade-q…
Imran92 Oct 2, 2023
a1986f9
return array of comments to fix psalm
Imran92 Oct 2, 2023
d37ebc3
Remove comment array return type
Imran92 Oct 2, 2023
58f0a41
Remove unnecessary array checks for graded lesson status
Imran92 Oct 2, 2023
8046828
Add function to check quiz awaiting status
Imran92 Oct 2, 2023
2b37b70
Use awaiting grade check function in lesson action
Imran92 Oct 2, 2023
7b3920f
Add test to check pending grade is rendered
Imran92 Oct 2, 2023
1c3ff85
Add test to check pending button not rendered for non LM
Imran92 Oct 2, 2023
fb0544a
Test that pending button is not rendered when lesson passed
Imran92 Oct 2, 2023
7836ed9
Test that pending button is not rendered when in progress
Imran92 Oct 2, 2023
5c867a1
Remove extra line
Imran92 Oct 2, 2023
1a27979
Fix lint issue
Imran92 Oct 2, 2023
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
36 changes: 23 additions & 13 deletions assets/css/3rd-party/themes/course/quiz.scss
Original file line number Diff line number Diff line change
Expand Up @@ -12,26 +12,36 @@
}
}
}

.wp-block-sensei-lms-quiz-actions {
button:disabled {
opacity: 0.4;
}
}

#sensei-quiz-list {
margin: 0 0 clamp(3.75rem, 2.5rem + 3.333vw, 5rem) 0;
}

.quiz {
.sensei-course-theme__quiz {
&__main-content {
.wp-block-post-title {
margin-bottom: 3.75rem;
}
}
&__footer {
.sensei-quiz-actions {
.sensei-quiz-action {
button {
padding: 1rem 32px;
}
}
.sensei-quiz-actions-secondary {
.sensei-quiz-action {
button {
font-family: var( --wp--preset--font-family--body );
}
}
}

.sensei-quiz-actions {
.sensei-quiz-action {
button {
padding: 1rem 32px;
}
}
.sensei-quiz-actions-secondary {
.sensei-quiz-action {
button {
font-family: var( --wp--preset--font-family--body );
}
}
}
Expand Down
6 changes: 5 additions & 1 deletion assets/css/frontend.scss
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,6 @@ a.sensei-certificate-link {
.quiz {
form {
#sensei-quiz-list {
margin: 0 0 1.618em 0;
list-style-position: inside;
list-style-type: none;
padding-inline-start: 0;
Expand Down Expand Up @@ -521,6 +520,11 @@ div.sensei-quiz-actions {
.sensei-quiz-action {
.button, button {
@include button-link;
text-decoration: none;

&:hover {
text-decoration: underline;
}
}
}
}
Expand Down
16 changes: 16 additions & 0 deletions assets/css/sensei-course-theme/quiz-compat.scss
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,22 @@ $textColor: #1E1E1E;
}
}

.wp-block-sensei-lms-quiz-actions {
button:disabled {
opacity: 0.6;
}

.sensei-quiz-actions-secondary {
.sensei-course-theme__button.is-link {
color: var(--sensei-primary-color);
}
}
}

#sensei-quiz-list {
margin: 0 0 3.75rem 0;
}

.quiz {
form {
#sensei-quiz-list {
Expand Down
8 changes: 8 additions & 0 deletions assets/css/sensei-course-theme/quiz.scss
Original file line number Diff line number Diff line change
Expand Up @@ -201,6 +201,14 @@ $vertical-spacing-desktop: 80px;
text-decoration: none;
}

.wp-block-sensei-lms-quiz-actions {
button:disabled {
cursor: not-allowed;
pointer-events: none;
width: auto;
}
}

.sensei-progress-bar {
&__bar {
height: 12px;
Expand Down
4 changes: 4 additions & 0 deletions changelog/add-stylings-for-footer-in-awaiting-grade-quiz-lm
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: minor
Type: changed

Changed footer style for quizzes awaiting grading
7 changes: 7 additions & 0 deletions includes/blocks/course-theme/class-lesson-actions.php
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,13 @@

$course_id = Sensei()->lesson->get_course_id( $lesson_id );

$is_learning_mode = \Sensei_Course_Theme_Option::has_learning_mode_enabled( $course_id );
$is_awaiting_grade = \Sensei_Quiz::is_quiz_awaiting_grade_for_user( $lesson_id, $user_id );

if ( $is_learning_mode && $is_awaiting_grade && 'quiz' === get_post_type() ) {
return '';

Check warning on line 168 in includes/blocks/course-theme/class-lesson-actions.php

View check run for this annotation

Codecov / codecov/patch

includes/blocks/course-theme/class-lesson-actions.php#L168

Added line #L168 was not covered by tests
}

if (
! Sensei_Course::is_user_enrolled( $course_id )
) {
Expand Down
44 changes: 41 additions & 3 deletions includes/class-sensei-quiz.php
Original file line number Diff line number Diff line change
Expand Up @@ -1856,14 +1856,20 @@
$lesson_id = Sensei()->quiz->get_lesson_id();
$is_quiz_completed = self::is_quiz_completed();
$is_reset_allowed = self::is_reset_allowed( $lesson_id );
$has_actions = $is_reset_allowed || ! $is_quiz_completed;
$course_id = Sensei()->lesson->get_course_id( $lesson_id );
$is_learning_mode = Sensei_Course_Theme_Option::has_learning_mode_enabled( $course_id );
$is_awaiting_grade = self::is_quiz_awaiting_grade_for_user( $lesson_id, get_current_user_id() );

$show_grade_pending_button = $is_learning_mode && $is_awaiting_grade;

$wrapper_attributes = get_block_wrapper_attributes(
[
'class' => 'sensei-quiz-actions',
]
);

$has_actions = $is_reset_allowed || ! $is_quiz_completed || $show_grade_pending_button;

if ( ! $has_actions ) {
return;
}
Expand Down Expand Up @@ -1898,11 +1904,17 @@
</div>
<?php endif ?>

<?php if ( $is_awaiting_grade && $is_learning_mode ) : ?>
<button type="button" class="wp-element-button sensei-course-theme__button is-primary" disabled>
<?php esc_attr_e( 'Pending teacher grade', 'sensei-lms' ); ?>
</button>
<?php endif ?>

<div class="sensei-quiz-actions-secondary">
<?php if ( $is_reset_allowed ) : ?>
<div class="sensei-quiz-action">
<button type="submit" name="quiz_reset" form="sensei-quiz-form" class="quiz-submit reset sensei-stop-double-submission">
<?php esc_attr_e( 'Reset Quiz', 'sensei-lms' ); ?>
<button type="submit" name="quiz_reset" form="sensei-quiz-form" class="quiz-submit reset sensei-stop-double-submission sensei-course-theme__button is-link">
<?php esc_attr_e( 'Restart Quiz', 'sensei-lms' ); ?>

Check warning on line 1917 in includes/class-sensei-quiz.php

View check run for this annotation

Codecov / codecov/patch

includes/class-sensei-quiz.php#L1916-L1917

Added lines #L1916 - L1917 were not covered by tests
</button>

<input type="hidden" name="woothemes_sensei_reset_quiz_nonce" form="sensei-quiz-form" id="woothemes_sensei_reset_quiz_nonce" value="<?php echo esc_attr( wp_create_nonce( 'woothemes_sensei_reset_quiz_nonce' ) ); ?>" />
Expand Down Expand Up @@ -2379,6 +2391,32 @@

$quiz_progress_repository->create( $quiz_id, $user_id );
}

/**
* Check if the quiz is in ungraded state for a user.
*
* @param ?int $lesson_id The lesson ID.
* @param ?int $user_id The user ID.
*
* @return bool True if the quiz is in ungraded state for the user, false otherwise.
*/
public static function is_quiz_awaiting_grade_for_user( $lesson_id = null, $user_id = null ) {
if ( empty( $lesson_id ) ) {
$lesson_id = Sensei()->quiz->get_lesson_id();

Check warning on line 2405 in includes/class-sensei-quiz.php

View check run for this annotation

Codecov / codecov/patch

includes/class-sensei-quiz.php#L2405

Added line #L2405 was not covered by tests
}

if ( empty( $user_id ) ) {
$user_id = get_current_user_id();

Check warning on line 2409 in includes/class-sensei-quiz.php

View check run for this annotation

Codecov / codecov/patch

includes/class-sensei-quiz.php#L2409

Added line #L2409 was not covered by tests
}

if ( empty( $lesson_id ) || empty( $user_id ) || 'lesson' !== get_post_type( $lesson_id ) ) {
return false;

Check warning on line 2413 in includes/class-sensei-quiz.php

View check run for this annotation

Codecov / codecov/patch

includes/class-sensei-quiz.php#L2413

Added line #L2413 was not covered by tests
}

$lesson_status = \Sensei_Utils::user_lesson_status( $lesson_id, $user_id );

return $lesson_status && 'ungraded' === $lesson_status->comment_approved;
}
}

/**
Expand Down
148 changes: 147 additions & 1 deletion tests/unit-tests/test-class-quiz.php
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public function tearDown(): void {
foreach ( $quizzes as $index => $quiz ) {
wp_delete_post( $quiz->ID, true );
}

WP_Block_Supports::$block_to_render = null;
}

/**
Expand Down Expand Up @@ -1950,4 +1950,150 @@ public function testMaybeCreateQuizProgress_WhenTablesBasedProgressFeatureIsDisa
$actual = $quiz_progress_repository->has( $quiz_id, $user_id );
$this->assertFalse( $actual );
}

public function testQuizFooterActions_WhenAwaitingGradeInLearningMode_RendersAwaitingGradeButton() {
/* Arrange */
$user_id = $this->factory->user->create();
$course_id = $this->factory->course->create();
$lesson_id = $this->factory->lesson->create(
[
'meta_input' => [
'_lesson_course' => $course_id,
],
]
);

$quiz_id = $this->factory->maybe_create_quiz_for_lesson( $lesson_id );
$course_enrolment = Sensei_Course_Enrolment::get_course_instance( $course_id );
$course_enrolment->enrol( $user_id );

wp_set_current_user( $user_id );

// Enable course theme;
update_post_meta( $course_id, Sensei_Course_Theme_Option::THEME_POST_META_NAME, Sensei_Course_Theme_Option::SENSEI_THEME );

Sensei_Utils::update_lesson_status( $user_id, $lesson_id, 'ungraded' );

$this->go_to( get_permalink( $quiz_id ) );

WP_Block_Supports::$block_to_render = [
'attrs' => [],
'blockName' => 'sensei-lms/quiz-actions',
];

/* Act */
$result = ( new \Sensei\Blocks\Course_Theme\Quiz_Actions() )->render();

/* Assert */
$this->assertStringContainsString( 'Pending teacher grade', $result );
}

public function testQuizFooterActions_WhenAwaitingGradeButNotInLearningMode_DoesNotRenderAwaitingGradeButton() {
/* Arrange */
$user_id = $this->factory->user->create();
$course_id = $this->factory->course->create();
$lesson_id = $this->factory->lesson->create(
[
'meta_input' => [
'_lesson_course' => $course_id,
],
]
);

$quiz_id = $this->factory->maybe_create_quiz_for_lesson( $lesson_id );
$course_enrolment = Sensei_Course_Enrolment::get_course_instance( $course_id );
$course_enrolment->enrol( $user_id );

wp_set_current_user( $user_id );

Sensei_Utils::update_lesson_status( $user_id, $lesson_id, 'ungraded' );

$this->go_to( get_permalink( $quiz_id ) );

WP_Block_Supports::$block_to_render = [
'attrs' => [],
'blockName' => 'sensei-lms/quiz-actions',
];

/* Act */
$result = ( new \Sensei\Blocks\Course_Theme\Quiz_Actions() )->render();

/* Assert */
$this->assertStringNotContainsString( 'Pending teacher grade', $result );
}

public function testQuizFooterActions_WhenPassedButInLearningMode_DoesNotRenderAwaitingGradeButton() {
/* Arrange */
$user_id = $this->factory->user->create();
$course_id = $this->factory->course->create();
$lesson_id = $this->factory->lesson->create(
[
'meta_input' => [
'_lesson_course' => $course_id,
],
]
);

$quiz_id = $this->factory->maybe_create_quiz_for_lesson( $lesson_id );
$course_enrolment = Sensei_Course_Enrolment::get_course_instance( $course_id );
$course_enrolment->enrol( $user_id );

wp_set_current_user( $user_id );

// Enable course theme;
update_post_meta( $course_id, Sensei_Course_Theme_Option::THEME_POST_META_NAME, Sensei_Course_Theme_Option::SENSEI_THEME );

Sensei_Utils::update_lesson_status( $user_id, $lesson_id, 'passed' );

$this->go_to( get_permalink( $quiz_id ) );

WP_Block_Supports::$block_to_render = [
'attrs' => [],
'blockName' => 'sensei-lms/quiz-actions',
];

/* Act */
$result = ( new \Sensei\Blocks\Course_Theme\Quiz_Actions() )->render();

/* Assert */
$this->assertStringNotContainsString( 'Pending teacher grade', $result );
}

public function testQuizFooterActions_WhenInProgressButInLearningMode_DoesNotRenderAwaitingGradeButton() {
/* Arrange */
$user_id = $this->factory->user->create();
$course_id = $this->factory->course->create();
$lesson_id = $this->factory->lesson->create(
[
'meta_input' => [
'_lesson_course' => $course_id,
],
]
);

$quiz_id = $this->factory->maybe_create_quiz_for_lesson( $lesson_id );
$course_enrolment = Sensei_Course_Enrolment::get_course_instance( $course_id );
$course_enrolment->enrol( $user_id );

wp_set_current_user( $user_id );

// Enable course theme;
update_post_meta( $course_id, Sensei_Course_Theme_Option::THEME_POST_META_NAME, Sensei_Course_Theme_Option::SENSEI_THEME );

// Explicitly set the lesson status to in-progress just to make sure.
Sensei_Utils::update_lesson_status( $user_id, $lesson_id );

$this->go_to( get_permalink( $quiz_id ) );

WP_Block_Supports::$block_to_render = [
'attrs' => [],
'blockName' => 'sensei-lms/quiz-actions',
];

/* Act */
$result = ( new \Sensei\Blocks\Course_Theme\Quiz_Actions() )->render();

/* Assert */
$this->assertStringNotContainsString( 'Pending teacher grade', $result );
}
}
Loading