Dmitrii Filippov | 06117e8 | 2020-06-25 13:26:55 +0200 | [diff] [blame] | 1 | /** |
| 2 | * @license |
Ben Rohlfs | 94fcbbc | 2022-05-27 10:45:03 +0200 | [diff] [blame] | 3 | * Copyright 2018 Google LLC |
| 4 | * SPDX-License-Identifier: Apache-2.0 |
Dmitrii Filippov | 06117e8 | 2020-06-25 13:26:55 +0200 | [diff] [blame] | 5 | */ |
Frank Borden | be9451a | 2022-09-12 15:44:29 +0200 | [diff] [blame] | 6 | import '../../../test/common-test-setup'; |
Frank Borden | e1ba821 | 2022-08-29 15:20:01 +0200 | [diff] [blame] | 7 | import {fixture, html, assert} from '@open-wc/testing'; |
Paladox none | 17f0c4e | 2021-08-11 03:45:30 +0000 | [diff] [blame] | 8 | import './gr-repo-header'; |
| 9 | import {GrRepoHeader} from './gr-repo-header'; |
Paladox none | 17f0c4e | 2021-08-11 03:45:30 +0000 | [diff] [blame] | 10 | import {stubRestApi} from '../../../test/test-utils'; |
Paladox none | 5554d95 | 2021-08-11 03:56:51 +0000 | [diff] [blame] | 11 | import {RepoName, UrlEncodedRepoName} from '../../../types/common'; |
Dmitrii Filippov | eb8b269 | 2020-04-06 18:02:35 +0200 | [diff] [blame] | 12 | |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 13 | suite('gr-repo-header tests', () => { |
Paladox none | 17f0c4e | 2021-08-11 03:45:30 +0000 | [diff] [blame] | 14 | let element: GrRepoHeader; |
Becky Siegel | 2078930 | 2018-01-05 14:18:05 -0800 | [diff] [blame] | 15 | |
Frank Borden | 018c758 | 2022-07-15 18:27:56 +0200 | [diff] [blame] | 16 | setup(async () => { |
| 17 | element = await fixture( |
| 18 | html`<gr-repo-header .repo=${'test' as RepoName}></gr-repo-header>` |
| 19 | ); |
| 20 | }); |
| 21 | |
| 22 | test('render', () => { |
Frank Borden | 37c7e42 | 2022-08-19 14:55:52 +0200 | [diff] [blame] | 23 | assert.shadowDom.equal( |
| 24 | element, |
| 25 | /* HTML */ ` |
| 26 | <div class="info"> |
| 27 | <h1 class="heading-1">test</h1> |
| 28 | <hr /> |
| 29 | <div> |
| 30 | <span> Detail: </span> |
Ben Rohlfs | 26db742 | 2022-09-15 22:21:11 +0200 | [diff] [blame] | 31 | <a href="/admin/repos/test"> Repo settings </a> |
Frank Borden | 37c7e42 | 2022-08-19 14:55:52 +0200 | [diff] [blame] | 32 | </div> |
| 33 | <div> |
| 34 | <span class="browse"> Browse: </span> |
| 35 | </div> |
Frank Borden | 018c758 | 2022-07-15 18:27:56 +0200 | [diff] [blame] | 36 | </div> |
Frank Borden | 37c7e42 | 2022-08-19 14:55:52 +0200 | [diff] [blame] | 37 | ` |
| 38 | ); |
Becky Siegel | 2078930 | 2018-01-05 14:18:05 -0800 | [diff] [blame] | 39 | }); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 40 | |
Paladox none | 5554d95 | 2021-08-11 03:56:51 +0000 | [diff] [blame] | 41 | test('repoUrl reset once repo changed', async () => { |
Frank Borden | 018c758 | 2022-07-15 18:27:56 +0200 | [diff] [blame] | 42 | element.repo = undefined; |
| 43 | await element.updateComplete; |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 44 | assert.equal(element._repoUrl, undefined); |
Frank Borden | 018c758 | 2022-07-15 18:27:56 +0200 | [diff] [blame] | 45 | |
Paladox none | 5554d95 | 2021-08-11 03:56:51 +0000 | [diff] [blame] | 46 | element.repo = 'test' as RepoName; |
Frank Borden | 018c758 | 2022-07-15 18:27:56 +0200 | [diff] [blame] | 47 | await element.updateComplete; |
| 48 | |
Ben Rohlfs | 26db742 | 2022-09-15 22:21:11 +0200 | [diff] [blame] | 49 | assert.equal(element._repoUrl, '/admin/repos/test'); |
Dmitrii Filippov | daf0ec9 | 2020-03-17 11:27:28 +0100 | [diff] [blame] | 50 | }); |
Dmitrii Filippov | 06117e8 | 2020-06-25 13:26:55 +0200 | [diff] [blame] | 51 | |
Paladox none | 5554d95 | 2021-08-11 03:56:51 +0000 | [diff] [blame] | 52 | test('webLinks set', async () => { |
Paladox none | 01a7ba0 | 2021-04-11 18:49:06 +0000 | [diff] [blame] | 53 | const repoRes = { |
Paladox none | 17f0c4e | 2021-08-11 03:45:30 +0000 | [diff] [blame] | 54 | id: 'test' as UrlEncodedRepoName, |
Paladox none | 01a7ba0 | 2021-04-11 18:49:06 +0000 | [diff] [blame] | 55 | web_links: [ |
| 56 | { |
| 57 | name: 'gitiles', |
| 58 | url: 'https://gerrit.test/g', |
| 59 | }, |
| 60 | ], |
| 61 | }; |
Paladox none | 01a7ba0 | 2021-04-11 18:49:06 +0000 | [diff] [blame] | 62 | stubRestApi('getRepo').returns(Promise.resolve(repoRes)); |
Frank Borden | 018c758 | 2022-07-15 18:27:56 +0200 | [diff] [blame] | 63 | element.repo = undefined; |
| 64 | await element.updateComplete; |
Paladox none | 01a7ba0 | 2021-04-11 18:49:06 +0000 | [diff] [blame] | 65 | |
| 66 | assert.deepEqual(element._webLinks, []); |
| 67 | |
Paladox none | 5554d95 | 2021-08-11 03:56:51 +0000 | [diff] [blame] | 68 | element.repo = 'test' as RepoName; |
Frank Borden | 018c758 | 2022-07-15 18:27:56 +0200 | [diff] [blame] | 69 | await element.updateComplete; |
| 70 | |
Paladox none | 5554d95 | 2021-08-11 03:56:51 +0000 | [diff] [blame] | 71 | assert.deepEqual(element._webLinks, repoRes.web_links); |
Paladox none | 01a7ba0 | 2021-04-11 18:49:06 +0000 | [diff] [blame] | 72 | }); |
| 73 | }); |