Skip to content
This repository has been archived by the owner on Jun 3, 2024. It is now read-only.

[ESLint] Lint test files #306

Merged
merged 5 commits into from
Jul 23, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 12 additions & 1 deletion .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -78,5 +78,16 @@
"prefer-const": ["error"],
"no-var": "error",
"eqeqeq": "error"
}
},
"overrides": [
{
"files": [
"tests/**/*.js"
],
"env": {
"jest": true,
"node": true
}
}
]
}
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@
"msgmerge": "node local_modules/merge-po/index",
"prepare": "npm run build-map-fonts && node build/before_build.js",
"build-map-fonts": "node build/build_map_fonts.js",
"lint": "eslint src bin public/javascript build",
"lint-fix": "eslint --fix src bin public/javascript build"
"lint": "eslint src bin public/javascript build tests",
"lint-fix": "eslint --fix src bin public/javascript build tests"
},
"repository": {
"type": "git",
Expand Down
26 changes: 13 additions & 13 deletions tests/__data__/i18n.js
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
module.exports = {
i18nData: {
message: {'fr test': 'en test'},
getPlural: function (n) {
return n > 1
}
getPlural: function(n) {
return n > 1;
},
},
date: {
dayNames: [
"Sunday",
"Monday",
"Tuesday",
"Wednesday",
"Thursday",
"Friday",
"Saturday"
]
}
}
'Sunday',
'Monday',
'Tuesday',
'Wednesday',
'Thursday',
'Friday',
'Saturday',
],
},
};
16 changes: 8 additions & 8 deletions tests/__mocks__/xml_http_mock.js
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
const xhrMockClass = () => ({
open : jest.fn()
, send : function () {
this.response = '{}'
this.onload()
}
, setRequestHeader: jest.fn(),
open: jest.fn(),
send: function() {
this.response = '{}';
this.onload();
},
setRequestHeader: jest.fn(),

})
});

window.XMLHttpRequest = jest.fn().mockImplementation(xhrMockClass)
window.XMLHttpRequest = jest.fn().mockImplementation(xhrMockClass);
20 changes: 10 additions & 10 deletions tests/integration.js
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
module.exports = {
setupFilesAfterEnv: ["jest-extended"],
testMatch : [`${__dirname}/integration/tests/*.js`],
globalSetup : `${__dirname}/integration/server_start.js`,
globalTeardown : `${__dirname}/integration/server_close.js`,
testPathIgnorePatterns : ['/node_modules/'],
setupFilesAfterEnv: ['jest-extended'],
testMatch: [`${__dirname}/integration/tests/*.js`],
globalSetup: `${__dirname}/integration/server_start.js`,
globalTeardown: `${__dirname}/integration/server_close.js`,
testPathIgnorePatterns: ['/node_modules/'],
'rootDir': __dirname + '/../',
'verbose': true,
'collectCoverage': false,
'transform': {
'\\.yml$': 'yaml-jest',
'\\.js?$': 'babel-jest'
'\\.js?$': 'babel-jest',
},
globals : {
puppeteerArguments : ['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage']
}
}
globals: {
puppeteerArguments: ['--no-sandbox', '--disable-setuid-sandbox', '--disable-dev-shm-usage'],
},
};
16 changes: 8 additions & 8 deletions tests/integration/favorites_tools.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import {wait} from "./tools";
import {wait} from './tools';

/**
* Prerequisite : Favorite Panel Must be open
Expand All @@ -7,14 +7,14 @@ import {wait} from "./tools";
*/
export async function getFavorites(page) {
return await page.evaluate(() => {
return Array.from(document.querySelectorAll('.favorite_panel__item__more_container')).map((e) => {
return Array.from(document.querySelectorAll('.favorite_panel__item__more_container')).map(e => {
return {
title: e.querySelector('.favorite_panel__item__title').innerText,
desc: e.querySelector('.favorite_panel__item__desc').innerText,
icons: Array.from(e.querySelector('.favorite_panel__item__image.icon').classList.values())
}
})
})
icons: Array.from(e.querySelector('.favorite_panel__item__image.icon').classList.values()),
};
});
});
}

/**
Expand All @@ -25,6 +25,6 @@ export async function getFavorites(page) {
* promise is resolved after animation
*/
export async function toggleFavoritePanel(page) {
await page.click('.service_panel__item__fav')
await wait(500)
await page.click('.service_panel__item__fav');
await wait(500);
}
52 changes: 26 additions & 26 deletions tests/integration/helpers/autocomplete.js
Original file line number Diff line number Diff line change
@@ -1,59 +1,59 @@
const SUGGEST_SELECTOR = '.autocomplete_suggestion'
const CLEAR_BUTTON_SELECTOR = '#clear_button'
const SEARCH_INPUT_SELECTOR = '#search'
const SUGGEST_SELECTOR = '.autocomplete_suggestion';
const CLEAR_BUTTON_SELECTOR = '#clear_button';
const SEARCH_INPUT_SELECTOR = '#search';

