Web Dev Solutions

Catalin Mititiuc

aboutsummaryrefslogtreecommitdiff
blob: 2abf9f348987d4597380b24b18c3ae4f62736e4c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
const { Builder, By, until, Select } = require('selenium-webdriver'),
  chrome = require('selenium-webdriver/chrome.js'),
  chromeOptions = new chrome.Options(),
  path = require('path');

chromeOptions.addArguments('--headless', '--disable-gpu', '--no-sandbox');

let driver;

beforeEach(async () => {
  const builder = new Builder().forBrowser('chrome').setChromeOptions(chromeOptions);
  driver = builder.build();
});

it('loads default scenario on initial page load', async () => {
  await driver.get(url('/'));
  await page.waitUntilMapLoaded(driver);

  const mapResource = page.findMapResourceEl(driver);
  await driver.switchTo().frame(mapResource);

  const defaultScenarioMapsSelector = '#mapsheet2, #mapsheet3';
  const maps = await driver.findElements(By.css(defaultScenarioMapsSelector));

  expect(maps.length).toBe(2);
});

it('loads previously-loaded scenario on page refresh', async () => {
  await driver.get(url('/'));

  const opts = await driver.findElements(By.css('option'));
  const scenario = await opts[1].getAttribute('value');
  await driver.executeScript(`window.localStorage.setItem('map', '${scenario}');`)

  await driver.get(url('/'));
  await page.waitUntilMapLoaded(driver);

  const mapResource = page.findMapResourceEl(driver);
  await driver.switchTo().frame(mapResource);

  const scenarioMapsSelector = '#mapsheet1, #mapsheet2, #mapsheet3';
  maps = await driver.findElements(By.css(scenarioMapsSelector));

  expect(maps.length).toBe(3);
});

it('loads built-in scenario from dialog', async () => {
  await driver.get(url('/'));
  await page.waitUntilMapLoaded(driver);

  const scenarioButton = await driver.findElement(By.css('#show-dialog'));
  await scenarioButton.click();

  const scenarioSelect = await driver.findElement(By.css('select'));
  const select = new Select(scenarioSelect);
  await select.selectByIndex(1);

  const confirmButton = await driver.findElement(By.css('#confirm-btn'));

  const mapPlaceholderEl = await driver.findElement(By.css('.map-placeholder'));
  await confirmButton.click();
  await driver.wait(until.elementIsVisible(mapPlaceholderEl), 1000);
  await driver.wait(until.elementIsNotVisible(mapPlaceholderEl), 1000);

  const mapResource = page.findMapResourceEl(driver);
  await driver.switchTo().frame(mapResource);

  const scenarioMapsSelector = '#mapsheet1, #mapsheet2, #mapsheet3';
  let maps = await driver.findElements(By.css(scenarioMapsSelector));

  expect(maps.length).toBe(3);
});

it('loads scenario directly from file', async () => {
  await driver.get(url('/'));
  const mapPlaceholderEl = await driver.findElement(By.css('.map-placeholder'));

  const scenario = path.resolve('./public/assets/images/scenario-dragon_hunting.svg')
  await driver.findElement(By.css('input[type="file"]')).sendKeys(scenario);

  await driver.wait(until.elementIsVisible(mapPlaceholderEl), 1000);
  await driver.wait(until.elementIsNotVisible(mapPlaceholderEl), 1000);

  const mapResource = page.findMapResourceEl(driver);
  await driver.switchTo().frame(mapResource);

  const scenarioMapsSelector = '#mapsheet1, #mapsheet2, #mapsheet3';
  let maps = await driver.findElements(By.css(scenarioMapsSelector));

  expect(maps.length).toBe(3);
});

it.todo('loads saved scenario from file');

afterEach(async () => {
  await driver.quit();
});