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 responses #13182

Open
wants to merge 2 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
27 changes: 20 additions & 7 deletions jest-setup.ts
Original file line number Diff line number Diff line change
@@ -1,9 +1,22 @@
require('core-js/es/reflect');
require('core-js/proposals/reflect-metadata');
import 'zone.js';
import 'zone.js/testing';
import { TestBed } from '@angular/core/testing';
import { BrowserDynamicTestingModule, platformBrowserDynamicTesting } from '@angular/platform-browser-dynamic/testing';

TestBed.initTestEnvironment(BrowserDynamicTestingModule, platformBrowserDynamicTesting());

require('@angular/localize/init');

(window as any).IntersectionObserver = jest.fn(() => ({
observe: jest.fn(),
unobserve: jest.fn(),
disconnect: jest.fn(),
}));
Object.defineProperty(window, 'IntersectionObserver', {
writable: true,
value: jest.fn(() => ({
observe: jest.fn(),
unobserve: jest.fn(),
disconnect: jest.fn(),
})),
});

Object.defineProperty(global, 'IntersectionObserver', {
writable: true,
value: window.IntersectionObserver,
});
33 changes: 25 additions & 8 deletions jest.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,29 @@
module.exports = {
preset: 'jest-preset-angular',
setupFilesAfterEnv: ['<rootDir>/jest-setup.ts'],
testEnvironment: 'jsdom',
globals: {
'ts-jest': {
tsconfig: '<rootDir>/tsconfig.spec.json',
stringifyContentPathRegex: '\\.html$',
useESM: true,
},
},
moduleFileExtensions: ['ts', 'html', 'js', 'json', 'mjs'],
moduleNameMapper: {
'^src/(.*)$': '<rootDir>/src/$1',
'^app/(.*)$': '<rootDir>/src/app/$1',
'^assets/(.*)$': '<rootDir>/src/assets/$1',
'^environments/(.*)$': '<rootDir>/src/environments/$1',
},
transformIgnorePatterns: ['node_modules/(?!@angular|rxjs|@ng-bootstrap|zone.js)'],
transform: {
'^.+\\.(ts|js|mjs|html|svg)$': ['jest-preset-angular', {
tsconfig: '<rootDir>/tsconfig.spec.json',
stringifyContentPathRegex: '\\.html$',
useESM: true,
}],
},
collectCoverageFrom: [
'src/web/app/**/*.ts',
'!src/web/app/**/*.module.ts',
Expand All @@ -7,12 +32,4 @@ module.exports = {
],
coverageDirectory: './coverage',
coverageReporters: ['lcov', 'text-summary'],
setupFiles: [
'./jest-setup.ts',
],
moduleNameMapper: {
d3: '<rootDir>/node_modules/d3/dist/d3.min.js',
'lodash-es': 'lodash'
},
globalSetup: 'jest-preset-angular/global-setup',
};
57 changes: 43 additions & 14 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@
"@angular/compiler-cli": "^16.2.12",
"@types/d3": "^7.4.3",
"@types/file-saver": "^2.0.7",
"@types/jest": "^29.5.11",
"@types/jest": "^29.5.13",
"@types/ua-parser-js": "^0.7.39",
"@typescript-eslint/eslint-plugin": "^6.19.1",
"@typescript-eslint/parser": "^6.19.1",
Expand All @@ -74,6 +74,7 @@
"eslint-plugin-jsdoc": "^48.0.4",
"eslint-plugin-rxjs": "^5.0.3",
"jest": "^29.7.0",
"jest-preset-angular": "^14.2.4",
"lintspaces-cli": "^0.7.1",
"npm-run-all": "^4.1.5",
"postcss-html": "^1.6.0",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ exports[`QuestionResponsePanelComponent should snap with feedback session with q
<tm-question-response-panel
RESPONSE_HIDDEN_QUESTIONS={[Function Array]}
feedbackSessionsService={[Function FeedbackSessionsService]}
hideSelfResponses="false"
intent={[Function String]}
previewAsPerson=""
questions={[Function Array]}
Expand Down Expand Up @@ -438,6 +439,7 @@ exports[`QuestionResponsePanelComponent should snap with feedback session with q
<tm-question-response-panel
RESPONSE_HIDDEN_QUESTIONS={[Function Array]}
feedbackSessionsService={[Function FeedbackSessionsService]}
hideSelfResponses="false"
intent={[Function String]}
previewAsPerson=""
questions={[Function Array]}
Expand Down Expand Up @@ -745,6 +747,7 @@ exports[`QuestionResponsePanelComponent should snap with questions and responses
<tm-question-response-panel
RESPONSE_HIDDEN_QUESTIONS={[Function Array]}
feedbackSessionsService={[Function FeedbackSessionsService]}
hideSelfResponses="false"
intent={[Function String]}
previewAsPerson=""
questions={[Function Array]}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,90 @@
import { ComponentFixture, TestBed, fakeAsync, tick } from '@angular/core/testing';
import { QuestionResponsePanelComponent } from './question-response-panel.component';
import { HttpClientTestingModule } from '@angular/common/http/testing';

Check failure on line 3 in src/web/app/components/question-response-panel/hide-my-responses.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

`@angular/common/http/testing` import should occur before import of `@angular/core/testing`

Check failure on line 3 in src/web/app/components/question-response-panel/hide-my-responses.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (windows-latest)

`@angular/common/http/testing` import should occur before import of `@angular/core/testing`
import { RouterTestingModule } from '@angular/router/testing';

Check failure on line 4 in src/web/app/components/question-response-panel/hide-my-responses.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

`@angular/router/testing` import should occur before import of `./question-response-panel.component`

Check failure on line 4 in src/web/app/components/question-response-panel/hide-my-responses.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (windows-latest)

`@angular/router/testing` import should occur before import of `./question-response-panel.component`
import { FeedbackSessionsService } from '../../../services/feedback-sessions.service';
import { StatusMessageService } from '../../../services/status-message.service';

describe('HideMyResponses Feature', () => {
let component: QuestionResponsePanelComponent;
let fixture: ComponentFixture<QuestionResponsePanelComponent>;

beforeEach(async () => {
await TestBed.configureTestingModule({
declarations: [ QuestionResponsePanelComponent ],

Check failure on line 14 in src/web/app/components/question-response-panel/hide-my-responses.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

There should be no space after '['

Check failure on line 14 in src/web/app/components/question-response-panel/hide-my-responses.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (ubuntu-latest)

There should be no space before ']'

Check failure on line 14 in src/web/app/components/question-response-panel/hide-my-responses.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (windows-latest)

There should be no space after '['

Check failure on line 14 in src/web/app/components/question-response-panel/hide-my-responses.component.spec.ts

View workflow job for this annotation

GitHub Actions / lint (windows-latest)

There should be no space before ']'
imports: [
HttpClientTestingModule,
RouterTestingModule,
],
providers: [
FeedbackSessionsService,
StatusMessageService,
],
}).compileComponents();

fixture = TestBed.createComponent(QuestionResponsePanelComponent);
component = fixture.componentInstance;
fixture.detectChanges();
});

it('should be able to toggle hide/show responses', fakeAsync(() => {
expect(component.hideSelfResponses).toBeFalsy();

component.hideSelfResponses = true;
tick();
fixture.detectChanges();
expect(component.hideSelfResponses).toBeTruthy();

component.hideSelfResponses = false;
tick();
fixture.detectChanges();
expect(component.hideSelfResponses).toBeFalsy();
}));

it('should initialize with default values', () => {
expect(component.session).toBeDefined();
expect(component.session.courseId).toBe('');
expect(component.questions).toEqual([]);
expect(component.regKey).toBe('');
expect(component.previewAsPerson).toBe('');
});

it('should have a defined FeedbackSessionsService', () => {
const feedbackSessionsService = TestBed.inject(FeedbackSessionsService);
expect(feedbackSessionsService).toBeDefined();
});

it('should have a defined StatusMessageService', () => {
const statusMessageService = TestBed.inject(StatusMessageService);
expect(statusMessageService).toBeDefined();
});

it('should render without errors', () => {
expect(fixture.nativeElement).toBeTruthy();
});

it('should have RESPONSE_HIDDEN_QUESTIONS array with "CONTRIB" initially', () => {
expect(component.RESPONSE_HIDDEN_QUESTIONS).toEqual(['CONTRIB']);
});

it('should have "STUDENT_RESULT" as initial intent', () => {
expect(component.intent).toBe('STUDENT_RESULT');
});

it('should update hideSelfResponses when toggled multiple times', fakeAsync(() => {
component.hideSelfResponses = true;
tick();
fixture.detectChanges();
expect(component.hideSelfResponses).toBeTruthy();

component.hideSelfResponses = false;
tick();
fixture.detectChanges();
expect(component.hideSelfResponses).toBeFalsy();

component.hideSelfResponses = true;
tick();
fixture.detectChanges();
expect(component.hideSelfResponses).toBeTruthy();
}));
});
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@
<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">-->
<div class="given-responses mt-4" *ngIf="question.responsesFromSelf.length && !hideSelfResponses">
<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 @@ -64,6 +64,9 @@ export class QuestionResponsePanelComponent {
@Input()
previewAsPerson: string = '';

@Input()
hideSelfResponses: boolean = false;

canUserSeeResponses(question: FeedbackQuestionModel): boolean {
const showResponsesTo: FeedbackVisibilityType[] = question.feedbackQuestion.showResponsesTo;
if (this.intent === Intent.STUDENT_RESULT) {
Expand Down
Loading
Loading