blob: e73538061ed4cb3493c3186c1c7892451fa1ec46 [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 {MrClickThroughs} from './mr-click-throughs.js';
7import page from 'page';
8
9let element;
10
11describe('mr-click-throughs', () => {
12 beforeEach(() => {
13 element = document.createElement('mr-click-throughs');
14 document.body.appendChild(element);
15
16 sinon.stub(page, 'call');
17 });
18
19 afterEach(() => {
20 document.body.removeChild(element);
21
22 page.call.restore();
23 });
24
25 it('initializes', () => {
26 assert.instanceOf(element, MrClickThroughs);
27 });
28
29 it('stateChanged', () => {
30 const state = {userV0: {currentUser:
31 {prefs: new Map(), prefsLoaded: false}}};
32 element.stateChanged(state);
33 assert.deepEqual(element.prefs, new Map([['render_markdown', false]]));
34 assert.isFalse(element.prefsLoaded);
35 });
36
37 it('anon does not see privacy dialog', () => {
38 assert.isFalse(element._showPrivacyDialog);
39 });
40
41 it('signed in user sees no privacy dialog before prefs load', () => {
42 element.userDisplayName = 'user@example.com';
43 element.prefsLoaded = false;
44 assert.isFalse(element._showPrivacyDialog);
45 });
46
47 it('signed in user sees no privacy dialog if dismissal pref set', () => {
48 element.userDisplayName = 'user@example.com';
49 element.prefsLoaded = true;
50 element.prefs = new Map([['privacy_click_through', true]]);
51 assert.isFalse(element._showPrivacyDialog);
52 });
53
54 it('signed in user sees privacy dialog if dismissal pref missing', () => {
55 element.userDisplayName = 'user@example.com';
56 element.prefsLoaded = true;
57 element.prefs = new Map();
58 assert.isTrue(element._showPrivacyDialog);
59 });
60
61 it('anon does not see corp mode dialog', () => {
62 assert.isFalse(element._showCorpModeDialog);
63 });
64
65 it('signed in user sees no corp mode dialog before prefs load', () => {
66 element.userDisplayName = 'user@example.com';
67 element.prefsLoaded = false;
68 assert.isFalse(element._showCorpModeDialog);
69 });
70
71 it('signed in user sees no corp mode dialog if dismissal pref set', () => {
72 element.userDisplayName = 'user@example.com';
73 element.prefsLoaded = true;
74 element.prefs = new Map([['corp_mode_click_through', true]]);
75 assert.isFalse(element._showCorpModeDialog);
76 });
77
78 it('non-corp user sees no corp mode dialog', () => {
79 element.userDisplayName = 'user@example.com';
80 element.prefsLoaded = true;
81 element.prefs = new Map();
82 assert.isFalse(element._showCorpModeDialog);
83 });
84
85 it('corp user sees corp mode dialog if dismissal pref missing', () => {
86 element.userDisplayName = 'user@example.com';
87 element.prefsLoaded = true;
88 element.prefs = new Map([['public_issue_notice', true]]);
89 assert.isTrue(element._showCorpModeDialog);
90 });
91
92 it('corp user sees no corp mode dialog in members-only project', () => {
93 window.CS_env = {projectIsRestricted: true};
94 element.userDisplayName = 'user@example.com';
95 element.prefsLoaded = true;
96 element.prefs = new Map([['public_issue_notice', true]]);
97 assert.isFalse(element._showCorpModeDialog);
98 });
99
100 it('corp user sees corp mode dialog with no RVG warning', async () => {
101 element.userDisplayName = 'user@example.com';
102 element.prefsLoaded = true;
103 element.prefs = new Map([['public_issue_notice', true]]);
104
105 await element.updateComplete;
106 assert.notInclude(element.shadowRoot.innerHTML, 'altered');
107 });
108
109 it('corp user sees corp mode dialog with RVG warning', async () => {
110 element.userDisplayName = 'user@example.com';
111 element.prefsLoaded = true;
112 element.prefs = new Map([
113 ['public_issue_notice', true],
114 ['restrict_new_issues', true],
115 ]);
116
117 await element.updateComplete;
118 assert.include(element.shadowRoot.innerHTML, 'altered');
119 });
120});