Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'test/integration/select.test.js')
-rw-r--r--test/integration/select.test.js127
1 files changed, 41 insertions, 86 deletions
diff --git a/test/integration/select.test.js b/test/integration/select.test.js
index 2594179..d9b632e 100644
--- a/test/integration/select.test.js
+++ b/test/integration/select.test.js
@@ -1,44 +1,49 @@
const { Builder, By, until } = require('selenium-webdriver'),
chrome = require('selenium-webdriver/chrome.js'),
chromeOptions = new chrome.Options(),
- { expect, it } = require('@jest/globals'),
- { readFile } = require('node:fs/promises'),
+ { readFile, readdir } = require('node:fs/promises'),
{ HttpResponse } = require('selenium-webdriver/devtools/networkinterceptor');
chromeOptions.addArguments('--headless', '--disable-gpu', '--no-sandbox');
-chromeOptions.enableBidi();
-let driver;
+const buildPath = 'build/assets/images';
+const defaultScenario = 'scenario-side_show';
+const fixtureFilePath = './test/integration/fixtures/scenario-test.svg';
-beforeEach(async () => {
- driver = new Builder().forBrowser('chrome').setChromeOptions(chromeOptions).build();
-});
+const selected = expect.stringContaining('selected');
+const notSelected = expect.not.stringContaining('selected');
-it('selects and deselects a trooper by clicking on its counter', async () => {
- const connection = await driver.createCDPConnection('page')
- const url = 'http://localhost:3005/assets/images/scenario-side_show.svg';
- const httpResponse = new HttpResponse(url);
- httpResponse.body = await readFile('./test/integration/fixtures/scenario-test.svg', 'utf8');
+let driver, httpResponse;
+
+beforeAll(async () => {
+ const filenames = await readdir(buildPath);
+ const scenario = filenames.find(filename => filename.includes(defaultScenario));
+
+ httpResponse = new HttpResponse(url(`/assets/images/${scenario}`));
+ httpResponse.body = await readFile(fixtureFilePath, 'utf8');
httpResponse.addHeaders('Content-Type', 'image/svg+xml');
+});
+beforeEach(async () => {
+ driver = new Builder().forBrowser('chrome').setChromeOptions(chromeOptions).build();
+ const connection = await driver.createCDPConnection('page')
await driver.onIntercept(connection, httpResponse, async () => {});
- await driver.get('http://localhost:3005');
- await driver.wait(until.elementLocated(By.css('#dice')), 1000);
+ await driver.get(url('/'));
+ const mapPlaceholderEl = await driver.findElement(By.css('.map-placeholder'));
+ await driver.wait(until.elementIsNotVisible(mapPlaceholderEl), 1000);
+});
+it('selects and deselects a trooper by clicking on its counter', async () => {
const record = await driver.findElement(By.css('.soldier-record'));
- const notSelected = expect.not.stringContaining('selected');
+ const objectEl = await driver.findElement(By.css('object'));
+ const selector = '.counter[data-allegiance="attacker"][data-number="1"]';
expect(await record.getAttribute('class')).toEqual(notSelected);
-
- const objectEl = await driver.findElement(By.css('object'));
await driver.switchTo().frame(objectEl);
-
- const selector = '.counter[data-allegiance="attacker"][data-number="1"]',
- svg = await driver.findElement(By.css('svg')),
- counter = await driver.findElement(By.css(selector), svg),
- selected = expect.stringContaining('selected');
-
+ const svg = await driver.findElement(By.css('svg'));
+ const counter = await driver.findElement(By.css(selector), svg);
expect(await counter.getAttribute('class')).toEqual(notSelected);
+
await counter.click();
expect(await counter.getAttribute('class')).toEqual(selected);
@@ -54,37 +59,20 @@ it('selects and deselects a trooper by clicking on its counter', async () => {
});
it('selects and deselects trooper by clicking on its record', async () => {
- const connection = await driver.createCDPConnection('page')
- const url = 'http://localhost:3005/assets/images/scenario-side_show.svg';
- const httpResponse = new HttpResponse(url);
- httpResponse.body = await readFile('./test/integration/fixtures/scenario-test.svg', 'utf8');
- httpResponse.addHeaders('Content-Type', 'image/svg+xml');
-
- await driver.onIntercept(connection, httpResponse, async () => {});
- await driver.get('http://localhost:3005');
- await driver.wait(until.elementLocated(By.css('#dice')), 1000);
-
const record = await driver.findElement(By.css('.soldier-record'));
- const notSelected = expect.not.stringContaining('selected');
+ const objectEl = await driver.findElement(By.css('object'));
+ const selector = '.counter[data-allegiance="attacker"][data-number="1"]';
expect(await record.getAttribute('class')).toEqual(notSelected);
-
- const objectEl = await driver.findElement(By.css('object'));
await driver.switchTo().frame(objectEl);
-
- const selector = '.counter[data-allegiance="attacker"][data-number="1"]',
- svg = await driver.findElement(By.css('svg')),
- counter = await driver.findElement(By.css(selector), svg);
-
+ const svg = await driver.findElement(By.css('svg'));
+ const counter = await driver.findElement(By.css(selector), svg);
expect(await counter.getAttribute('class')).toEqual(notSelected);
await driver.switchTo().defaultContent();
await record.click();
- const selected = expect.stringContaining('selected');
-
expect(await record.getAttribute('class')).toEqual(selected);
-
await driver.switchTo().frame(objectEl);
expect(await counter.getAttribute('class')).toEqual(selected);
@@ -92,36 +80,21 @@ it('selects and deselects trooper by clicking on its record', async () => {
await record.click();
expect(await record.getAttribute('class')).toEqual(notSelected);
-
await driver.switchTo().frame(objectEl);
expect(await counter.getAttribute('class')).toEqual(notSelected);
});
it('selects a trooper by clicking on its counter and deselects it by clicking on its record', async () => {
- const connection = await driver.createCDPConnection('page')
- const url = 'http://localhost:3005/assets/images/scenario-side_show.svg';
- const httpResponse = new HttpResponse(url);
- httpResponse.body = await readFile('./test/integration/fixtures/scenario-test.svg', 'utf8');
- httpResponse.addHeaders('Content-Type', 'image/svg+xml');
-
- await driver.onIntercept(connection, httpResponse, async () => {});
- await driver.get('http://localhost:3005');
- await driver.wait(until.elementLocated(By.css('#dice')), 1000);
-
const record = await driver.findElement(By.css('.soldier-record'));
- const notSelected = expect.not.stringContaining('selected');
+ const objectEl = await driver.findElement(By.css('object'));
+ const selector = '.counter[data-allegiance="attacker"][data-number="1"]';
expect(await record.getAttribute('class')).toEqual(notSelected);
-
- const objectEl = await driver.findElement(By.css('object'));
await driver.switchTo().frame(objectEl);
-
- const selector = '.counter[data-allegiance="attacker"][data-number="1"]',
- svg = await driver.findElement(By.css('svg')),
- counter = await driver.findElement(By.css(selector), svg),
- selected = expect.stringContaining('selected');
-
+ const svg = await driver.findElement(By.css('svg'));
+ const counter = await driver.findElement(By.css(selector), svg);
expect(await counter.getAttribute('class')).toEqual(notSelected);
+
await counter.click();
expect(await counter.getAttribute('class')).toEqual(selected);
@@ -131,43 +104,25 @@ it('selects a trooper by clicking on its counter and deselects it by clicking on
await record.click();
expect(await record.getAttribute('class')).toEqual(notSelected);
-
await driver.switchTo().frame(objectEl);
expect(await counter.getAttribute('class')).toEqual(notSelected);
});
it('selects a trooper by clicking on its record and deselects it by clicking on its counter', async () => {
- const connection = await driver.createCDPConnection('page')
- const url = 'http://localhost:3005/assets/images/scenario-side_show.svg';
- const httpResponse = new HttpResponse(url);
- httpResponse.body = await readFile('./test/integration/fixtures/scenario-test.svg', 'utf8');
- httpResponse.addHeaders('Content-Type', 'image/svg+xml');
-
- await driver.onIntercept(connection, httpResponse, async () => {});
- await driver.get('http://localhost:3005');
- await driver.wait(until.elementLocated(By.css('#dice')), 1000);
-
const record = await driver.findElement(By.css('.soldier-record'));
- const notSelected = expect.not.stringContaining('selected');
+ const objectEl = await driver.findElement(By.css('object'));
+ const selector = '.counter[data-allegiance="attacker"][data-number="1"]';
expect(await record.getAttribute('class')).toEqual(notSelected);
-
- const objectEl = await driver.findElement(By.css('object'));
await driver.switchTo().frame(objectEl);
-
- const selector = '.counter[data-allegiance="attacker"][data-number="1"]',
- svg = await driver.findElement(By.css('svg')),
- counter = await driver.findElement(By.css(selector), svg);
-
+ const svg = await driver.findElement(By.css('svg'));
+ const counter = await driver.findElement(By.css(selector), svg);
expect(await counter.getAttribute('class')).toEqual(notSelected);
await driver.switchTo().defaultContent();
await record.click();
- const selected = expect.stringContaining('selected');
-
expect(await record.getAttribute('class')).toEqual(selected);
-
await driver.switchTo().frame(objectEl);
expect(await counter.getAttribute('class')).toEqual(selected);