Web Dev Solutions

Catalin Mititiuc

From a80728f16f90616d93dcc9ed932528b35e2ef62d Mon Sep 17 00:00:00 2001 From: Catalin Mititiuc Date: Fri, 24 May 2024 15:59:17 -0700 Subject: WIP: mock selenium response --- jest.config.integ.cjs | 2 +- public/assets/css/map.css | 4 +- public/assets/css/style.css | 5 + public/assets/images/counters-test.svg | 31 ++++ public/assets/images/counters.svg | 4 +- public/assets/images/map4.svg | 108 +++++++------- public/assets/images/mapsheets.svg | 176 +++++++++++------------ public/assets/images/scenario-dragon_hunting.svg | 20 ++- public/assets/images/scenario-side_show.svg | 31 +++- public/index.html.test | 14 ++ server.cjs | 6 +- src/index.js | 32 ++--- src/index.js.test | 13 ++ src/modules/record_sheet.js | 26 +++- test/integration/fixtures/index.html | 8 -- test/integration/fixtures/scenario-test.svg | 102 +++++++++++++ test/integration/page.test.js | 71 +++++++-- 17 files changed, 467 insertions(+), 186 deletions(-) create mode 100644 public/assets/images/counters-test.svg create mode 100644 public/index.html.test create mode 100644 src/index.js.test delete mode 100644 test/integration/fixtures/index.html create mode 100644 test/integration/fixtures/scenario-test.svg diff --git a/jest.config.integ.cjs b/jest.config.integ.cjs index 0b50bae..7a8028a 100644 --- a/jest.config.integ.cjs +++ b/jest.config.integ.cjs @@ -4,5 +4,5 @@ module.exports = { globalSetup: './test/integration/setup.cjs', globalTeardown: './test/integration/teardown.cjs', testPathIgnorePatterns: ['/node_modules/', 'test/unit'], - testTimeout: 5000 + testTimeout: 5000, }; diff --git a/public/assets/css/map.css b/public/assets/css/map.css index ed2b7ce..8f45936 100644 --- a/public/assets/css/map.css +++ b/public/assets/css/map.css @@ -395,6 +395,7 @@ g[data-y="76"] { --i: 76; } .floor { fill: white; + /* fill: inherit; */ } .building path { @@ -416,9 +417,6 @@ g[data-y="76"] { --i: 76; } .building .windows, .building .door-edges { stroke-width: 2.5px; -} - -.building .windows, .building .door-edges { stroke: orange; } diff --git a/public/assets/css/style.css b/public/assets/css/style.css index f3b1736..cde2c33 100644 --- a/public/assets/css/style.css +++ b/public/assets/css/style.css @@ -181,6 +181,11 @@ polygon.firing-arc[data-allegiance="attacker"] { fill: blue; } +.weapon-icon { + stroke: white; + stroke-width: 0.5px; +} + .soldier-record svg { width: 20px; height: 20px; diff --git a/public/assets/images/counters-test.svg b/public/assets/images/counters-test.svg new file mode 100644 index 0000000..b7d5cd9 --- /dev/null +++ b/public/assets/images/counters-test.svg @@ -0,0 +1,31 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/public/assets/images/counters.svg b/public/assets/images/counters.svg index aab06a8..2254d3d 100644 --- a/public/assets/images/counters.svg +++ b/public/assets/images/counters.svg @@ -1,7 +1,7 @@ - + @@ -19,7 +19,7 @@ - + diff --git a/public/assets/images/map4.svg b/public/assets/images/map4.svg index d5c3326..53a2b71 100644 --- a/public/assets/images/map4.svg +++ b/public/assets/images/map4.svg @@ -5,50 +5,46 @@ g[data-edge="north"] { --i: -2; } g[data-edge="south"] { --i: 52; } - g#hex line { - opacity: 1; + #background { + stroke: #304b75; + fill: #bacae3; } - g#hex path { - opacity: 1; + pattern use { stroke: black; - stroke-width: 0.25px; + stroke-width: 0.3px; } - use[href="#hex"] { - opacity: 1; + .cw-60-deg { + transform: rotate(60deg); } - g#hex line { - stroke-width: 0.2px; - transform: scale(1.2); - } - - g#hex line:nth-child(2) { - transform: rotate(60deg) scale(1.2); - } - - g#hex line:nth-child(3) { - transform: rotate(-60deg) scale(1.2); + .ccw-60-deg { + transform: rotate(-60deg); } - - - - - - - - + + + + + + + + + + + + + + + + + + + 1 2 3 @@ -57,28 +53,44 @@ 6 7 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - + + @@ -86,5 +98,5 @@ - + diff --git a/public/assets/images/mapsheets.svg b/public/assets/images/mapsheets.svg index 46a2fe1..44b5c2f 100644 --- a/public/assets/images/mapsheets.svg +++ b/public/assets/images/mapsheets.svg @@ -2,34 +2,34 @@ - - + - - - - - - + - - - - - - + - - - - - - + - - - - - - + - - - - - - + - - - - - - - - - - - - - - - - @@ -396,16 +396,16 @@ - - + + - + - + @@ -453,7 +453,7 @@ - + @@ -471,7 +471,7 @@ - + @@ -491,7 +491,7 @@ - + @@ -513,7 +513,7 @@ - + @@ -528,7 +528,7 @@ - + @@ -540,11 +540,11 @@ - 1 + 1 - + @@ -558,11 +558,11 @@ - 1 + 1 - + @@ -572,11 +572,11 @@ - 1 + 1 - + @@ -590,11 +590,11 @@ - 1 + 1 - + @@ -608,11 +608,11 @@ - 3 + 3 - + @@ -620,11 +620,11 @@ - 1 + 1 - + @@ -660,14 +660,14 @@ m 0 3.3 h 10.5 v 3 h -10.5 z "/> - 3 + 3 - + @@ -679,11 +679,11 @@ - 1 + 1 - + @@ -709,11 +709,11 @@ m 0 2.75 h 14 v 2.3 h -14 z "/> - 3 + 3 - + @@ -722,11 +722,11 @@ - 1 + 1 - + @@ -740,11 +740,11 @@ - 1 + 1 - + @@ -758,11 +758,11 @@ - 2 + 2 - + @@ -772,11 +772,11 @@ - 1 + 1 - + @@ -812,14 +812,14 @@ m 0 3.3 h 10.5 v 3 h -10.5 z "/> - 2 + 2 - + @@ -859,7 +859,7 @@ - 2 + 2 diff --git a/public/assets/images/scenario-dragon_hunting.svg b/public/assets/images/scenario-dragon_hunting.svg index 27b0bdf..cb33581 100644 --- a/public/assets/images/scenario-dragon_hunting.svg +++ b/public/assets/images/scenario-dragon_hunting.svg @@ -60,9 +60,9 @@ - - - + + + @@ -122,5 +122,19 @@ + + + + diff --git a/test/integration/page.test.js b/test/integration/page.test.js index e4739b0..f708c4f 100644 --- a/test/integration/page.test.js +++ b/test/integration/page.test.js @@ -1,4 +1,6 @@ -const { Builder, By } = require('selenium-webdriver'), +const { ProvideResponseParameters } = require('selenium-webdriver/bidi/provideResponseParameters'); + +const { Builder, By, until } = require('selenium-webdriver'), chrome = require('selenium-webdriver/chrome.js'), getNetworkInstance = require('selenium-webdriver/bidi/network.js'), { AddInterceptParameters } = require('selenium-webdriver/bidi/addInterceptParameters'), @@ -10,8 +12,10 @@ const { Builder, By } = require('selenium-webdriver'), { tmpdir } = require('os'), puppeteer = require('puppeteer'); -const DIR = path.resolve(tmpdir(), 'test-dir'); +const { HttpResponse } = require('selenium-webdriver/devtools/networkinterceptor'); +const fs = require('node:fs/promises'); +const DIR = path.resolve(tmpdir(), 'test-dir'); chromeOptions.addArguments('--headless', '--disable-gpu', '--no-sandbox'); chromeOptions.enableBidi(); @@ -53,17 +57,66 @@ it('loads the page', async () => { it.only('selects an off-board soldier', async () => { // it.only.each(Array(10).fill(null))('selects an off-board soldier', async () => { - const id = await driver.getWindowHandle(); - const network = await getNetworkInstance(driver, id); - await network.beforeRequestSent(function (event) { - console.log('request url', event.request.url); - }); + // const id = await driver.getWindowHandle(); + // const network = await getNetworkInstance(driver, id); // const intercept = await network.addIntercept(new AddInterceptParameters(InterceptPhase.BEFORE_REQUEST_SENT)); + // await network.beforeRequestSent(async event => { + // console.log('request url', event.request.url); + // await network.provideResponse(new ProvideResponseParameters(event.request)); + // }); + + // await network.responseStarted(async event => { + // if (event.response.url.includes('scenario')) + // console.log('response', event.response); + // }); + + // await network.responseStarted(async (event) => { + // if (event.response.url.includes('scenario')) { + // console.log('event', event); + // console.log('request', event.request); + // console.log('response', event.response.result); + // } + // }); + + // await network.beforeRequestSent(async (event) => { + // if (event.request.url.includes('scenario')) { + // console.log('event', event); + // console.log('request', event.request.request); + // await network.provideResponse(new ProvideResponseParameters(event.request.request)); + // // await network.failRequest(event.request.request); + // } + // }); + + const connection = await driver.createCDPConnection('page') + const url = 'http://localhost:3005/assets/images/scenario-side_show.svg'; + const httpResponse = new HttpResponse(url); + + // httpResponse.body = ` + // + // + // `; + + httpResponse.body = await fs.readFile('./test/integration/fixtures/scenario-test.svg', 'utf8'); + httpResponse.addHeaders('Content-Type', 'image/svg+xml'); + + await driver.onIntercept(connection, httpResponse, async function () { + console.log('intercepted'); + // await driver.switchTo().frame(await driver.findElement(By.css('object'))); + // console.log(await driver.getPageSource()); + }); + await driver.get('http://localhost:3005'); + // expect(await driver.getTitle()).toEqual('Infantry Combat Solo Basic'); + + await driver.wait(until.elementIsVisible(driver.findElement(By.css('object'))), 1000); + // await driver.wait(until.elementLocated(By.css('#dice')), 1000); + takeScreenshot(driver); // await driver.switchTo().frame(await driver.findElement(By.css('object'))); + // console.log(await driver.getPageSource()); + // const testDir = path.dirname(expect.getState().testPath); // await writeFile(path.join(testDir, `scenario.svg`), ` // @@ -91,18 +144,18 @@ it.only('selects an off-board soldier', async () => { // await browser.close(); - // console.log('test dir', testDir); // const selector = '.counter[data-allegiance="attacker"][data-number="1"]', // svg = await driver.findElement(By.css('svg')), // counter = await driver.findElement(By.css(selector), svg); - // takeScreenshot(driver); + // await driver.findElement(By.css('#dice')); // await counter.click(); // expect(await counter.getAttribute('class')).toEqual(expect.stringContaining('selected')); + // await takeScreenshot(driver); }); afterEach(async () => { -- cgit v1.2.3