blob: 0ee6b460dc0e2cabc7054c62560e65136ca5d13d [file] [log] [blame]
Adrià Vilanova Martínezf19ea432024-01-23 20:20:52 +01001// Copyright 2019 The Chromium Authors
Copybara854996b2021-09-07 19:36:02 +00002// 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 {FORMATTER}
7 from 'elements/chops/chops-timestamp/chops-timestamp-helpers.js';
8import {MrSiteBanner} from './mr-site-banner.js';
9
10
11let element;
12
13describe('mr-site-banner', () => {
14 beforeEach(() => {
15 element = document.createElement('mr-site-banner');
16 document.body.appendChild(element);
17 });
18
19 afterEach(() => {
20 document.body.removeChild(element);
21 });
22
23 it('initializes', () => {
24 assert.instanceOf(element, MrSiteBanner);
25 });
26
27 it('displays a banner message', async () => {
28 element.bannerMessage = 'Message';
29 await element.updateComplete;
30 assert.equal(element.shadowRoot.textContent.trim(), 'Message');
31 assert.isNull(element.shadowRoot.querySelector('chops-timestamp'));
32 });
33
34 it('displays the banner timestamp', async () => {
35 const timestamp = 1560450600;
36
37 element.bannerMessage = 'Message';
38 element.bannerTime = timestamp;
39 await element.updateComplete;
40
41 const chopsTimestamp = element.shadowRoot.querySelector('chops-timestamp');
42
43 // The formatted date strings differ based on time zone and browser, so we
44 // can't use static strings for testing. We can't stub out the format method
45 // because it's native code and can't be modified. So just use the FORMATTER
46 // object.
47 assert.include(
48 chopsTimestamp.shadowRoot.textContent,
49 FORMATTER.format(new Date(timestamp * 1000)));
50 });
51
52 it('hides when there is no banner message', async () => {
53 await element.updateComplete;
54 assert.isTrue(element.hidden);
55 });
56});