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

General: Migrate exam scores module to signals, inject and standalone #9921

Open
wants to merge 8 commits into
base: develop
Choose a base branch
from

Conversation

coolchock
Copy link
Contributor

@coolchock coolchock commented Dec 1, 2024

Checklist

General

Client

Description

This pull request migrates exam scores module to use signals, inject and standalone

Steps for Testing

Prerequisites:

  • 1 Instructor
  • 1 Exam with some scores
  1. Log in to Artemis
  2. Navigate to Course Administration -> Select a course -> Exams -> Exam Scores
  3. Verify that graphs on the exam scores page are displayed properly
  4. Verify that clicking on the bars in the chart within the Exercise Groups & Exercise Statistics section redirects you to an exercise. Please note that the first bar does not redirect, as it represents the exercise group average. The following bars, however, represent individual exercise averages and will redirect accordingly.

Testserver States

Note

These badges show the state of the test servers.
Green = Currently available, Red = Currently locked
Click on the badges to get to the test servers.







Review Progress

Performance Review

  • I (as a reviewer) confirm that the client changes (in particular related to REST calls and UI responsiveness) are implemented with a very good performance even for very large courses with more than 2000 students.
  • I (as a reviewer) confirm that the server changes (in particular related to database calls) are implemented with a very good performance even for very large courses with more than 2000 students.

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Exam Mode Test

  • Test 1
  • Test 2

Performance Tests

  • Test 1
  • Test 2

Summary by CodeRabbit

Release Notes

  • New Features

    • Both ExamScoresComponent and ExamScoresAverageScoresGraphComponent are now standalone components, enhancing their modularity and reusability.
    • Enhanced functionalities for displaying exam scores and statistics, including improved error handling and state management.
  • Bug Fixes

    • Resolved issues in how average scores and course data are accessed, improving reliability in data display.
  • Documentation

    • Updated test configurations to improve clarity and efficiency in testing components.
  • Tests

    • Streamlined test setups for both components, ensuring better input management and component initialization.

@github-actions github-actions bot added tests client Pull requests that update TypeScript code. (Added Automatically!) labels Dec 1, 2024
@coolchock coolchock temporarily deployed to artemis-test1.artemis.cit.tum.de December 2, 2024 09:26 — with GitHub Actions Inactive
@coolchock coolchock marked this pull request as ready for review December 2, 2024 11:02
@coolchock coolchock requested a review from a team as a code owner December 2, 2024 11:02
Copy link

coderabbitai bot commented Dec 2, 2024

Walkthrough

The pull request introduces significant modifications to the ExamScoresAverageScoresGraphComponent and ExamScoresComponent in an Angular application. Key changes include the transition of these components to standalone status, allowing independent usage. The dependency injection mechanism has been updated to utilize the inject function, simplifying initialization. Additionally, the way properties like averageScores and course are accessed has shifted from direct property access to method calls. The module structure has also been updated, reflecting these changes in component registration. Test files have been adjusted to align with the new component structure and input handling.

Changes

File Change Summary
src/main/webapp/app/exam/exam-scores/exam-scores-average-scores-graph.component.html Updated access to averageScores from property access this.averageScores.title to method call this.averageScores().title.
src/main/webapp/app/exam/exam-scores/exam-scores-average-scores-graph.component.ts Converted to standalone component, updated imports, removed constructor, and changed @Input properties to use input function for required inputs. Adjusted methods to access properties accordingly.
src/main/webapp/app/exam/exam-scores/exam-scores.component.ts Converted to standalone component, updated imports, refactored constructor to use inject for dependency injection, added new properties for state management, and improved error handling in ngOnInit.
src/main/webapp/app/exam/exam-scores/exam-scores.module.ts Moved ExamScoresComponent and ExamScoresAverageScoresGraphComponent from declarations to imports.
src/test/javascript/spec/component/exam/exam-scores/exam-scores-average-scores-graph.component.spec.ts Adjusted imports, streamlined component initialization, and updated input handling in tests.
src/test/javascript/spec/component/exam/exam-scores/exam-scores.component.spec.ts Enhanced testing setup with new imports and providers, removed unnecessary mock components, and simplified the beforeEach block.

Possibly related PRs

Suggested labels

refactoring, small, ready to merge, maintainer-approved

Suggested reviewers

  • EneaGore
  • florian-glombik
  • SimonEntholzer
  • JohannesStoehr
  • az108
  • HawKhiem
  • sachmii

📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL

📥 Commits

Reviewing files that changed from the base of the PR and between dece904 and 92bd1f8.

