How to use createNull method in ts-auto-mock

Best JavaScript code snippet using ts-auto-mock

legendTests.ts

Source:legendTests.ts Github

copy

Full Screen

...48 });49 it('legend dom validation one legend item count validation',(done) => {50 var legendData: powerbi.visuals.LegendDataPoint[] = [51 {52 label: 'California', color: 'red', icon: LegendIcon.Line, identity: powerbi.visuals.SelectionId.createNull(), selected: false53 }54 ];55 legend.drawLegend({ dataPoints: legendData }, viewport);56 setTimeout(() => {57 expect($('.legendItem').length).toBe(1);58 expect($('.legendText').length).toBe(1);59 expect($('.legendIcon').length).toBe(1);60 done();61 }, DefaultWaitForRender);62 });63 it('legend dom validation three legend items count validation',(done) => {64 var legendData: powerbi.visuals.LegendDataPoint[] = [65 { label: 'California', color: '#ff0000', icon: LegendIcon.Line, identity: powerbi.visuals.SelectionId.createNull(), selected: false },66 { label: 'Texas', color: '#0000ff', icon: LegendIcon.Line, identity: powerbi.visuals.SelectionId.createNull(), selected: false },67 { label: 'Washington', color: '00ff00', icon: LegendIcon.Line, identity: powerbi.visuals.SelectionId.createNull(), selected: false }68 ];69 legend.drawLegend({ dataPoints: legendData }, viewport);70 setTimeout(() => {71 expect($('.legendItem').length).toBe(3);72 expect($('.legendText').length).toBe(3);73 expect($('.legendIcon').length).toBe(3);74 done();75 }, DefaultWaitForRender);76 });77 it('legend dom validation incremental build',(done) => {78 // Draw the legend once with the 3 states79 var initialData: powerbi.visuals.LegendDataPoint[] = [80 { label: 'California', color: '#fff000', icon: LegendIcon.Box, identity: powerbi.visuals.SelectionId.createNull(), selected: false },81 { label: 'Texas', color: '#ff00ff', icon: LegendIcon.Box, identity: powerbi.visuals.SelectionId.createNull(), selected: false },82 { label: 'Washington', color: '#fff000', icon: LegendIcon.Box, identity: powerbi.visuals.SelectionId.createNull(), selected: false }83 ];84 legend.drawLegend({ dataPoints: initialData }, viewport);85 setTimeout(() => {86 validateLegendDOM(initialData);87 // Draw the legend against with a new state at the start88 var legendData: powerbi.visuals.LegendDataPoint[] = [89 { label: 'Alaska', color: '#fff000', icon: LegendIcon.Box, identity: powerbi.visuals.SelectionId.createNull(), selected: false },90 { label: 'California', color: '#fff00d', icon: LegendIcon.Box, identity: powerbi.visuals.SelectionId.createNull(), selected: false },91 { label: 'Texas', color: '#fffe00', icon: LegendIcon.Box, identity: powerbi.visuals.SelectionId.createNull(), selected: false },92 { label: 'Washington', color: '#0000dd', icon: LegendIcon.Box, identity: powerbi.visuals.SelectionId.createNull(), selected: false }93 ];94 legend.reset();95 legend.drawLegend({ dataPoints: legendData }, viewport);96 setTimeout(() => {97 validateLegendDOM(legendData);98 done();99 }, DefaultWaitForRender);100 }, DefaultWaitForRender);101 });102 it('legend dom validation three legend items first item text',(done) => {103 var legendData: powerbi.visuals.LegendDataPoint[] = [104 { label: 'California', color: 'red', icon: LegendIcon.Line, identity: powerbi.visuals.SelectionId.createNull(), selected: false },105 { label: 'Texas', color: 'blue', icon: LegendIcon.Line, identity: powerbi.visuals.SelectionId.createNull(), selected: false },106 { label: 'Washington', color: 'green', icon: LegendIcon.Line, identity: powerbi.visuals.SelectionId.createNull(), selected: false }107 ];108 legend.reset();109 legend.drawLegend({ dataPoints: legendData }, viewport);110 setTimeout(() => {111 expect($('.legendText').first().text()).toBe('California');112 done();113 }, DefaultWaitForRender);114 });115 it('legend dom validation three legend items last item text',(done) => {116 var legendData: powerbi.visuals.LegendDataPoint[] = [117 { label: 'California', color: 'red', icon: LegendIcon.Line, identity: powerbi.visuals.SelectionId.createNull(), selected: false },118 { label: 'Texas', color: 'blue', icon: LegendIcon.Line, identity: powerbi.visuals.SelectionId.createNull(), selected: false },119 { label: 'Washington', color: 'green', icon: LegendIcon.Line, identity: powerbi.visuals.SelectionId.createNull(), selected: false }120 ];121 legend.drawLegend({ dataPoints: legendData }, viewport);122 setTimeout(() => {123 expect($('.legendText').last().text()).toBe('Washington');124 done();125 }, DefaultWaitForRender);126 });127 it('legend dom validation three legend items colors count',(done) => {128 var legendData: powerbi.visuals.LegendDataPoint[] = [129 { label: 'California', color: 'red', icon: LegendIcon.Line, identity: powerbi.visuals.SelectionId.createNull(), selected: false },130 { label: 'Texas', color: 'blue', icon: LegendIcon.Line, identity: powerbi.visuals.SelectionId.createNull(), selected: false },131 { label: 'Washington', color: 'green', icon: LegendIcon.Line, identity: powerbi.visuals.SelectionId.createNull(), selected: false }132 ];133 legend.drawLegend({ dataPoints: legendData }, viewport);134 setTimeout(() => {135 expect($('.legendIcon').length).toBe(3);136 done();137 }, DefaultWaitForRender);138 });139 it('legend defaults',() => {140 var legendArray = getLotsOfLegendData();141 var legendData: powerbi.visuals.LegendData = { dataPoints: legendArray, title: '' };142 var props: powerbi.DataViewObject = {};143 powerbi.visuals.LegendData.update(legendData, props);144 expect(props[powerbi.visuals.legendProps.show]).toBe(true);145 expect(props[powerbi.visuals.legendProps.position]).toEqual(powerbi.legendPosition.top);146 });147 it('legend with title',() => {148 var legendData = getLotsOfLegendData();149 legend.drawLegend({ dataPoints: legendData, title: 'states' }, viewport);150 powerbi.visuals.SVGUtil.flushAllD3Transitions();151 expect($('.legendTitle').length).toBe(1);152 });153 it('legend with long title on Right',() => {154 var legendData = getLotsOfLegendData();155 legend.changeOrientation(LegendPosition.Right);156 legend.drawLegend({ dataPoints: legendData, title: 'This is a super long title and should be truncated by now' }, viewport);157 powerbi.visuals.SVGUtil.flushAllD3Transitions();158 expect($('.legendTitle').text()).toEqual('This is a super long title...');159 });160 it('legend no title',() => {161 var legendData = getLotsOfLegendData();162 legend.drawLegend({ dataPoints: legendData }, viewport);163 powerbi.visuals.SVGUtil.flushAllD3Transitions();164 expect($('.legendTitle').length).toBe(0);165 });166 it('legend Top & horizontal trim',() => {167 var legendData = getLotsOfLegendData();168 legend.changeOrientation(LegendPosition.Top);169 legend.drawLegend({ dataPoints: legendData }, { height: 100, width: 1000 });170 powerbi.visuals.SVGUtil.flushAllD3Transitions();171 expect($('.legendItem').length).toBeGreaterThan(5);172 expect($('.legendItem').length).toBeLessThan(52);173 });174 it('legend Bottom & horizontal trim',() => {175 var legendData = getLotsOfLegendData();176 legend.changeOrientation(LegendPosition.Bottom);177 legend.drawLegend({ dataPoints: legendData }, { height: 100, width: 1000 });178 powerbi.visuals.SVGUtil.flushAllD3Transitions();179 expect($('.legendItem').length).toBeGreaterThan(5);180 expect($('.legendItem').length).toBeLessThan(52);181 });182 it('legend Left & vertical trim',() => {183 var legendData = getLotsOfLegendData();184 legend.changeOrientation(LegendPosition.Left);185 legend.drawLegend({ dataPoints: legendData }, { height: 200, width: 1000 });186 powerbi.visuals.SVGUtil.flushAllD3Transitions();187 expect($('.legendItem').length).toBeGreaterThan(5);188 expect($('.legendItem').length).toBeLessThan(52);189 });190 it('legend Right & vertical trim',() => {191 var legendData = getLotsOfLegendData();192 legend.changeOrientation(LegendPosition.Right);193 legend.drawLegend({ dataPoints: legendData }, { height: 200, width: 1000 });194 powerbi.visuals.SVGUtil.flushAllD3Transitions();195 expect($('.legendItem').length).toBeGreaterThan(5);196 expect($('.legendItem').length).toBeLessThan(52);197 });198 it('Intelligent Layout: Low label count should result in longer max-width',() => {199 var legendData = [{200 label: 'Really long label, but i have the space to show',201 color: 'red',202 icon: LegendIcon.Line,203 identity: powerbi.visuals.SelectionId.createNull(), selected: false204 }];205 legend.changeOrientation(LegendPosition.Top);206 legend.drawLegend({ dataPoints: legendData }, { height: 100, width: 1000 });207 powerbi.visuals.SVGUtil.flushAllD3Transitions();208 expect($('.legendItem').length).toBe(1);209 expect($($('.legendText')[0]).text()).not.toContain('...');210 });211 it('Intelligent Layout: Lots of small labels should get compacted in horizontal layout',() => {212 var legendData = getLotsOfLegendData();213 legend.changeOrientation(LegendPosition.Top);214 legend.drawLegend({ dataPoints: legendData }, { height: 100, width: 1000 });215 powerbi.visuals.SVGUtil.flushAllD3Transitions();216 expect($('.legendItem').length).toBe(25);217 });218 it('Intelligent Layout: If labels in horizontal layout have small widths, width of legend should be small',() => {219 var legendData = getLotsOfLegendData();220 legend.changeOrientation(LegendPosition.Right);221 legend.drawLegend({ dataPoints: legendData }, { height: 100, width: 1000 });222 powerbi.visuals.SVGUtil.flushAllD3Transitions();223 expect(legend.getMargins().width).toBeLessThan(200);224 });225 it('Intelligent Layout: If labels in horizontal layout have large widths, width of legend should be 30% of viewport',() => {226 var legendData = [{227 label: 'I am a really long label, but you should not allow me to take more than 300px',228 color: 'red',229 icon: LegendIcon.Line,230 identity: powerbi.visuals.SelectionId.createNull(), selected: false231 }];232 legend.changeOrientation(LegendPosition.Right);233 legend.drawLegend({ dataPoints: legendData }, { height: 100, width: 1000 });234 powerbi.visuals.SVGUtil.flushAllD3Transitions();235 expect(legend.getMargins().width).toBe(300);236 });237 it('Intelligent Layout: Only right arrow shown at start ',() => {238 var legendData = getLotsOfLegendData();239 legend.changeOrientation(LegendPosition.Top);240 legend.drawLegend({ dataPoints: legendData }, { height: 100, width: 1000 });241 powerbi.visuals.SVGUtil.flushAllD3Transitions();242 expect($('.navArrow').length).toBe(1);243 });244 it('Intelligent Layout: No arrows when you have enough horizontal space ',() => {245 var legendData = [{246 label: 'Skywalker',247 color: 'red',248 icon: LegendIcon.Line,249 identity: powerbi.visuals.SelectionId.createNull(), selected: false250 },{251 label: 'The End',252 color: 'blue',253 icon: LegendIcon.Line,254 identity: powerbi.visuals.SelectionId.createNull(), selected: false255 }];256 legend.changeOrientation(LegendPosition.Bottom);257 legend.drawLegend({ dataPoints: legendData }, { height: 100, width: 1000 });258 powerbi.visuals.SVGUtil.flushAllD3Transitions();259 expect($('.navArrow').length).toBe(0);260 });261 it('Intelligent Layout: No arrows when you have enough vertical space ',() => {262 var legendData = [{263 label: 'Skywalker',264 color: 'red',265 icon: LegendIcon.Line,266 identity: powerbi.visuals.SelectionId.createNull(), selected: false267 }, {268 label: 'The End',269 color: 'blue',270 icon: LegendIcon.Line,271 identity: powerbi.visuals.SelectionId.createNull(), selected: false272 }];273 legend.changeOrientation(LegendPosition.Right);274 legend.drawLegend({ dataPoints: legendData }, { height: 100, width: 1000 });275 powerbi.visuals.SVGUtil.flushAllD3Transitions();276 expect($('.navArrow').length).toBe(0);277 });278 it('Intelligent Layout: No arrows when you have enough horizontal space, but appears on resize ',() => {279 var legendData = [{280 label: 'Skywalker',281 color: 'red',282 icon: LegendIcon.Line,283 identity: powerbi.visuals.SelectionId.createNull(), selected: false284 }, {285 label: 'The End',286 color: 'blue',287 icon: LegendIcon.Line,288 identity: powerbi.visuals.SelectionId.createNull(), selected: false289 }];290 legend.changeOrientation(LegendPosition.Top);291 legend.drawLegend({ dataPoints: legendData }, { height: 100, width: 1000 });292 powerbi.visuals.SVGUtil.flushAllD3Transitions();293 expect($('.navArrow').length).toBe(0);294 legend.drawLegend({ dataPoints: legendData }, { height: 100, width: 100 });295 powerbi.visuals.SVGUtil.flushAllD3Transitions();296 expect($('.navArrow').length).toBe(1);297 });298 it('Intelligent Layout: No arrows when you have enough vertical space, but appears on resize ',() => {299 var legendData = [{300 label: 'Skywalker',301 color: 'red',302 icon: LegendIcon.Line,303 identity: powerbi.visuals.SelectionId.createNull(), selected: false304 }, {305 label: 'The End',306 color: 'blue',307 icon: LegendIcon.Line,308 identity: powerbi.visuals.SelectionId.createNull(), selected: false309 }];310 legend.changeOrientation(LegendPosition.Right);311 legend.drawLegend({ dataPoints: legendData }, { height: 100, width: 1000 });312 powerbi.visuals.SVGUtil.flushAllD3Transitions();313 expect($('.navArrow').length).toBe(0);314 legend.drawLegend({ dataPoints: legendData }, { height: 20, width: 100 });315 powerbi.visuals.SVGUtil.flushAllD3Transitions();316 expect($('.navArrow').length).toBe(1);317 });318 it('Intelligent Layout: Only down arrow shown at start ',() => {319 var legendData = getLotsOfLegendData();320 legend.changeOrientation(LegendPosition.Right);321 legend.drawLegend({ dataPoints: legendData }, { height: 100, width: 1000 });322 powerbi.visuals.SVGUtil.flushAllD3Transitions();323 expect($('.navArrow').length).toBe(1);324 });325 it('Intelligent Layout: Only down arrow shown at start ',() => {326 var legendData = getLotsOfLegendData();327 legend.changeOrientation(LegendPosition.Right);328 legend.drawLegend({ dataPoints: legendData }, { height: 100, width: 1000 });329 powerbi.visuals.SVGUtil.flushAllD3Transitions();330 expect($('.navArrow').length).toBe(1);331 });332 it('Intelligent Layout: Second arrow appears when you page right',() => {333 var legendData = getLotsOfLegendData();334 legend.changeOrientation(LegendPosition.Top);335 legend.drawLegend({ dataPoints: legendData }, { height: 100, width: 1000 });336 powerbi.visuals.SVGUtil.flushAllD3Transitions();337 expect($('.navArrow').length).toBe(1);338 (<any>$('.navArrow').first()).d3Click(0, 0);339 expect($('.navArrow').length).toBe(2);340 });341 it('Intelligent Layout: Second arrow appears when you page down',() => {342 var legendData = getLotsOfLegendData();343 legend.changeOrientation(LegendPosition.Left);344 legend.drawLegend({ dataPoints: legendData }, { height: 100, width: 1000 });345 powerbi.visuals.SVGUtil.flushAllD3Transitions();346 expect($('.navArrow').length).toBe(1);347 (<any>$('.navArrow').first()).d3Click(0, 0);348 expect($('.navArrow').length).toBe(2);349 });350 it('Intelligent Layout: Second arrow disappears when you page rigth to last page',() => {351 var legendData = getLotsOfLegendData();352 legend.changeOrientation(LegendPosition.Top);353 legend.drawLegend({ dataPoints: legendData }, { height: 100, width: 1000 });354 powerbi.visuals.SVGUtil.flushAllD3Transitions();355 expect($('.navArrow').length).toBe(1);356 (<any>$('.navArrow').first()).d3Click(0, 0);357 expect($('.navArrow').length).toBe(2);358 (<any>$('.navArrow').last()).d3Click(0, 0);359 expect($('.navArrow').length).toBe(1);360 });361 it('Intelligent Layout: Second arrow disappears when you page down to last page',() => {362 var legendData = getLotsOfLegendData();363 legend.changeOrientation(LegendPosition.Right);364 legend.drawLegend({ dataPoints: legendData }, { height: 500, width: 1000 });365 powerbi.visuals.SVGUtil.flushAllD3Transitions();366 expect($('.navArrow').length).toBe(1);367 (<any>$('.navArrow').first()).d3Click(0, 0);368 expect($('.navArrow').length).toBe(2);369 (<any>$('.navArrow').last()).d3Click(0, 0);370 expect($('.navArrow').length).toBe(1);371 });372 it('legend interactivity test ', () => {373 var scopeId1 = powerbitests.mocks.dataViewScopeIdentity('California');374 var scopeId2 = powerbitests.mocks.dataViewScopeIdentity('Texas');375 var scopeId3 = powerbitests.mocks.dataViewScopeIdentity('Washington');376 var legendData = [377 { label: 'California', color: '#ff0000', icon: LegendIcon.Line, identity: powerbi.visuals.SelectionId.createWithId(scopeId1), selected: false },378 { label: 'Texas', color: '#0000ff', icon: LegendIcon.Line, identity: powerbi.visuals.SelectionId.createWithId(scopeId2), selected: false },379 { label: 'Washington', color: '#00ff00', icon: LegendIcon.Line, identity: powerbi.visuals.SelectionId.createWithId(scopeId3), selected: false }380 ];381 var viewport = {382 height: 500,383 width: 500384 };385 legend = powerbi.visuals.createLegend(element, false, interactivityService);386 legend.drawLegend({ title: "Top Data", dataPoints: legendData }, viewport);387 var icons = $('.legendIcon');388 spyOn(hostServices, 'onSelect').and.callThrough();389 // Click first legend390 (<any>icons.first()).d3Click(0, 0);391 expect(icons[0].style.fill).toBe('#ff0000');392 expect(icons[1].style.fill).toBe('#a6a6a6');393 expect(icons[2].style.fill).toBe('#a6a6a6');394 395 // Click the last legend item, should just select current and clear others396 (<any>icons.last()).d3Click(0, 0);397 expect(icons[0].style.fill).toBe('#a6a6a6');398 expect(icons[1].style.fill).toBe('#a6a6a6');399 expect(icons[2].style.fill).toBe('#00ff00');400 401 // Control + Click legend item, should multiselect402 (<any>icons.first()).d3Click(0, 0, powerbitests.helpers.ClickEventType.CtrlKey);403 expect(icons[0].style.fill).toBe('#ff0000');404 expect(icons[1].style.fill).toBe('#a6a6a6');405 //expect(icons[2].style.fill).toBe('#00ff00');406 407 // Click the clear catcher should clear the legend selection408 (<any>($('.clearCatcher').first())).d3Click(0, 0);409 expect(icons[0].style.fill).toBe('#ff0000');410 expect(icons[1].style.fill).toBe('#0000ff');411 expect(icons[2].style.fill).toBe('#00ff00');412 413 });414 function validateLegendDOM(expectedData: powerbi.visuals.LegendDataPoint[]): void {415 var len = expectedData.length;416 var labels = $('.legendText');417 expect(labels.length).toBe(len);418 var icons = $('.legendIcon');419 expect(icons.length).toBe(len);420 for (var i = 0; i < len; ++i) {421 var expectedDatum = expectedData[i];422 expect($(labels.get(i)).text()).toBe(expectedDatum.label);423 expect($(icons.get(i)).css('fill')).toBe(expectedDatum.color);424 }425 }426 function getLotsOfLegendData(): powerbi.visuals.LegendDataPoint[] {427 var states = ['AL', 'AK', 'AS', 'AZ', 'AR', 'CA', 'CO',428 'CT', 'DE', 'DC', 'FM', 'FL', 'GA', 'GU', 'HI', 'ID',429 'IL', 'IN', 'IA', 'KS', 'KY', 'LA', 'ME', 'MH', 'MD',430 'MA', 'MI', 'MN', 'MS', 'MO', 'MT', 'NE', 'NV', 'NH',431 'NJ', 'NM', 'NY', 'NC', 'ND', 'MP', 'OH', 'OK', 'OR',432 'PW', 'PA', 'PR', 'RI', 'SC', 'SD', 'TN', 'TX', 'UT',433 'VT', 'VI', 'VA', 'WA', 'WV', 'WI', 'WY', 'AE', 'AA',434 'AP'];435 var colors = d3.scale.category20c();436 var legendData: powerbi.visuals.LegendDataPoint[] = [];437 for (var i = 0; i < states.length; i++) {438 legendData.push({ label: states[i], color: colors(i), icon: LegendIcon.Line, identity: powerbi.visuals.SelectionId.createNull(), selected: false });439 }440 return legendData;441 }442});443 describe("interactive legend DOM validation",() => {444 var element: JQuery;445 var viewport: powerbi.IViewport;446 var legend: ILegend;447 var colorStyle = 'color: {0};';448 var defaultLegendHeight = 65;449 var interactivityService: IInteractivityService;450 beforeEach(() => {451 element = powerbitests.helpers.testDom('500', '500');452 var hostServices = powerbitests.mocks.createVisualHostServices();453 interactivityService = powerbi.visuals.createInteractivityService(hostServices);454 legend = powerbi.visuals.createLegend(element, true, interactivityService);455 });456 it('legend dom validation one legend item count validation',(done) => {457 var legendData: powerbi.visuals.LegendDataPoint[] = [458 { category: 'state', label: 'California', color: 'red', icon: LegendIcon.Line, measure: 5, identity: powerbi.visuals.SelectionId.createNull(), selected: false }459 ];460 legend.drawLegend({ dataPoints: legendData }, viewport);461 setTimeout(() => {462 expect($('.interactive-legend .title').length).toBe(1);463 expect($('.interactive-legend .item').length).toBe(1);464 done();465 }, DefaultWaitForRender);466 });467 it('legend dom validation three legend items count validation',(done) => {468 var legendData: powerbi.visuals.LegendDataPoint[] = [469 { category: 'state', label: 'California', color: 'red', icon: LegendIcon.Line, measure: 5, identity: powerbi.visuals.SelectionId.createNull(), selected: false },470 { category: 'state', label: 'Texas', color: 'blue', icon: LegendIcon.Line, measure: 10, identity: powerbi.visuals.SelectionId.createNull(), selected: false },471 { category: 'state', label: 'Washington', color: 'green', icon: LegendIcon.Line, measure: 15, identity: powerbi.visuals.SelectionId.createNull(), selected: false },472 ];473 legend.drawLegend({ dataPoints: legendData }, viewport);474 setTimeout(() => {475 expect($('.interactive-legend .title').length).toBe(1);476 expect($('.interactive-legend .item').length).toBe(3);477 done();478 }, DefaultWaitForRender);479 });480 it('legend dom validation incremental build',(done) => {481 // Draw the legend once with the 3 states482 var initialData: powerbi.visuals.LegendDataPoint[] = [483 { category: 'state', label: 'California', color: 'red', icon: LegendIcon.Box, measure: 5, identity: powerbi.visuals.SelectionId.createNull(), selected: false },484 { category: 'state', label: 'Texas', color: 'blue', icon: LegendIcon.Box, measure: 10, identity: powerbi.visuals.SelectionId.createNull(), selected: false },485 { category: 'state', label: 'Washington', color: 'green', icon: LegendIcon.Box, measure: 15, identity: powerbi.visuals.SelectionId.createNull(), selected: false },486 ];487 legend.drawLegend({ dataPoints: initialData }, viewport);488 setTimeout(() => {489 validateLegendDOM(initialData);490 // Draw the legend against with a new state at the start491 var legendData: powerbi.visuals.LegendDataPoint[] = [492 { category: 'state', label: 'Alaska', color: 'red', icon: LegendIcon.Box, measure: 0, identity: powerbi.visuals.SelectionId.createNull(), selected: false },493 { category: 'state', label: 'California', color: 'blue', icon: LegendIcon.Box, measure: 5, identity: powerbi.visuals.SelectionId.createNull(), selected: false },494 { category: 'state', label: 'Texas', color: 'green', icon: LegendIcon.Box, measure: 10, identity: powerbi.visuals.SelectionId.createNull(), selected: false },495 { category: 'state', label: 'Washington', color: 'orange', icon: LegendIcon.Box, measure: 15, identity: powerbi.visuals.SelectionId.createNull(), selected: false },496 ];497 legend.reset();498 legend.drawLegend({ dataPoints: legendData }, viewport);499 setTimeout(() => {500 validateLegendDOM(legendData);501 done();502 }, DefaultWaitForRender);503 }, DefaultWaitForRender);504 });505 it('legend dom validation three legend items first item name and measure',(done) => {506 var legendData: powerbi.visuals.LegendDataPoint[] = [507 { category: 'state', label: 'Alaska', color: 'red', icon: LegendIcon.Box, measure: 0, identity: powerbi.visuals.SelectionId.createNull(), selected: false },508 { category: 'state', label: 'California', color: 'blue', icon: LegendIcon.Box, measure: 5, identity: powerbi.visuals.SelectionId.createNull(), selected: false },509 { category: 'state', label: 'Texas', color: 'green', icon: LegendIcon.Box, measure: 10, identity: powerbi.visuals.SelectionId.createNull(), selected: false },510 ];511 legend.drawLegend({ dataPoints: legendData }, viewport);512 setTimeout(() => {513 expect($('.interactive-legend .title').text()).toBe(legendData[0].category);514 expect($('.interactive-legend .item').first().find('.itemName').text().trim()).toBe('Alaska');515 expect($('.interactive-legend .item').first().find('.itemMeasure').text().trim()).toBe('0');516 done();517 }, DefaultWaitForRender);518 });519 it('legend dom validation three legend items last item name and measure',(done) => {520 var legendData: powerbi.visuals.LegendDataPoint[] = [521 { category: 'state', label: 'Alaska', color: 'red', icon: LegendIcon.Box, measure: 0, identity: powerbi.visuals.SelectionId.createNull(), selected: false },522 { category: 'state', label: 'California', color: 'blue', icon: LegendIcon.Box, measure: 5, identity: powerbi.visuals.SelectionId.createNull(), selected: false },523 { category: 'state', label: 'Texas', color: 'green', icon: LegendIcon.Box, measure: 10, identity: powerbi.visuals.SelectionId.createNull(), selected: false },524 ];525 legend.drawLegend({ dataPoints: legendData }, viewport);526 setTimeout(() => {527 expect($('.interactive-legend .title').text()).toBe(legendData[0].category);528 // last item is actually the second item since values should be placed in a two-row table.529 expect($('.interactive-legend .item').last().find('.itemName').text().trim()).toBe('California');530 expect($('.interactive-legend .item').last().find('.itemMeasure').text().trim()).toBe('5');531 done();532 }, DefaultWaitForRender);533 });534 it('legend dom validation three legend items colors count',(done) => {535 var legendData: powerbi.visuals.LegendDataPoint[] = [536 { category: 'state', label: 'Alaska', color: 'red', icon: LegendIcon.Box, measure: 0, identity: powerbi.visuals.SelectionId.createNull(), selected: false },537 { category: 'state', label: 'California', color: 'blue', icon: LegendIcon.Box, measure: 5, identity: powerbi.visuals.SelectionId.createNull(), selected: false },538 { category: 'state', label: 'Texas', color: 'green', icon: LegendIcon.Box, measure: 10, identity: powerbi.visuals.SelectionId.createNull(), selected: false },539 ];540 legend.drawLegend({ dataPoints: legendData }, viewport);541 setTimeout(() => {542 expect($('.interactive-legend .icon').length).toBe(3);543 done();544 }, DefaultWaitForRender);545 });546 // Legend Height tests - legend height is constant regardless of data.547 it('legend getHeight empty',() => {548 expect(legend.getMargins().height).toBe(defaultLegendHeight);549 });550 it('legend getHeight no data',() => {551 legend.drawLegend({ dataPoints: [] }, viewport);552 expect(legend.getMargins().height).toBe(defaultLegendHeight);553 });554 it('legend getHeight data',() => {555 legend.drawLegend({556 dataPoints: [557 { category: 'state', label: 'Alaska', color: 'red', icon: LegendIcon.Box, measure: 0, identity: powerbi.visuals.SelectionId.createNull(), selected: false },558 { category: 'state', label: 'California', color: 'blue', icon: LegendIcon.Box, measure: 5, identity: powerbi.visuals.SelectionId.createNull(), selected: false },559 { category: 'state', label: 'Texas', color: 'green', icon: LegendIcon.Box, measure: 10, identity: powerbi.visuals.SelectionId.createNull(), selected: false },560 ]561 }, viewport);562 expect(legend.getMargins().height).toBe(defaultLegendHeight);563 });564 it('legend getHeight one data point',() => {565 legend.drawLegend({566 dataPoints: [567 { category: 'state', label: 'Alaska', color: 'red', icon: LegendIcon.Box, measure: 0, identity: powerbi.visuals.SelectionId.createNull(), selected: false },568 ]569 }, viewport);570 expect(legend.getMargins().height).toBe(defaultLegendHeight);571 });572 function validateLegendDOM(expectedData: powerbi.visuals.LegendDataPoint[]): void {573 var len = expectedData.length;574 var items = $('.interactive-legend .item');575 expect($('.interactive-legend .title').length).toBe(1);576 expect(items.length).toBe(len);577 var icons = $('.interactive-legend .icon');578 expect(icons.length).toBe(len);579 // items are returned from the table, first row and then second row.580 // rearrage it to match the way the legend outputs it: by columns.581 var rearrangedItems = [];...

Full Screen

Full Screen

obdDevice.test.js

Source:obdDevice.test.js Github

copy

Full Screen

...4} = require('../obdDevice')5describe('ObdDevice', () => {6 describe('connect', () => {7 test('should forward connected event when obd device connects', () => {8 const obd = ObdDevice.createNull();9 this.eventTriggered = false;10 obd.on(ObdDeviceEvent.CONNECTED, () => { this.eventTriggered = true; });11 obd.connect();12 13 expect(this.eventTriggered).toBe(true);14 });15 test('should connect with env var address and channel', () => {16 const obd = ObdDevice.createNull('my_address', 10);17 obd.connect();18 19 expect(obd.isConnected()).toBe(true);20 expect(obd.getAddress()).toBe('my_address');21 expect(obd.getChannel()).toBe(10);22 });23 });24 describe('responseReceived event', () => {25 test('should forward response received event when obd device receives data', () => {26 const obd = ObdDevice.createNull();27 obd.on(ObdDeviceEvent.RESPONSE_RECEIVED, (data) => { responseData = data; });28 obd.simulateResponseReceived('my_data');29 30 expect(responseData).toBe('my_data');31 });32 });33 describe('write', () => {34 test('should write to OBD device', () => {35 const obd = ObdDevice.createNull();36 const sentMessages = trackSentMessages(obd)37 obd.write('my_message');38 39 expect(sentMessages).toContain('my_message');40 });41 test('should trigger event when message is written', () => {42 const obd = ObdDevice.createNull()43 const writes = [ 'ATX1', 'ATX2', 'ATX3', 'ATX4', 'ATX5' ]44 const sentMessages = trackSentMessages(obd)45 writes.map(x => { obd.write(x) })46 expect(sentMessages).toEqual(writes)47 });48 function trackSentMessages(obd) {49 const sentMessages = []50 obd.on(ObdDeviceEvent.WRITE_MSG, (message) => {51 sentMessages.push(message)52 })53 return sentMessages;54 }55 });56 describe('pollPids', () => {57 test('should add PIDs to active pollers list', () => {58 const obd = ObdDevice.createNull();59 const pids = ['pid1', 'pid2']60 obd.addPollers(pids);61 expect(obd.getActivePollers()).toEqual(pids)62 })63 });64 describe('startPolling', () => {65 test('should emit startPolling event', () => {66 const obd = ObdDevice.createNull();67 this.eventTriggered = false;68 obd.on(ObdDeviceEvent.STARTED_POLLING, () => { this.eventTriggered = true; });69 obd.startPolling();70 expect(this.eventTriggered).toBeTruthy();71 })72 });...

Full Screen

Full Screen

Using AI Code Generation

copy

Full Screen

1import { createNull } from 'ts-auto-mock';2const myMock = createNull<MyInterface>();3import { createNull } from 'ts-auto-mock';4const myMock = createNull<MyInterface>();5import { createNull } from 'ts-auto-mock';6const myMock = createNull<MyInterface>();7import { createNull } from 'ts-auto-mock';8const myMock = createNull<MyInterface>();9import { createNull } from 'ts-auto-mock';10const myMock = createNull<MyInterface>();11import { createNull } from 'ts-auto-mock';12const myMock = createNull<MyInterface>();13import { createNull } from 'ts-auto-mock';14const myMock = createNull<MyInterface>();15import { createNull } from 'ts-auto-mock';16const myMock = createNull<MyInterface>();17import { createNull } from 'ts-auto-mock';18const myMock = createNull<MyInterface>();19import { createNull } from 'ts-auto-mock';20const myMock = createNull<MyInterface>();21import { createNull } from 'ts-auto-mock';22const myMock = createNull<MyInterface>();23import { createNull } from 'ts-auto-mock';24const myMock = createNull<MyInterface>();25import { createNull } from

Full Screen

Using AI Code Generation

copy

Full Screen

1import { createNull } from 'ts-auto-mock';2const test1 = createNull<MyInterface>();3console.log(test1);4import { createNull } from 'ts-auto-mock';5const test2 = createNull<MyInterface>();6console.log(test2);7import { createNull } from 'ts-auto-mock';8const test3 = createNull<MyInterface>();9console.log(test3);10import { createNull } from 'ts-auto-mock';11const test4 = createNull<MyInterface>();12console.log(test4);13import { createNull } from 'ts-auto-mock';14const test5 = createNull<MyInterface>();15console.log(test5);16import { createNull } from 'ts-auto-mock';17const test6 = createNull<MyInterface>();18console.log(test6);19import { createNull } from 'ts-auto-mock';20const test7 = createNull<MyInterface>();21console.log(test7);22import { createNull } from 'ts-auto-mock';23const test8 = createNull<MyInterface>();24console.log(test8);25import { createNull } from 'ts-auto-mock';26const test9 = createNull<MyInterface>();27console.log(test9);28import { createNull } from 'ts-auto-mock';29const test10 = createNull<MyInterface>();30console.log(test10);31import { createNull } from 'ts-auto-mock';32const test11 = createNull<MyInterface>();33console.log(test11);

Full Screen

Using AI Code Generation

copy

Full Screen

1import {createNull} from 'ts-auto-mock';2const result = createNull<test1>();3import {createNull} from 'ts-auto-mock';4const result = createNull<test2>();5import {createNull} from 'ts-auto-mock';6const result = createNull<test3>();7import {createNull} from 'ts-auto-mock';8const result = createNull<test4>();9import {createNull} from 'ts-auto-mock';10const result = createNull<test5>();11import {createNull} from 'ts-auto-mock';12const result = createNull<test6>();13import {createNull} from 'ts-auto-mock';14const result = createNull<test7>();15import {createNull} from 'ts-auto-mock';16const result = createNull<test8>();17import {createNull} from 'ts-auto-mock';18const result = createNull<test9>();19import {createNull} from 'ts-auto-mock';20const result = createNull<test10>();21import {createNull} from 'ts-auto-mock';22const result = createNull<test11>();23import {createNull} from 'ts-auto-mock';24const result = createNull<test12>();25import {createNull} from

Full Screen

Using AI Code Generation

copy

Full Screen

1import { createNull } from 'ts-auto-mock';2export interface Test1 {3 prop1: string;4 prop2: number;5}6export const test1: Test1 = createNull<Test1>();7import { createNull } from 'ts-auto-mock';8export interface Test2 {9 prop1: string;10 prop2: number;11}12export const test2: Test2 = createNull<Test2>();13import { createNull } from 'ts-auto-mock';14export interface Test3 {15 prop1: string;16 prop2: number;17}18export const test3: Test3 = createNull<Test3>();19import { test1 } from './test1';20import { test2 } from './test2';21import { test3 } from './test3';22console.log('test1', test1);23console.log('test2', test2);24console.log('test3', test3);25test1 { prop1: '', prop2: 0 }26test2 { prop1: '', prop2: 0 }27test3 { prop1: '', prop2: 0 }28test1 { prop1: '', prop2: 0 }29test2 { prop1: '', prop2: 0 }30test3 { prop1: '', prop2: 0 }31{32 "compilerOptions": {

Full Screen

Using AI Code Generation

copy

Full Screen

1import { createNull } from 'ts-auto-mock';2import { Example } from './example';3const example: Example = createNull();4console.log(example);5export interface Example {6 a: string;7 b: number;8 c: boolean;9 d: string[];10 e: number[];11 f: boolean[];12 g: Example;13 h: Example[];14}15import { create, createNull } from 'ts-auto-mock';16const example = create<Example>({17 a: createNull(),18 b: createNull(),19 c: createNull(),20 d: createNull(),21 e: createNull(),22 f: createNull(),23 g: createNull(),24 h: createNull(),25});26console.log(example);27import { createMock, createNull } from 'ts-auto-mock';28const example = createMock<Example>({29 a: createNull(),30 b: createNull(),31 c: createNull(),32 d: createNull(),33 e: createNull(),34 f: createNull(),35 g: createNull(),36 h: createNull(),37});38console.log(example);

Full Screen

Using AI Code Generation

copy

Full Screen

1const { createNull } = require('ts-auto-mock');2const mock = createNull('test1');3console.log('mock: ', mock);4const { createNull } = require('ts-auto-mock');5const mock = createNull('test2');6console.log('mock: ', mock);7const { createNull } = require('ts-auto-mock');8const mock = createNull('test3');9console.log('mock: ', mock);10const { createNull } = require('ts-auto-mock');11const mock = createNull('test4');12console.log('mock: ', mock);13const { createNull } = require('ts-auto-mock');14const mock = createNull('test5');15console.log('mock: ', mock);16const { createNull } = require('ts-auto-mock');17const mock = createNull('test6');18console.log('mock: ', mock);19const { createNull } = require('ts-auto-mock');20const mock = createNull('test7');21console.log('mock: ', mock);22const { createNull } = require('ts-auto-mock');23const mock = createNull('test8');24console.log('mock: ', mock);25const { createNull } = require('ts-auto-mock');26const mock = createNull('test9');27console.log('mock: ', mock);28const { createNull } = require('ts-auto-mock');29const mock = createNull('test10');30console.log('mock: ', mock);

Full Screen

Using AI Code Generation

copy

Full Screen

1const createNull = require('ts-auto-mock').createNull;2const myInterface = createNull('MyInterface');3const createNull = require('ts-auto-mock').createNull;4const myInterface = createNull('MyInterface');5const createNull = require('ts-auto-mock').createNull;6const myInterface = createNull('MyInterface');7const createNull = require('ts-auto-mock').createNull;8const myInterface = createNull('MyInterface');9const createNull = require('ts-auto-mock').createNull;10const myInterface = createNull('MyInterface');11const createNull = require('ts-auto-mock').createNull;12const myInterface = createNull('MyInterface');13const createNull = require('ts-auto-mock').createNull;14const myInterface = createNull('MyInterface');15const createNull = require('ts-auto-mock').createNull;16const myInterface = createNull('MyInterface');

Full Screen

Using AI Code Generation

copy

Full Screen

1import { createNull } from 'ts-auto-mock';2import { Test1 } from './test1';3const nullValue: Test1 = createNull<Test1>();4import { createNull } from 'ts-auto-mock';5import { Test2 } from './test2';6const nullValue: Test2 = createNull<Test2>();7import { createNull } from 'ts-auto-mock';8import { Test3 } from './test3';9const nullValue: Test3 = createNull<Test3>();10import { createNull } from 'ts-auto-mock';11import { Test4 } from './test4';12const nullValue: Test4 = createNull<Test4>();13import { createNull } from 'ts-auto-mock';14import { Test5 } from './test5';15const nullValue: Test5 = createNull<Test5>();16import { createNull } from 'ts-auto-mock';17import { Test6 } from './test6';18const nullValue: Test6 = createNull<Test6>();19import { createNull } from 'ts-auto-mock';20import { Test7 } from './test7';21const nullValue: Test7 = createNull<Test7>();22import { createNull } from 'ts-auto-mock';23import { Test

Full Screen

Automation Testing Tutorials

Learn to execute automation testing from scratch with LambdaTest Learning Hub. Right from setting up the prerequisites to run your first automation test, to following best practices and diving deeper into advanced test scenarios. LambdaTest Learning Hubs compile a list of step-by-step guides to help you be proficient with different test automation frameworks i.e. Selenium, Cypress, TestNG etc.

LambdaTest Learning Hubs:

YouTube

You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.

Run ts-auto-mock automation tests on LambdaTest cloud grid

Perform automation testing on 3000+ real desktop and mobile devices online.

Try LambdaTest Now !!

Get 100 minutes of automation test minutes FREE!!

Next-Gen App & Browser Testing Cloud

Was this article helpful?

Helpful

NotHelpful