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

Development: Migrate exam and exam exercise import client code to signals #10106

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

Conversation

coolchock
Copy link
Contributor

@coolchock coolchock commented Jan 5, 2025

Checklist

General

Client

Description

This PR updates the Exam and Exam Exercise Import components to use Signals.

Steps for Testing

Prerequisites:

  • 1 Instructor
  1. Log in to Artemis
  2. Navigate to Course Administration -> Exams
  3. Try to import an exam and check if it works
  4. Try to import an exam exercise to an exam and check if it works

Review Progress

Code Review

  • Code Review 1
  • Code Review 2

Manual Tests

  • Test 1
  • Test 2

Summary by CodeRabbit

Summary by CodeRabbit

  • Refactor
    • Transitioned component input handling to a function-based approach for improved consistency in data retrieval and UI evaluation.
    • Updated template conditional logic to use function calls for clearer state management.
    • Replaced direct property assignments with setter methods for managing component state.
    • Modified how properties are accessed within components to enhance interaction with parent components.
  • Chores
    • Streamlined initialization by removing redundant constructors in certain services.
  • Tests
    • Aligned test cases with the new input-binding mechanism by updating the way component inputs are set.
    • Enhanced test initialization for modal components using reactive signals for state management.

@github-actions github-actions bot added tests client Pull requests that update TypeScript code. (Added Automatically!) labels Jan 5, 2025
Copy link

There hasn't been any activity on this pull request recently. Therefore, this pull request has been automatically marked as stale and will be closed if no further activity occurs within seven days. Thank you for your contributions.

@github-actions github-actions bot added the stale label Jan 13, 2025
@coolchock coolchock removed the stale label Jan 26, 2025
# Conflicts:
#	src/main/webapp/app/exam/manage/exam-management.module.ts
#	src/main/webapp/app/exam/manage/exams/exam-exercise-import/exam-exercise-import.component.ts
#	src/main/webapp/app/exam/manage/exams/exam-import/exam-import-paging.service.ts
#	src/main/webapp/app/exam/manage/exams/exam-import/exam-import.component.ts
#	src/test/javascript/spec/component/exam/exam-update.component.spec.ts
Copy link

github-actions bot commented Feb 3, 2025

There hasn't been any activity on this pull request recently. Therefore, this pull request has been automatically marked as stale and will be closed if no further activity occurs within seven days. Thank you for your contributions.

@github-actions github-actions bot added the stale label Feb 3, 2025
# Conflicts:
#	src/main/webapp/app/exam/manage/exam-management.module.ts
#	src/test/javascript/spec/component/exam/manage/exam-import.component.spec.ts
@github-actions github-actions bot removed the stale label Feb 14, 2025
@coolchock coolchock changed the title General: Migrate exam and exam exercise import to signals, inject and standalone General: Migrate exam and exam exercise import to signals Feb 15, 2025
@coolchock coolchock marked this pull request as ready for review February 15, 2025 09:38
@coolchock coolchock requested a review from a team as a code owner February 15, 2025 09:38
Copy link

coderabbitai bot commented Feb 15, 2025

Walkthrough

This pull request refactors how component inputs are accessed by transitioning from direct property access to function calls. In several Angular components and their corresponding tests, the use of the @Input() and @ViewChild() decorators has been replaced with function-based approaches using input() and viewChild.required(). The changes update both the HTML templates and TypeScript files to call properties as functions (e.g., exam() instead of exam) and adjust the test suites to use fixture.componentRef.setInput(). Additionally, a redundant constructor was removed from a paging service.

Changes