📒 Files selected for processing (6)
  • src/main/webapp/app/exam/exam-scores/exam-scores-average-scores-graph.component.html (1 hunks)
  • src/main/webapp/app/exam/exam-scores/exam-scores-average-scores-graph.component.ts (4 hunks)
  • src/main/webapp/app/exam/exam-scores/exam-scores.component.ts (3 hunks)
  • src/main/webapp/app/exam/exam-scores/exam-scores.module.ts (1 hunks)
  • src/test/javascript/spec/component/exam/exam-scores/exam-scores-average-scores-graph.component.spec.ts (5 hunks)
  • src/test/javascript/spec/component/exam/exam-scores/exam-scores.component.spec.ts (5 hunks)
🧰 Additional context used
📓 Path-based instructions (6)
src/main/webapp/app/exam/exam-scores/exam-scores-average-scores-graph.component.html (1)

Pattern src/main/webapp/**/*.html: @if and @for are new and valid Angular syntax replacing *ngIf and *ngFor. They should always be used over the old style.

src/main/webapp/app/exam/exam-scores/exam-scores.module.ts (1)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

src/test/javascript/spec/component/exam/exam-scores/exam-scores-average-scores-graph.component.spec.ts (1)

Pattern src/test/javascript/spec/**/*.ts: jest: true; mock: NgMocks; bad_practices: avoid_full_module_import; perf_improvements: mock_irrelevant_deps; service_testing: mock_http_for_logic; no_schema: avoid_NO_ERRORS_SCHEMA; expectation_specificity: true; solutions: {boolean: toBeTrue/False, reference: toBe, existence: toBeNull/NotNull, undefined: toBeUndefined, class_obj: toContainEntries/toEqual, spy_calls: {not_called: not.toHaveBeenCalled, once: toHaveBeenCalledOnce, with_value: toHaveBeenCalledWith|toHaveBeenCalledExactlyOnceWith}}

src/test/javascript/spec/component/exam/exam-scores/exam-scores.component.spec.ts (1)

Pattern src/test/javascript/spec/**/*.ts: jest: true; mock: NgMocks; bad_practices: avoid_full_module_import; perf_improvements: mock_irrelevant_deps; service_testing: mock_http_for_logic; no_schema: avoid_NO_ERRORS_SCHEMA; expectation_specificity: true; solutions: {boolean: toBeTrue/False, reference: toBe, existence: toBeNull/NotNull, undefined: toBeUndefined, class_obj: toContainEntries/toEqual, spy_calls: {not_called: not.toHaveBeenCalled, once: toHaveBeenCalledOnce, with_value: toHaveBeenCalledWith|toHaveBeenCalledExactlyOnceWith}}

src/main/webapp/app/exam/exam-scores/exam-scores-average-scores-graph.component.ts (1)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

src/main/webapp/app/exam/exam-scores/exam-scores.component.ts (1)

Pattern src/main/webapp/**/*.ts: angular_style:https://angular.io/guide/styleguide;methods_in_html:false;lazy_loading:true;code_reuse:true;tests:meaningful;types:PascalCase;enums:PascalCase;funcs:camelCase;props:camelCase;no_priv_prefix:true;strings:single_quotes;localize:true;btns:functionality;links:navigation;icons_text:newline;labels:associate;code_style:arrow_funcs,curly_braces,open_braces_same_line,indent_4;memory_leak_prevention:true;routes:naming_schema;chart_framework:ngx-charts;responsive_layout:true

🔇 Additional comments (11)
src/main/webapp/app/exam/exam-scores/exam-scores-average-scores-graph.component.ts (2)

23-24: Adoption of standalone component with appropriate imports

Declaring the component as standalone and importing necessary modules enhances modularity and reusability.


1-1: Verify Angular version compatibility for inject and input usage

The usage of inject for dependency injection and input.required for input properties are features introduced in Angular 16. Please ensure that the project's Angular version is 16 or later to support these features.

Run the following script to check the Angular version used in the project:

Also applies to: 27-31, 33-34

✅ Verification successful

Angular version is compatible with inject and input features

The project uses Angular 18.2.12, which fully supports the inject function and input properties introduced in Angular 16. These features can be safely used in the codebase.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check Angular version in package.json

# Expected: "@angular/core" has version >=16.0.0
grep '"@angular/core"' package.json

Length of output: 73

src/main/webapp/app/exam/exam-scores/exam-scores.component.ts (2)

81-92: Transition to standalone component and module imports

