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

[#12588] Add unit tests to comment-visibility-setting-pipe #12589

Merged
Merged
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
@@ -1,3 +1,5 @@
import { CommentVisibilityType } from '../../../types/api-output';
import { CommentVisibilityControl } from '../../../types/comment-visibility-control';
import {
CommentVisibilityControlNamePipe,
CommentVisibilityTypeDescriptionPipe, CommentVisibilityTypeNamePipe, CommentVisibilityTypesJointNamePipe,
Expand All @@ -8,25 +10,86 @@ describe('CommentVisibilityControlNamePipe', () => {
const pipe: CommentVisibilityControlNamePipe = new CommentVisibilityControlNamePipe();
expect(pipe).toBeTruthy();
});

it('should return appropriate display strings given a CommentVisibilityControl', () => {
const pipe: CommentVisibilityControlNamePipe = new CommentVisibilityControlNamePipe();

expect(pipe.transform(CommentVisibilityControl.SHOW_COMMENT)).toBe('Can see this comment');
expect(pipe.transform(CommentVisibilityControl.SHOW_GIVER_NAME)).toBe("Can see comment giver's name");
expect(pipe.transform('INVALID_VALUE' as CommentVisibilityControl)).toBe('Unknown');
});
});

describe('CommentVisibilityTypeDescriptionPipe', () => {
it('create an instance', () => {
const pipe: CommentVisibilityTypeDescriptionPipe = new CommentVisibilityTypeDescriptionPipe();
expect(pipe).toBeTruthy();
});

it('should return appropriate display strings given a CommentVisibilityType', () => {
const pipe: CommentVisibilityTypeDescriptionPipe = new CommentVisibilityTypeDescriptionPipe();

expect(pipe.transform(CommentVisibilityType.GIVER)).toBe('Control what response giver(s) can view');
expect(pipe.transform(CommentVisibilityType.RECIPIENT)).toBe('Control what response recipient(s) can view');
expect(pipe.transform(CommentVisibilityType.INSTRUCTORS)).toBe('Control what instructors can view');
expect(pipe.transform(CommentVisibilityType.GIVER_TEAM_MEMBERS))
.toBe('Control what team members of response giver can view');
expect(pipe.transform(CommentVisibilityType.RECIPIENT_TEAM_MEMBERS))
.toBe('Control what team members of response recipient(s) can view');
expect(pipe.transform(CommentVisibilityType.STUDENTS))
.toBe('Control what other students in this course can view');
expect(pipe.transform('INVALID_VALUE' as CommentVisibilityType)).toBe('Unknown');
});
});

describe('CommentVisibilityTypeNamePipe', () => {
it('create an instance', () => {
const pipe: CommentVisibilityTypeNamePipe = new CommentVisibilityTypeNamePipe();
expect(pipe).toBeTruthy();
});

it('should return appropriate display strings given a CommentVisibilityType', () => {
const pipe: CommentVisibilityTypeNamePipe = new CommentVisibilityTypeNamePipe();

expect(pipe.transform(CommentVisibilityType.GIVER)).toBe('Response Giver(s)');
expect(pipe.transform(CommentVisibilityType.RECIPIENT)).toBe('Response Recipient(s)');
expect(pipe.transform(CommentVisibilityType.INSTRUCTORS)).toBe('Instructors');
expect(pipe.transform(CommentVisibilityType.GIVER_TEAM_MEMBERS)).toBe("Response Giver's Team Members");
expect(pipe.transform(CommentVisibilityType.RECIPIENT_TEAM_MEMBERS)).toBe("Response Recipient's Team Members");
expect(pipe.transform(CommentVisibilityType.STUDENTS)).toBe('Other students in this course');
expect(pipe.transform('INVALID_VALUE' as CommentVisibilityType)).toBe('Unknown');
});
});

describe('CommentVisibilityTypesJointNamePipe', () => {
it('create an instance', () => {
const pipe: CommentVisibilityTypesJointNamePipe = new CommentVisibilityTypesJointNamePipe();
expect(pipe).toBeTruthy();
});

it('should handle an empty array', () => {
const pipe: CommentVisibilityTypesJointNamePipe = new CommentVisibilityTypesJointNamePipe();
expect(pipe.transform([])).toBe('nobody');
});

it('should output the correct string when given an array of 1 CommentVisibilityTypes', () => {
const pipe: CommentVisibilityTypesJointNamePipe = new CommentVisibilityTypesJointNamePipe();
expect(pipe.transform([CommentVisibilityType.GIVER])).toBe('response giver(s)');
});

it('should output the correct string when given an array of CommentVisibilityTypes', () => {
const pipe: CommentVisibilityTypesJointNamePipe = new CommentVisibilityTypesJointNamePipe();
expect(pipe
.transform([CommentVisibilityType.GIVER,
CommentVisibilityType.INSTRUCTORS, CommentVisibilityType.STUDENTS]))
.toBe('response giver(s), and instructors, and other students in this course');
});

it('should output a string when given an array of CommentVisibilityTypes and an invalid value', () => {
const pipe: CommentVisibilityTypesJointNamePipe = new CommentVisibilityTypesJointNamePipe();
expect(pipe
.transform(['INVALID_VALUE' as CommentVisibilityType,
CommentVisibilityType.INSTRUCTORS, CommentVisibilityType.STUDENTS]))
.toBe('unknown, and instructors, and other students in this course');
});
});
Loading