|
| 1 | +import { determineAvatarPosition, readReceiptTooltip } from "../../../../src/components/views/rooms/ReadReceiptGroup"; |
| 2 | + |
| 3 | +describe("ReadReceiptGroup", () => { |
| 4 | + describe("TooltipText", () => { |
| 5 | + it("returns '...and more' with hasMore", () => { |
| 6 | + expect(readReceiptTooltip(["Alice", "Bob", "Charlie", "Dan", "Eve"], true)) |
| 7 | + .toEqual("Alice, Bob, Charlie, Dan, Eve and more"); |
| 8 | + expect(readReceiptTooltip(["Alice", "Bob", "Charlie", "Dan"], true)) |
| 9 | + .toEqual("Alice, Bob, Charlie, Dan and more"); |
| 10 | + expect(readReceiptTooltip(["Alice", "Bob", "Charlie"], true)) |
| 11 | + .toEqual("Alice, Bob, Charlie and more"); |
| 12 | + expect(readReceiptTooltip(["Alice", "Bob"], true)) |
| 13 | + .toEqual("Alice, Bob and more"); |
| 14 | + expect(readReceiptTooltip(["Alice"], true)) |
| 15 | + .toEqual("Alice and more"); |
| 16 | + expect(readReceiptTooltip([], false)) |
| 17 | + .toEqual(null); |
| 18 | + }); |
| 19 | + it("returns a pretty list without hasMore", () => { |
| 20 | + expect(readReceiptTooltip(["Alice", "Bob", "Charlie", "Dan", "Eve"], false)) |
| 21 | + .toEqual("Alice, Bob, Charlie, Dan and Eve"); |
| 22 | + expect(readReceiptTooltip(["Alice", "Bob", "Charlie", "Dan"], false)) |
| 23 | + .toEqual("Alice, Bob, Charlie and Dan"); |
| 24 | + expect(readReceiptTooltip(["Alice", "Bob", "Charlie"], false)) |
| 25 | + .toEqual("Alice, Bob and Charlie"); |
| 26 | + expect(readReceiptTooltip(["Alice", "Bob"], false)) |
| 27 | + .toEqual("Alice and Bob"); |
| 28 | + expect(readReceiptTooltip(["Alice"], false)) |
| 29 | + .toEqual("Alice"); |
| 30 | + expect(readReceiptTooltip([], false)) |
| 31 | + .toEqual(null); |
| 32 | + }); |
| 33 | + }); |
| 34 | + describe("AvatarPosition", () => { |
| 35 | + // The avatar slots are numbered from right to left |
| 36 | + // That means currently, we’ve got the slots | 3 | 2 | 1 | 0 | each with 10px distance to the next one. |
| 37 | + // We want to fill slots so the first avatar is in the left-most slot without leaving any slots at the right |
| 38 | + // unoccupied. |
| 39 | + it("to handle the non-overflowing case correctly", () => { |
| 40 | + expect(determineAvatarPosition(0, 1, 4)) |
| 41 | + .toEqual({ hidden: false, position: 0 }); |
| 42 | + |
| 43 | + expect(determineAvatarPosition(0, 2, 4)) |
| 44 | + .toEqual({ hidden: false, position: 1 }); |
| 45 | + expect(determineAvatarPosition(1, 2, 4)) |
| 46 | + .toEqual({ hidden: false, position: 0 }); |
| 47 | + |
| 48 | + expect(determineAvatarPosition(0, 3, 4)) |
| 49 | + .toEqual({ hidden: false, position: 2 }); |
| 50 | + expect(determineAvatarPosition(1, 3, 4)) |
| 51 | + .toEqual({ hidden: false, position: 1 }); |
| 52 | + expect(determineAvatarPosition(2, 3, 4)) |
| 53 | + .toEqual({ hidden: false, position: 0 }); |
| 54 | + |
| 55 | + expect(determineAvatarPosition(0, 4, 4)) |
| 56 | + .toEqual({ hidden: false, position: 3 }); |
| 57 | + expect(determineAvatarPosition(1, 4, 4)) |
| 58 | + .toEqual({ hidden: false, position: 2 }); |
| 59 | + expect(determineAvatarPosition(2, 4, 4)) |
| 60 | + .toEqual({ hidden: false, position: 1 }); |
| 61 | + expect(determineAvatarPosition(3, 4, 4)) |
| 62 | + .toEqual({ hidden: false, position: 0 }); |
| 63 | + }); |
| 64 | + |
| 65 | + it("to handle the overflowing case correctly", () => { |
| 66 | + expect(determineAvatarPosition(0, 6, 4)) |
| 67 | + .toEqual({ hidden: false, position: 3 }); |
| 68 | + expect(determineAvatarPosition(1, 6, 4)) |
| 69 | + .toEqual({ hidden: false, position: 2 }); |
| 70 | + expect(determineAvatarPosition(2, 6, 4)) |
| 71 | + .toEqual({ hidden: false, position: 1 }); |
| 72 | + expect(determineAvatarPosition(3, 6, 4)) |
| 73 | + .toEqual({ hidden: false, position: 0 }); |
| 74 | + expect(determineAvatarPosition(4, 6, 4)) |
| 75 | + .toEqual({ hidden: true, position: 0 }); |
| 76 | + expect(determineAvatarPosition(5, 6, 4)) |
| 77 | + .toEqual({ hidden: true, position: 0 }); |
| 78 | + }); |
| 79 | + }); |
| 80 | +}); |
0 commit comments