1/* 2 * Copyright (C) 2022 Huawei Device Co., Ltd. 3 * Licensed under the Apache License, Version 2.0 (the "License"); 4 * you may not use this file except in compliance with the License. 5 * You may obtain a copy of the License at 6 * 7 * http://www.apache.org/licenses/LICENSE-2.0 8 * 9 * Unless required by applicable law or agreed to in writing, software 10 * distributed under the License is distributed on an "AS IS" BASIS, 11 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 * See the License for the specific language governing permissions and 13 * limitations under the License. 14 */ 15 16// @ts-ignore 17import {LitMainMenuItem} from "../../../dist/base-ui/menu/LitMainMenuItem.js"; 18 19describe("litMainMenuItem Test", () => { 20 21 it('litMainMenuItem01', () => { 22 let litMainMenuItem = new LitMainMenuItem(); 23 expect(litMainMenuItem).not.toBeUndefined() 24 expect(litMainMenuItem).not.toBeNull() 25 }); 26 27 it('litMainMenuItem02', () => { 28 let litMainMenuItem = new LitMainMenuItem(); 29 expect(litMainMenuItem.title).toEqual("") 30 }); 31 32 it('litMainMenuItem03', () => { 33 let litMainMenuItem = new LitMainMenuItem(); 34 litMainMenuItem.title ="test" 35 expect(litMainMenuItem.title).toEqual("test") 36 }); 37 38 39 it('litMainMenuItem04', () => { 40 document.body.innerHTML = `<lit-main-menu-item file></lit-main-menu-item> 41 ` 42 let litMainMenuItem = new LitMainMenuItem(); 43 litMainMenuItem.title ="test02" 44 expect(litMainMenuItem.title).toEqual("test02") 45 }); 46 47 it('litMainMenuItem05', () => { 48 document.body.innerHTML = `<lit-main-menu-item></lit-main-menu-item> 49 ` 50 let litMainMenuItem = new LitMainMenuItem(); 51 litMainMenuItem.title ="test03" 52 expect(litMainMenuItem.title).toEqual("test03") 53 }); 54 55 it('litMainMenuItem06', () => { 56 document.body.innerHTML = `<lit-main-menu-item></lit-main-menu-item> 57 ` 58 let litMainMenuItem = new LitMainMenuItem(); 59 expect(litMainMenuItem.isFile()).toBeFalsy(); 60 }); 61 62 it('litMainMenuItem07', () => { 63 document.body.innerHTML = `<lit-main-menu-item></lit-main-menu-item> 64 ` 65 let litMainMenuItem = new LitMainMenuItem(); 66 litMainMenuItem.disabled = true; 67 expect(litMainMenuItem.disabled).toBeTruthy(); 68 }); 69 70 it('litMainMenuItem08', () => { 71 document.body.innerHTML = `<lit-main-menu-item></lit-main-menu-item> 72 ` 73 let litMainMenuItem = new LitMainMenuItem(); 74 litMainMenuItem.disabled = false; 75 expect(litMainMenuItem.disabled).toBeFalsy(); 76 }); 77 78 it('litMainMenuItem09', () => { 79 let litMainMenuItem = new LitMainMenuItem(); 80 expect(litMainMenuItem.initHtml()).toMatchInlineSnapshot(` 81" 82 <style> 83 :host{ 84 user-select: none; 85 display: flex; 86 font-family: Helvetica; 87 opacity: 0.6; 88 font-size: 14px; 89 color: var(--dark-color,rgba(0,0,0,0.6)); 90 text-align: left; 91 line-height: 20px; 92 font-weight: 400 93 background-color: #FFFFFF; 94 transition: background-color .3s; 95 } 96 :host(:not([disabled]):hover){ 97 display: flex; 98 background-color: var(--dark-background8,#0A59F7); 99 color: #FFFFFF; 100 cursor: pointer; 101 } 102 :host([disabled]:hover){ 103 display: flex; 104 /*background-color:#3391FF;*/ 105 /*color: #FFFFFF;*/ 106 cursor:not-allowed; 107 } 108 :host([disabled]) .root{ 109 cursor:not-allowed; 110 display: flex; 111 align-items: center; 112 padding: 10px 24px; 113 width: 100%; 114 } 115 :host(:not([disabled])) .root{ 116 cursor:pointer; 117 display: flex; 118 align-items: center; 119 padding: 10px 24px; 120 width: 100%; 121 } 122 .name{ 123 padding-left: 10px; 124 cursor: pointer; 125 } 126 .icon{ 127 pointer-events: none; 128 } 129 :host(:not([file])) .name{ 130 pointer-events: none; 131 } 132 :host(:not([file])) .root{ 133 pointer-events: none; 134 } 135 :host([file]) .name{ 136 pointer-events: none; 137 } 138 :host([file]) .icon{ 139 pointer-events: none; 140 } 141 142 :host([back]) { 143 background-color: var(--dark-background8,#0A59F7); 144 } 145 146 </style> 147 <input id=\\"file\\" class=\\"file\\" type=\\"file\\" style=\\"display:none;pointer-events: none\\" /> 148 <label class=\\"root\\" for=\\"file\\"> 149 <lit-icon class=\\"icon\\" name=\\"user\\" size=\\"20\\"></lit-icon> 150 <label class=\\"name\\"></label> 151 </label> 152 " 153`); 154 }); 155 it('litMainMenuItem10', () => { 156 let litMainMenuItem = new LitMainMenuItem(); 157 litMainMenuItem.back = true 158 expect(litMainMenuItem.back).toBeTruthy() 159 }) 160 it('litMainMenuItem11', () => { 161 let litMainMenuItem = new LitMainMenuItem(); 162 litMainMenuItem.back = false 163 expect(litMainMenuItem.back).toBeFalsy() 164 }) 165 166 it('litMainMenuItem12', () => { 167 const onclick = jest.fn(); 168 let menuItem = document.body.innerHTML = ` 169 <lit-main-menu-item id='menu'></lit-main-menu-item> 170 ` 171 const menu = document.getElementById('menu'); 172 expect(onclick).not.toBeCalled(); 173 menu!.onclick = onclick; 174 menu!.click(); 175 expect(onclick).toBeCalled(); 176 expect(onclick).toHaveBeenCalledTimes(1); 177 }); 178}) 179