File(s) Change Summary
src/main/webapp/app/exam/manage/exams/exam-exercise-import/exam-exercise-import.component.html
src/main/webapp/app/exam/manage/exams/exam-exercise-import/exam-exercise-import.component.ts
Refactored the Exam Exercise Import Component by replacing direct property accesses (e.g., exam.exerciseGroups) with function calls (e.g., exam().exerciseGroups), removing @Input() decorators and initializing inputs using input() methods.
src/main/webapp/app/exam/manage/exams/exam-import/exam-import-paging.service.ts Removed the redundant constructor in the Exam Import Paging Service, which previously called the superclass constructor.
src/main/webapp/app/exam/manage/exams/exam-import/exam-import.component.html
src/main/webapp/app/exam/manage/exams/exam-import/exam-import.component.ts
Updated the Exam Import Component by replacing traditional @Input() and @ViewChild() usage with input() and viewChild.required(), and converting property accesses to function calls for inputs and internal component references.
src/test/javascript/spec/component/exam/exam-update.component.spec.ts
src/test/javascript/spec/component/exam/manage/exam-exercise-import.component.spec.ts
src/test/javascript/spec/component/exam/manage/exam-import.component.spec.ts
Adjusted test suites to set component inputs using fixture.componentRef.setInput(), and updated import statements to include the new input decorator from Angular’s core package.
src/test/javascript/spec/component/exam/manage/exam-management.component.spec.ts
src/main/webapp/app/exam/manage/exam-management.component.ts
src/main/webapp/app/exam/manage/exercise-groups/exercise-groups.component.ts
Updated test cases and component methods to use setter methods for various properties instead of direct assignments, reflecting a shift towards a functional approach in managing component state.

Sequence Diagram(s)

sequenceDiagram
    participant P as Parent Component/Test
    participant E as ExamExerciseImportComponent
    P->>E: Set input using setInput('exam', examObject)
    E->>E: Initialize exam via input.required<Exam>()
    E->>E: Invoke exam() to retrieve exam data
    E->>Template: Bind exam().exerciseGroups in HTML
Loading
sequenceDiagram
    participant P as Parent Component/Test
    participant I as ExamImportComponent
    P->>I: Set inputs using setInput (e.g., subsequentExerciseGroupSelection, targetExamId)
    I->>I: Initialize inputs via input() functions
    I->>I: Call input functions (e.g., subsequentExerciseGroupSelection()) during processing
    I->>Child: Access child component via viewChild.required()
Loading

Possibly related PRs

Suggested labels

ready to merge, exam


📜 Recent review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 56d68c5 and e6a709c.

