Best JavaScript code snippet using wpt
resizable-columns.test.ts
Source:resizable-columns.test.ts
...87 await testFn(page);88 });89};90describe.each([true, false])('StickyHeader=%s', sticky => {91 function setupStickyTest(testFn: (page: TablePage) => Promise<void>) {92 return setupTest(async page => {93 if (sticky) {94 await page.toggleStickyHeader();95 await page.windowScrollTo({ top: 400 });96 await expect(page.getHeaderTopOffset()).resolves.toEqual(-1);97 }98 await testFn(page);99 });100 }101 test(102 'should expand and shrink a column correctly',103 setupStickyTest(async page => {104 const delta = 50;105 let prevWidth = await page.getColumnWidth(2);106 await page.resizeColumn(2, delta);107 let width = await page.getColumnWidth(2);108 expect(width).toBe(prevWidth + delta);109 prevWidth = width;110 await page.resizeColumn(2, -delta);111 width = await page.getColumnWidth(2);112 expect(width).toBe(prevWidth - delta);113 })114 );115 test(116 'should not shrink a column less than its min-width',117 setupStickyTest(async page => {118 const minWidth = await page.getColumnMinWidth(2);119 await page.resizeColumn(2, -200);120 const width = await page.getColumnWidth(2);121 expect(minWidth).toBe(width);122 })123 );124 test(125 'should expand automatically when the cursor stops outside of the table container',126 setupStickyTest(async page => {127 const columnSelector = tableWrapper.findColumnHeaders().get(4).toSelector();128 const { left: originalLeft } = await page.getBoundingBox(columnSelector);129 await page.resizeBeyondTableWidth(4);130 const { left: newLeft } = await page.getBoundingBox(columnSelector);131 expect(newLeft).toBeLessThan(originalLeft);132 })133 );134 test(135 'should expand the last column after hiding a column',136 setupStickyTest(async page => {137 const columnToHideWidth = await page.getColumnWidth(1);138 const oldLastColumnWidth = await page.getColumnWidth(4);139 await page.toggleColumn('name');140 const newLastColumnWidth = await page.getColumnWidth(3);141 expect(newLastColumnWidth).toBe(oldLastColumnWidth + columnToHideWidth);142 })143 );144 test(145 'should render "width: auto" for the last on big screens and explicit value on small',146 setupStickyTest(async page => {147 await expect(page.getColumnStyle(4)).resolves.toContain('width: auto;');148 await page.setWindowSize({ ...defaultScreen, width: 620 });149 await expect(page.getColumnStyle(4)).resolves.toContain('width: 120px;');150 })151 );152 test(153 'should shrink the last column after revealing a column',154 setupStickyTest(async page => {155 const nameColumnWidth = await page.getColumnWidth(1);156 await page.toggleColumn('name');157 const prevLastColumnWidth = await page.getColumnWidth(3);158 await page.toggleColumn('name');159 const newLastColumnWidth = await page.getColumnWidth(4);160 expect(newLastColumnWidth).toBe(prevLastColumnWidth - nameColumnWidth);161 })162 );163 test(164 'should expand the last column when the container is resized outwards',165 setupStickyTest(async page => {166 const prevDateColumnWidth = await page.getColumnWidth(4);167 await page.setWindowSize({ ...defaultScreen, width: defaultScreen.width + 200 });168 const dateColumnWidth = await page.getColumnWidth(4);169 expect(dateColumnWidth).toBeGreaterThan(prevDateColumnWidth);170 })171 );172 test(173 'should compress the last column when the container is resized inwards',174 setupStickyTest(async page => {175 const prevDateColumnWidth = await page.getColumnWidth(4);176 await page.setWindowSize({ ...defaultScreen, width: defaultScreen.width - 200 });177 const dateColumnWidth = await page.getColumnWidth(4);178 expect(dateColumnWidth).toBeLessThan(prevDateColumnWidth);179 })180 );181 test(182 'should correctly reveal the last column that was hidden by default',183 setupStickyTest(async page => {184 await page.toggleColumn('extra');185 expect(await page.getColumnWidth(5)).toBeGreaterThan(100);186 })187 );188});189test(190 'should show and hide scrollbar',191 setupTest(async page => {192 await expect(page.isExisting(tableWrapper.find(scrollbarSelector).toSelector())).resolves.toEqual(false);193 await page.resizeColumn(3, 500);194 await page.resizeColumn(2, 1000);195 await page.waitForVisible(tableWrapper.find(scrollbarSelector).toSelector());196 await expect(page.isExisting(tableWrapper.find(scrollbarSelector).toSelector())).resolves.toEqual(true);197 })...
sticky-util.js
Source:sticky-util.js
...16 *17 * Returns an 'elements' object which has each of the above elements as an18 * accessible property.19 */20function setupStickyTest(stickyDirection, stickyOffset) {21 const elements = {};22 const inline = stickyDirection === 'left' || stickyDirection === 'right';23 elements.scroller = document.createElement('div');24 elements.scroller.style.position = 'relative';25 elements.scroller.style.width = (inline ? '200px' : '100px');26 elements.scroller.style.height = (inline ? '100px' : '200px');27 elements.scroller.style.overflow = 'scroll';28 elements.contents = document.createElement('div');29 elements.contents.style.height = (inline ? '100%' : '500px');30 elements.contents.style.width = (inline ? '500px' : '100%');31 elements.prepadding = document.createElement('div');32 elements.prepadding.style.height = (inline ? '100%' : '100px');33 elements.prepadding.style.width = (inline ? '100px' : '100%');34 if (inline)35 elements.prepadding.style.display = 'inline-block';36 elements.container = document.createElement('div');37 elements.container.style.height = (inline ? '100%' : '300px');38 elements.container.style.width = (inline ? '300px' : '100%');39 if (inline)40 elements.container.style.display = 'inline-block';41 elements.filler = document.createElement('div');42 elements.filler.style.height = (inline ? '100%' : '100px');43 elements.filler.style.width = (inline ? '100px' : '100%');44 if (inline)45 elements.filler.style.display = 'inline-block';46 elements.sticky = document.createElement('div');47 elements.sticky.style = `${stickyDirection}: ${stickyOffset}px;`;48 elements.sticky.style.position = 'sticky';49 elements.sticky.style.height = (inline ? '100%' : '100px');50 elements.sticky.style.width = (inline ? '100px' : '100%');51 elements.sticky.style.backgroundColor = 'green';52 if (inline)53 elements.sticky.style.display = 'inline-block';54 elements.scroller.appendChild(elements.contents);55 elements.contents.appendChild(elements.prepadding);56 elements.contents.appendChild(elements.container);57 elements.container.appendChild(elements.filler);58 elements.container.appendChild(elements.sticky);59 document.body.appendChild(elements.scroller);60 return elements;61}62/**63 * Similar to above, but nests a second sticky (named innerSticky) inside the64 * sticky element.65 *66 * In the 'bottom' and 'right' cases, we also inject some padding before the67 * innerSticky element, to give it something to push into. This inner padding is68 * not exposed.69 */70function setupNestedStickyTest(stickyDirection, outerStickyOffset,71 innerStickyOffset) {72 const elements = setupStickyTest(stickyDirection, outerStickyOffset);73 const inline = stickyDirection === 'left' || stickyDirection === 'right';74 if (stickyDirection === 'bottom' || stickyDirection === 'right') {75 const innerPadding = document.createElement('div');76 innerPadding.style.height = (inline ? '100%' : '50px');77 innerPadding.style.width = (inline ? '50px' : '100%');78 if (inline)79 innerPadding.style.display = 'inline-block';80 elements.sticky.appendChild(innerPadding);81 }82 elements.innerSticky = document.createElement('div');83 elements.innerSticky.style = `${stickyDirection}: ${innerStickyOffset}px;`;84 elements.innerSticky.style.position = 'sticky';85 elements.innerSticky.style.height = (inline ? '100%' : '50px');86 elements.innerSticky.style.width = (inline ? '50px' : '100%');...
Using AI Code Generation
1var wptdriver = {2 setupStickyTest: function() {3 console.log('setupStickyTest');4 }5};6module.exports = wptdriver;7var wptdriver = require('./wptdriver.js');
Using AI Code Generation
1var wpt = require('webpagetest');2var wptdriver = require('./wptdriver.js');3var wpt = new wpt('www.webpagetest.org');4var wptdriver = new wptdriver(wpt);5console.log(testId);6I am not able to reproduce the problem. I created a new node.js script that calls the createTest method and it works as expected (returns the test ID). I don't know what is going on with your script but I don't think it is a problem with
Using AI Code Generation
1setupStickyTest("test");2setupStickyTest("test");3setupStickyTest("test1");4setupStickyTest("test2");5setupStickyTest("test1");6setupStickyTest("test2");
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.
You could also refer to video tutorials over LambdaTest YouTube channel to get step by step demonstration from industry experts.
Get 100 minutes of automation test minutes FREE!!