blob: 90544745886597aed02483c6381296e940797a34 [file] [log] [blame]
Dmitrii Filippov06117e82020-06-25 13:26:55 +02001/**
2 * @license
Ben Rohlfs94fcbbc2022-05-27 10:45:03 +02003 * Copyright 2018 Google LLC
4 * SPDX-License-Identifier: Apache-2.0
Dmitrii Filippov06117e82020-06-25 13:26:55 +02005 */
Frank Bordenbe9451a2022-09-12 15:44:29 +02006import '../../../test/common-test-setup';
Frank Bordene1ba8212022-08-29 15:20:01 +02007import {fixture, html, assert} from '@open-wc/testing';
Paladox none17f0c4e2021-08-11 03:45:30 +00008import './gr-repo-header';
9import {GrRepoHeader} from './gr-repo-header';
Paladox none17f0c4e2021-08-11 03:45:30 +000010import {stubRestApi} from '../../../test/test-utils';
Paladox none5554d952021-08-11 03:56:51 +000011import {RepoName, UrlEncodedRepoName} from '../../../types/common';
Dmitrii Filippoveb8b2692020-04-06 18:02:35 +020012
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010013suite('gr-repo-header tests', () => {
Paladox none17f0c4e2021-08-11 03:45:30 +000014 let element: GrRepoHeader;
Becky Siegel20789302018-01-05 14:18:05 -080015
Frank Borden018c7582022-07-15 18:27:56 +020016 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 Borden37c7e422022-08-19 14:55:52 +020023 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 Rohlfs26db7422022-09-15 22:21:11 +020031 <a href="/admin/repos/test"> Repo settings </a>
Frank Borden37c7e422022-08-19 14:55:52 +020032 </div>
33 <div>
34 <span class="browse"> Browse: </span>
35 </div>
Frank Borden018c7582022-07-15 18:27:56 +020036 </div>
Frank Borden37c7e422022-08-19 14:55:52 +020037 `
38 );
Becky Siegel20789302018-01-05 14:18:05 -080039 });
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010040
Paladox none5554d952021-08-11 03:56:51 +000041 test('repoUrl reset once repo changed', async () => {
Frank Borden018c7582022-07-15 18:27:56 +020042 element.repo = undefined;
43 await element.updateComplete;
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010044 assert.equal(element._repoUrl, undefined);
Frank Borden018c7582022-07-15 18:27:56 +020045
Paladox none5554d952021-08-11 03:56:51 +000046 element.repo = 'test' as RepoName;
Frank Borden018c7582022-07-15 18:27:56 +020047 await element.updateComplete;
48
Ben Rohlfs26db7422022-09-15 22:21:11 +020049 assert.equal(element._repoUrl, '/admin/repos/test');
Dmitrii Filippovdaf0ec92020-03-17 11:27:28 +010050 });
Dmitrii Filippov06117e82020-06-25 13:26:55 +020051
Paladox none5554d952021-08-11 03:56:51 +000052 test('webLinks set', async () => {
Paladox none01a7ba02021-04-11 18:49:06 +000053 const repoRes = {
Paladox none17f0c4e2021-08-11 03:45:30 +000054 id: 'test' as UrlEncodedRepoName,
Paladox none01a7ba02021-04-11 18:49:06 +000055 web_links: [
56 {
57 name: 'gitiles',
58 url: 'https://gerrit.test/g',
59 },
60 ],
61 };
Paladox none01a7ba02021-04-11 18:49:06 +000062 stubRestApi('getRepo').returns(Promise.resolve(repoRes));
Frank Borden018c7582022-07-15 18:27:56 +020063 element.repo = undefined;
64 await element.updateComplete;
Paladox none01a7ba02021-04-11 18:49:06 +000065
66 assert.deepEqual(element._webLinks, []);
67
Paladox none5554d952021-08-11 03:56:51 +000068 element.repo = 'test' as RepoName;
Frank Borden018c7582022-07-15 18:27:56 +020069 await element.updateComplete;
70
Paladox none5554d952021-08-11 03:56:51 +000071 assert.deepEqual(element._webLinks, repoRes.web_links);
Paladox none01a7ba02021-04-11 18:49:06 +000072 });
73});