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

[#13174] Student viewing responses: allow hiding self reponses #13187

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@
<strong>Other responses (to you): </strong>Responses are not visible to you.
</div>
</ng-template>
<div class="given-responses mt-4" *ngIf="question.responsesFromSelf.length">
<div class="given-responses mt-4" *ngIf="question.responsesFromSelf.length && !hideMyResponses">
<strong>Your own responses (to others):</strong>
<div *ngFor="let responseFromSelf of question.responsesFromSelf">
<tm-student-view-responses [responses]="[responseFromSelf]" [isSelfResponses]="true" [feedbackQuestion]="question.feedbackQuestion" [timezone]="session.timeZone" [statistics]="question.questionStatistics"></tm-student-view-responses>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,9 @@ export class QuestionResponsePanelComponent {
@Input()
regKey: string = '';

@Input()
hideMyResponses: boolean = false;

@Input()
previewAsPerson: string = '';

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,11 @@ <h4>Previewing Session Results as
</div>
</div>

<div class="toggle-container">
<input class="toggle-input" type="checkbox" id="hideMyResponses" (change)="toggleHideSelfResponses($event)" >
<label class="toggle-label" for="hideMyResponses">Hide my own responses</label>
</div>

<tm-loading-retry [shouldShowRetry]="hasFeedbackSessionResultsLoadingFailed" [message]="'Failed to load results'" (retryEvent)="retryLoadingFeedbackSessionResults()">
<div *tmIsLoading="isFeedbackSessionResultsLoading">
<div *ngIf="questions.length === 0" class="mt-4">
Expand All @@ -82,6 +87,7 @@ <h4>Previewing Session Results as
</div>
<tm-question-response-panel [questions]="questions" [session]="session"
[intent]="intent" [regKey]="regKey" [previewAsPerson]="previewAsPerson"
[hideMyResponses]="hideMyResponses"
></tm-question-response-panel>
</div>
</tm-loading-retry>
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import { HttpClientTestingModule } from '@angular/common/http/testing';
import { ComponentFixture, TestBed, waitForAsync } from '@angular/core/testing';
import { ActivatedRoute } from '@angular/router';
import { FormsModule } from '@angular/forms';

Check failure on line 4 in src/web/app/pages-session/session-result-page/session-result-page.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

`@angular/forms` import should occur before import of `@angular/router`

Check failure on line 4 in src/web/app/pages-session/session-result-page/session-result-page.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (windows-latest)

`@angular/forms` import should occur before import of `@angular/router`
import { RouterTestingModule } from '@angular/router/testing';
import { of, throwError } from 'rxjs';
import SpyInstance = jest.SpyInstance;
Expand Down Expand Up @@ -36,6 +37,10 @@
StudentViewResponsesModule,
} from '../../components/question-responses/student-view-responses/student-view-responses.module';
import { QuestionTextWithInfoModule } from '../../components/question-text-with-info/question-text-with-info.module';
import {

Check failure on line 40 in src/web/app/pages-session/session-result-page/session-result-page.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

`../../components/question-response-panel/question-response-panel.component` import should occur before import of `../../components/question-response-panel/question-response-panel.module`

Check failure on line 40 in src/web/app/pages-session/session-result-page/session-result-page.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (windows-latest)

`../../components/question-response-panel/question-response-panel.component` import should occur before import of `../../components/question-response-panel/question-response-panel.module`
QuestionResponsePanelComponent

Check failure on line 41 in src/web/app/pages-session/session-result-page/session-result-page.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

Missing trailing comma

Check failure on line 41 in src/web/app/pages-session/session-result-page/session-result-page.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (windows-latest)

Missing trailing comma
} from "../../components/question-response-panel/question-response-panel.component";

Check failure on line 42 in src/web/app/pages-session/session-result-page/session-result-page.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

Strings must use singlequote

Check failure on line 42 in src/web/app/pages-session/session-result-page/session-result-page.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (windows-latest)

Strings must use singlequote
import {By} from "@angular/platform-browser";

Check failure on line 43 in src/web/app/pages-session/session-result-page/session-result-page.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

`@angular/platform-browser` import should occur before import of `@angular/router`

Check failure on line 43 in src/web/app/pages-session/session-result-page/session-result-page.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

A space is required after '{'

Check failure on line 43 in src/web/app/pages-session/session-result-page/session-result-page.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

A space is required before '}'

Check failure on line 43 in src/web/app/pages-session/session-result-page/session-result-page.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

Strings must use singlequote

Check failure on line 43 in src/web/app/pages-session/session-result-page/session-result-page.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (windows-latest)

`@angular/platform-browser` import should occur before import of `@angular/router`

Check failure on line 43 in src/web/app/pages-session/session-result-page/session-result-page.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (windows-latest)

A space is required after '{'

Check failure on line 43 in src/web/app/pages-session/session-result-page/session-result-page.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (windows-latest)

A space is required before '}'

Check failure on line 43 in src/web/app/pages-session/session-result-page/session-result-page.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (windows-latest)

Strings must use singlequote

describe('SessionResultPageComponent', () => {
const testFeedbackSession: FeedbackSession = {
Expand Down Expand Up @@ -119,6 +124,7 @@
imports: [
HttpClientTestingModule,
RouterTestingModule,
FormsModule,
StudentViewResponsesModule,
QuestionTextWithInfoModule,
QuestionResponsePanelModule,
Expand Down Expand Up @@ -413,4 +419,70 @@
expect(component.questions.length).toEqual(1);
expect(component.questions[0]).toEqual(testFeedbackQuestionModel);
});

// Test the toggle feature
it('should toggle `hideMyResponses` when the checkbox is clicked', () => {
// Arrange: Get the checkbox input element
const checkbox = fixture.debugElement.query(By.css('#hideMyResponses')).nativeElement;

// Act: Toggle the checkbox to hide responses
checkbox.checked = true;
checkbox.dispatchEvent(new Event('change'));
fixture.detectChanges();

// Assert: The `hideMyResponses` should be true
expect(component.hideMyResponses).toBe(true);

// Act: Toggle the checkbox again to show responses
checkbox.checked = false;
checkbox.dispatchEvent(new Event('change'));
fixture.detectChanges();

// Assert: The `hideMyResponses` should be false
expect(component.hideMyResponses).toBe(false);
});

it('should pass `hideMyResponses` to QuestionResponsePanelComponent correctly', () => {
// Arrange: Set `hideMyResponses` to true
component.hideMyResponses = true;
fixture.detectChanges();

// Act: Get the QuestionResponsePanelComponent instance
const questionResponsePanel = fixture.debugElement.query(By.directive(QuestionResponsePanelComponent))
.componentInstance as QuestionResponsePanelComponent;

// Assert: The `hideMyResponses` should be passed to the child component
expect(questionResponsePanel.hideMyResponses).toBe(true);

// Arrange: Set `hideMyResponses` to false
component.hideMyResponses = false;
fixture.detectChanges();

// Assert: The `hideMyResponses` should now be false in the child component
expect(questionResponsePanel.hideMyResponses).toBe(false);
});

it('should hide the self responses section when `hideMyResponses` is true', () => {
// Arrange: Set `hideMyResponses` to true
component.hideMyResponses = true;
fixture.detectChanges();

// Act: Query the responses section with class `given-responses`
const responseSection = fixture.debugElement.query(By.css('.given-responses'));

// Assert: Response section should not be present in the DOM
expect(responseSection).toBeNull();
});

it('should show the self responses section when `hideMyResponses` is false', () => {
// Arrange: Set `hideMyResponses` to false
component.hideMyResponses = false;
fixture.detectChanges();

// Act: Query the responses section with class `given-responses`
const responseSection = fixture.debugElement.query(By.css('.given-responses'));

// Assert: Response section should be present in the DOM
expect(responseSection).not.toBeNull();
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,13 @@ export class SessionResultPageComponent implements OnInit {

private backendUrl: string = environment.backendUrl;

hideMyResponses: boolean = false;

toggleHideSelfResponses(event: Event): void {
const target = event.target as HTMLInputElement;
this.hideMyResponses = target.checked;
}

constructor(private feedbackQuestionsService: FeedbackQuestionsService,
private feedbackSessionsService: FeedbackSessionsService,
private route: ActivatedRoute,
Expand Down
Loading