export default class AutocompleteHelper {
constructor(page) {
this.page = page
this.page = page;
}

async typeAndWait(word) {
await this.page.keyboard.type(word)
await this.page.waitForSelector(SUGGEST_SELECTOR)
await this.page.keyboard.type(word);
await this.page.waitForSelector(SUGGEST_SELECTOR);
}

async pressDown() {
await this.page.keyboard.press('ArrowDown')
await this.page.keyboard.press('ArrowDown');
}

async hoverResult(position) {
await this.page.hover(`.autocomplete_suggestion:nth-child(${position})`)
await this.page.hover(`.autocomplete_suggestion:nth-child(${position})`);
}

async clickResult(position) {
await this.page.click(`.autocomplete_suggestion:nth-child(${position})`)
await this.page.click(`.autocomplete_suggestion:nth-child(${position})`);
}

async getSelectedElementPos() {
let suggestList = await this.getSuggestList()
return suggestList.findIndex((suggest) => {
return suggest.classes.some((cssClass) => {
return cssClass.trim() === 'selected'
})
})
const suggestList = await this.getSuggestList();
return suggestList.findIndex(suggest => {
return suggest.classes.some(cssClass => {
return cssClass.trim() === 'selected';
});
});
}

async getClearFieldButton() {
await this.page.waitForSelector(CLEAR_BUTTON_SELECTOR)
await this.page.waitForSelector(CLEAR_BUTTON_SELECTOR);
}

async clearField() {
return await this.page.click(CLEAR_BUTTON_SELECTOR)
return await this.page.click(CLEAR_BUTTON_SELECTOR);
}

async getSuggestList() {
return await this.page.evaluate((SUGGEST_SELECTOR) => {
let suggests = Array.from(document.querySelectorAll(SUGGEST_SELECTOR))
return suggests.map((suggest) => {
return {label : suggest.innerText, classes : Array.from(suggest.classList)}
})
}, SUGGEST_SELECTOR)
return await this.page.evaluate(SUGGEST_SELECTOR => {
const suggests = Array.from(document.querySelectorAll(SUGGEST_SELECTOR));
return suggests.map(suggest => {
return {label: suggest.innerText, classes: Array.from(suggest.classList)};
});
}, SUGGEST_SELECTOR);
}

async getSearchInputValue() {
return this.page.evaluate((SEARCH_INPUT_SELECTOR) => {
return document.querySelector(SEARCH_INPUT_SELECTOR).value
}, SEARCH_INPUT_SELECTOR)
return this.page.evaluate(SEARCH_INPUT_SELECTOR => {
return document.querySelector(SEARCH_INPUT_SELECTOR).value;
}, SEARCH_INPUT_SELECTOR);
}


Expand Down
52 changes: 29 additions & 23 deletions tests/integration/helpers/response_handler.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,48 @@
export default class ResponseHandler {

constructor(page) {
this.preparedResponses = []
this.page = page
this.preparedResponses = [];
this.page = page;
}

static async init(page) {
const responseHandler = new ResponseHandler(page)
await responseHandler.prepareResponse()
return responseHandler
const responseHandler = new ResponseHandler(page);
await responseHandler.prepareResponse();
return responseHandler;
}

addPreparedResponse(response, query, options) {
let alreadySetResponse = this.preparedResponses.find((preparedResponse) => preparedResponse.query.toString() === query.toString())
if(!alreadySetResponse) {
this.preparedResponses.push({response, query, options})
const alreadySetResponse = this.preparedResponses.find(
preparedResponse => preparedResponse.query.toString() === query.toString()
);
if (!alreadySetResponse) {
this.preparedResponses.push({response, query, options});
}
}

async prepareResponse() {
await this.page.setRequestInterception(true)
this.page.on('request', async (interceptedRequest) => {
let preparedResponse = this.preparedResponses.find(preparedResponse => {
return interceptedRequest.url().match(preparedResponse.query)
})
await this.page.setRequestInterception(true);
this.page.on('request', async interceptedRequest => {
const preparedResponse = this.preparedResponses.find(preparedResponse => {
return interceptedRequest.url().match(preparedResponse.query);
});

if(preparedResponse){
interceptedRequest.headers['Access-Control-Allow-Origin'] = '*'
let status = 200
if(preparedResponse.options) {
if(preparedResponse.options.status) {
status = preparedResponse.options.status
if (preparedResponse) {
interceptedRequest.headers['Access-Control-Allow-Origin'] = '*';
let status = 200;
if (preparedResponse.options) {
if (preparedResponse.options.status) {
status = preparedResponse.options.status;
}
}
await interceptedRequest.respond({status : status, body : JSON.stringify(preparedResponse.response), headers : interceptedRequest.headers})
return
await interceptedRequest.respond({
status: status,
body: JSON.stringify(preparedResponse.response),
headers: interceptedRequest.headers}
);
return;
}
interceptedRequest.continue()
})
interceptedRequest.continue();
});
}
}
6 changes: 3 additions & 3 deletions tests/integration/server_close.js
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
module.exports = async function () {
global.appServer.close()
}
module.exports = async function() {
global.appServer.close();
};
Loading