📒 Files selected for processing (1)
  • src/test/javascript/spec/component/exam/manage/exam-management.component.spec.ts (2 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • src/test/javascript/spec/component/exam/manage/exam-management.component.spec.ts
⏰ Context from checks skipped due to timeout of 90000ms (8)
  • GitHub Check: Call Build Workflow / Build .war artifact
  • GitHub Check: Call Build Workflow / Build and Push Docker Image
  • GitHub Check: client-tests-selected
  • GitHub Check: client-style
  • GitHub Check: client-tests
  • GitHub Check: server-style
  • GitHub Check: server-tests
  • GitHub Check: Analyse

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 generate docstrings to generate docstrings for this PR. (Beta)
  • @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

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
src/test/javascript/spec/component/exam/manage/exercise-groups/exercise-groups.component.spec.ts (1)

283-286: Enhance test coverage for signal-based properties.

While the signal initialization is correct, consider adding test cases to verify:

  1. Signal value updates during the modal interaction
  2. Signal subscriptions and their effects

Example test case to add:

it('updates signal values in the import modal', fakeAsync(() => {
    const mockReturnValue = {
        componentInstance: {
            subsequentExerciseGroupSelection: signal<boolean>(false),
            targetCourseId: signal<number | undefined>(undefined),
            targetExamId: signal<number | undefined>(undefined),
        },
        result: Promise.resolve([]),
    } as NgbModalRef;
    
    jest.spyOn(modalService, 'open').mockReturnValue(mockReturnValue);
    
    comp.openExerciseGroupImportModal();
    
    // Test signal updates
    mockReturnValue.componentInstance.subsequentExerciseGroupSelection.set(true);
    mockReturnValue.componentInstance.targetCourseId.set(123);
    mockReturnValue.componentInstance.targetExamId.set(456);
    
    tick();
    
    expect(mockReturnValue.componentInstance.subsequentExerciseGroupSelection()).toBeTrue();
    expect(mockReturnValue.componentInstance.targetCourseId()).toBe(123);
    expect(mockReturnValue.componentInstance.targetExamId()).toBe(456);
}));
📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between c699dd9 and 56d68c5.

📒 Files selected for processing (1)
  • src/test/javascript/spec/component/exam/manage/exercise-groups/exercise-groups.component.spec.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
`src/test/javascript/spec/**/*.ts`: jest: true; mock: NgMock...

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/manage/exercise-groups/exercise-groups.component.spec.ts
⏰ Context from checks skipped due to timeout of 90000ms (9)
  • GitHub Check: client-style
  • GitHub Check: client-tests-selected
  • GitHub Check: client-tests
  • GitHub Check: server-style
  • GitHub Check: server-tests
  • GitHub Check: Call Build Workflow / Build .war artifact
  • GitHub Check: Call Build Workflow / Build and Push Docker Image
  • GitHub Check: Codacy Static Code Analysis
  • GitHub Check: Analyse
🔇 Additional comments (1)
src/test/javascript/spec/component/exam/manage/exercise-groups/exercise-groups.component.spec.ts (1)

32-32: LGTM!

The import of signal from @angular/core is correctly placed and necessary for the signal-based reactivity system.

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 16, 2025
@helios-aet helios-aet bot temporarily deployed to artemis-test1.artemis.cit.tum.de February 16, 2025 13:12 Inactive
@helios-aet helios-aet bot temporarily deployed to artemis-test4.artemis.cit.tum.de February 16, 2025 13:17 Inactive
ole-ve
ole-ve previously approved these changes Feb 16, 2025
Copy link
Contributor

@ole-ve ole-ve 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 TS4, error does not occur anymore and all test steps were valid

BBesrour
BBesrour previously approved these changes Feb 16, 2025
Copy link
Contributor

@magaupp magaupp left a comment

Choose a reason for hiding this comment

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

Looks good overall. One issue:

coderabbitai[bot]
coderabbitai bot previously approved these changes Feb 16, 2025
magaupp
magaupp previously approved these changes Feb 16, 2025
Copy link
Contributor

@magaupp magaupp left a comment

Choose a reason for hiding this comment

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

Thanks for the change. Code looks good

ole-ve
ole-ve previously approved these changes Feb 16, 2025
Copy link
Contributor

@ole-ve ole-ve left a comment

Choose a reason for hiding this comment

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

manual testing, unchanged by client test change

BBesrour
BBesrour previously approved these changes Feb 16, 2025
@krusche krusche changed the title Development: Migrate exam and exam exercise import to signals Development: Migrate exam and exam exercise import client code to signals Feb 17, 2025
# Conflicts:
#	src/test/javascript/spec/component/exam/manage/exercise-groups/exercise-groups.component.spec.ts
@helios-aet helios-aet bot temporarily deployed to artemis-test4.artemis.cit.tum.de February 17, 2025 20:44 Inactive
Copy link

@HanyangXu0508 HanyangXu0508 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 server 4 and worked well.
image

@helios-aet helios-aet bot temporarily deployed to artemis-test1.artemis.cit.tum.de February 17, 2025 23:22 Inactive
@helios-aet helios-aet bot temporarily deployed to artemis-test4.artemis.cit.tum.de February 17, 2025 23:28 Inactive
Copy link
Contributor

@magaupp magaupp left a comment

Choose a reason for hiding this comment

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

Re-approve code

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 to merge small tests
Projects
Status: Ready For Review
Development

Successfully merging this pull request may close these issues.

7 participants