blob: 0eb9d302c3246315a25d620f8e340414bb5b8718 [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001// Copyright 2019 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5import {assert} from 'chai';
6import {MrActivityTable} from './mr-activity-table.js';
7import sinon from 'sinon';
8
9const SECONDS_PER_DAY = 24 * 60 * 60;
10
11let element;
12
13describe('mr-activity-table', () => {
14 beforeEach(() => {
15 element = document.createElement('mr-activity-table');
16 document.body.appendChild(element);
17 });
18
19 afterEach(() => {
20 document.body.removeChild(element);
21 });
22
23 it('initializes', () => {
24 assert.instanceOf(element, MrActivityTable);
25 });
26
27 it('no comments makes empty activity array', () => {
28 element.comments = [];
29
30 for (let i = 0; i < 93; i++) {
31 assert.equal(0, element._activityArray[i].commentCount);
32 }
33 });
34
35 it('activity array handles old comments', () => {
36 // 94 days since EPOCH.
37 sinon.stub(element, '_todayUnixTime').get(() => 94 * SECONDS_PER_DAY);
38
39 element.comments = [
40 {content: 'blah', timestamp: 0}, // too old.
41 {content: 'ignore', timestamp: 100}, // too old.
42 {
43 content: 'comment',
44 timestamp: SECONDS_PER_DAY + 1, // barely young enough.
45 },
46 {content: 'hello', timestamp: SECONDS_PER_DAY + 10}, // same day as above.
47 {content: 'world', timestamp: SECONDS_PER_DAY * 94}, // today
48 ];
49
50 assert.equal(93, element._activityArray.length);
51 assert.equal(2, element._activityArray[0].commentCount);
52 for (let i = 1; i < 92; i++) {
53 assert.equal(0, element._activityArray[i].commentCount);
54 }
55 assert.equal(1, element._activityArray[92].commentCount);
56 });
57});