Declaring the ExamScoresComponent as standalone with the necessary imports improves modularity and aligns with modern Angular practices.


1-1: Verify Angular version compatibility for inject usage

The usage of inject for dependency injection replaces constructor injection and is introduced in Angular 16. Please ensure that the project's Angular version supports this feature.

Run the following script to confirm the Angular version:

Also applies to: 95-105

✅ Verification successful

inject usage is compatible with the current Angular version

The project uses Angular 18.2.12, which fully supports the inject function for dependency injection. This feature was introduced in Angular 14+ and is now considered a recommended approach.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check Angular version in package.json

# Expected: "@angular/core" has version >=16.0.0
grep '"@angular/core"' package.json

Length of output: 73

src/main/webapp/app/exam/exam-scores/exam-scores-average-scores-graph.component.html (1)

3-3: Update template bindings to match new input handling

Changing this.averageScores.title to this.averageScores().title correctly reflects the updated input property accessed via a function due to the use of input.required.

src/main/webapp/app/exam/exam-scores/exam-scores.module.ts (1)

25-26: Adjust module configuration for standalone components

Moving ExamScoresComponent and ExamScoresAverageScoresGraphComponent from declarations to imports aligns with their status as standalone components and ensures proper module configuration.

src/test/javascript/spec/component/exam/exam-scores/exam-scores-average-scores-graph.component.spec.ts (1)

58-58: Update test setup to accommodate input changes

The test has been updated to use fixture.componentRef.setInput for setting averageScores and course, aligning with the component's new input handling using input.required. This ensures that inputs are correctly initialized in the tests.

Also applies to: 72-79, 99-101, 147-150

src/test/javascript/spec/component/exam/exam-scores/exam-scores.component.spec.ts (4)

1-3: LGTM! Clean import organization for testing utilities.

The addition of HTTP testing utilities and animation module mocking demonstrates good testing practices by properly isolating the component under test.

Also applies to: 18-19


278-294: LGTM! Well-structured TestBed configuration.

The TestBed configuration follows Angular testing best practices:

  • Properly mocks BrowserAnimationsModule to avoid animation-related issues
  • Correctly provides HTTP testing utilities
  • Uses MockTranslateService for i18n testing

330-337: LGTM! Clean component initialization with proper type safety.

The component initialization follows testing best practices:

  • Uses type-safe injector access
  • Properly sets up spies for external services
  • Maintains clear separation of concerns

Line range hint 341-800: Excellent test coverage and implementation quality.

The test suite demonstrates high quality through:

  • Comprehensive coverage of component functionality
  • Proper error case handling
  • Thorough validation of calculations and exports
  • Good edge case coverage
  • Clear test organization and readability

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai or @coderabbitai title anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

Copy link

@HawKhiem HawKhiem left a comment

Choose a reason for hiding this comment

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

Tested on TS3. I can't seem to access exams scores. I don't know if I missed any step. Please correct me if I'm wrong (I can't upload videos for some reason. Its been loading for 10 minutes so I upload this screenshot. When I clicked on scores, it was simply loading as shown. I waited for about 5 minutes but no scores were shown)

image

Comment on lines +82 to +92
imports: [
FaIconComponent,
TranslateDirective,
ExportModule,
RouterLink,
NgStyle,
ArtemisParticipantScoresModule,
ExamScoresAverageScoresGraphComponent,
ArtemisSharedComponentModule,
ArtemisSharedCommonModule,
],
Copy link
Contributor

Choose a reason for hiding this comment

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

Might it be possible to remove some of those imports? I know it's still difficult, as some important dependencies themselves are not standalone, but have you tried here?

@sawys777 sawys777 temporarily deployed to artemis-test1.artemis.cit.tum.de December 6, 2024 23:23 — with GitHub Actions Inactive
Copy link

@sawys777 sawys777 left a comment

Choose a reason for hiding this comment

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

Tested on TS1, tested on several modules and the feature worked accordingly to the test description for most of the Test Course except for Test Course Aniruddh Zaveri, the exam score couldn't be loaded after several tries.

Copy link
Member

@BBesrour BBesrour left a comment

Choose a reason for hiding this comment

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

code lgtm.
Small comment about the module, can't we remove it since it doesn't declare any component anymore?

Copy link
Member

Choose a reason for hiding this comment

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

Do we still need this file? can't we instead import the components in the module where this file is imported?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
client Pull requests that update TypeScript code. (Added Automatically!) ready for review tests
Projects
Status: Ready For Review
Development

Successfully merging this pull request may close these issues.

5 participants