blob: 013a3a4d968f7e0597a041863fcf9a89d4bb2d01 [file] [log] [blame]
Copybara854996b2021-09-07 19:36:02 +00001// Copyright 2020 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 sinon from 'sinon';
7import {MrIssueEntryPage} from './mr-issue-entry-page.js';
8
9let element;
10
11describe('mr-issue-entry-page', () => {
12 beforeEach(() => {
13 element = document.createElement('mr-issue-entry-page');
14 document.body.appendChild(element);
15 });
16
17 afterEach(() => {
18 document.body.removeChild(element);
19 });
20
21 it('initializes', () => {
22 assert.instanceOf(element, MrIssueEntryPage);
23 });
24
25 describe('requires user to be logged in', () => {
26 it('redirects to loginUrl if not logged in', async () => {
27 document.body.removeChild(element);
28 element = document.createElement('mr-issue-entry-page');
29 assert.isUndefined(element.userDisplayName);
30
31 const EXPECTED = 'abc';
32 element.loginUrl = EXPECTED;
33
34 const pageStub = sinon.stub(element, '_page');
35 document.body.appendChild(element);
36 await element.updateComplete;
37
38 sinon.assert.calledOnce(pageStub);
39 sinon.assert.calledWith(pageStub, EXPECTED);
40 });
41
42 it('renders when user is logged in', async () => {
43 document.body.removeChild(element);
44 element = document.createElement('mr-issue-entry-page');
45
46 element.loginUrl = 'abc';
47 element.userDisplayName = 'not_undefined';
48
49 const pageStub = sinon.stub(element, '_page');
50 const renderSpy = sinon.spy(element, 'render');
51 document.body.appendChild(element);
52 await element.updateComplete;
53
54 sinon.assert.notCalled(pageStub);
55 sinon.assert.calledOnce(renderSpy);
56 });
57 });
58});