Skip to content

Commit

Permalink
Add unit tests to comment-visibility-setting-pipe (#12589)
Browse files Browse the repository at this point in the history
  • Loading branch information
cedricongjh authored Sep 25, 2023
1 parent fe6a397 commit be905b6
Showing 1 changed file with 63 additions and 0 deletions.
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');
});
});

0 comments on commit be905b6

Please sign in to comment.