Skip to content

Commit

Permalink
add tests
Browse files Browse the repository at this point in the history
  • Loading branch information
balesniy committed Jun 10, 2024
1 parent d852041 commit 6fb5027
Show file tree
Hide file tree
Showing 224 changed files with 1,108 additions and 1 deletion.
8 changes: 8 additions & 0 deletions .htmlvalidate.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
module.exports = {
"rules": {
"heading-level": ["error", {
"allowMultipleH1": false,
"minInitialRank": "h1",
}]
}
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
54 changes: 54 additions & 0 deletions figma/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<!DOCTYPE html>
<html lang="ru">
<head>
<meta charset="utf-8">
<link href="style.css" rel="stylesheet">
<title>Drink2Go</title>
</head>
<body>
<header data-test="header">
<picture>
<source media="(min-width: 1440px)" srcset="sections/Header.png" >
<source media="(min-width: 768px)" srcset="sections/Header(1).png" >
<img src="sections/Header(2).png" alt="">
</picture>
</header>
<main>
<section data-test="hero">
<picture>
<source media="(min-width: 1440px)" srcset="sections/Slider.png" >
<source media="(min-width: 768px)" srcset="sections/Slider(1).png" >
<img src="sections/Slider(2).png" alt="">
</picture>
</section>
<section data-test="features">
<picture>
<source media="(min-width: 1440px)" srcset="sections/Features.png" >
<source media="(min-width: 768px)" srcset="sections/Features(1).png" >
<img src="sections/Features(2).png" alt="">
</picture>
</section>
<section data-test="catalog">
<picture>
<source media="(min-width: 1440px)" srcset="sections/Catalog.png" >
<source media="(min-width: 768px)" srcset="sections/Catalog(1).png" >
<img src="sections/Catalog(2).png" alt="">
</picture>
</section>
<section data-test="map">
<picture>
<source media="(min-width: 1440px)" srcset="sections/Map.png" >
<source media="(min-width: 768px)" srcset="sections/Map(1).png" >
<img src="sections/Map(2).png" alt="">
</picture>
</section>
</main>
<footer data-test="footer">
<picture>
<source media="(min-width: 1440px)" srcset="sections/Footer.png" >
<source media="(min-width: 768px)" srcset="sections/Footer(1).png" >
<img src="sections/Footer(2).png" alt="">
</picture>
</footer>
</body>
</html>
Binary file added figma/sections/Catalog(1).png
Binary file added figma/sections/Catalog(2).png
Binary file added figma/sections/Catalog.png
Binary file added figma/sections/Features(1).png
Binary file added figma/sections/Features(2).png
Binary file added figma/sections/Features.png
Binary file added figma/sections/Footer(1).png
Binary file added figma/sections/Footer(2).png
Binary file added figma/sections/Footer.png
Binary file added figma/sections/Header(1).png
Binary file added figma/sections/Header(2).png
Binary file added figma/sections/Header.png
Binary file added figma/sections/Map(1).png
Binary file added figma/sections/Map(2).png
Binary file added figma/sections/Map.png
Binary file added figma/sections/Slider(1).png
Binary file added figma/sections/Slider(2).png
Binary file added figma/sections/Slider.png
20 changes: 20 additions & 0 deletions figma/style.css
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
body {
margin: 0 auto;
width: 320px;
}

@media (min-width: 768px) {
body {
width: 768px;
}
}

@media (min-width: 1440px) {
body {
width: 1440px;
}
}

img {
display: block;
}
19 changes: 18 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,22 @@
"lint:scripts": "eslint . --ignore-path .gitignore --ignore-pattern vendor/",
"optimize": "npm-run-all -p optimize:**",
"optimize:raster": "gulp optimizeRaster",
"optimize:vector": "gulp optimizeVector"
"optimize:vector": "gulp optimizeVector",
"test-pp": "node run-test.js",
"test-menu": "backstop test --config=\"test-config/backstop-test-menu.config.js\"",
"test-swiper": "backstop test --config=\"test-config/backstop-test-swiper.config.js\"",
"test-05": "backstop test --config=\"test-config/backstop-test-05.config.json\"",
"test-08": "backstop test --config=\"test-config/backstop-test-08.config.json\"",
"test-07": "backstop test --config=\"test-config/backstop-test-07.config.json\"",
"html-04": "backstop test --config=\"test-config/backstop-html-04.config.js\"",
"test-ff": "backstop test --config=\"test-config/backstop-test-ff.config.js\"",
"test-03": "backstop test --config=\"test-config/backstop-test-03.config.js\"",
"test-logo": "backstop test --config=\"test-config/backstop-test-logo.config.js\"",
"test-04": "backstop test --config=\"test-config/backstop-test-04.config.js\"",
"html-03": "backstop test --config=\"test-config/backstop-html-03.config.js\"",
"test-06": "backstop test --config=\"test-config/backstop-test-06.config.js\"",
"img-01": "backstop test --config=\"test-config/backstop-img-01.config.js\"",
"test-headers": "html-validate source/index.html"
},
"devDependencies": {
"@htmlacademy/editorconfig-cli": "3.0.0",
Expand All @@ -45,6 +60,8 @@
"gulp-sharp-responsive": "0.4.1",
"gulp-stacksvg": "4.0.0",
"gulp-svgmin": "4.1.0",
"htmlacademy-backstopjs": "6.6.1",
"html-validate": "^8.5.0",
"linthtml-config-htmlacademy": "1.0.25",
"npm-run-all": "4.1.5",
"postcss": "8.4.38",
Expand Down
56 changes: 56 additions & 0 deletions run-test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
const fs = require('node:fs/promises');
const backstop = require('htmlacademy-backstopjs');
const fontsConfig = require('./test-config/backstop-test-05.config');
const ppConfig = require('./test-config/backstop-test-06.config');
const styleguideConfig = require('./test-config/backstop-test-07.config');
const interactionConfig = require('./test-config/backstop-test-08.config');

(async () => {
let passedSelectors
try {
await backstop('test', { config: ppConfig });
console.log('All blocks passed')
} catch (e) {
console.log('mismatch blocks detected')
} finally {
const reportFile = await fs.readFile('./backstop_data/json_report/jsonReport.json', 'utf8')
const report = JSON.parse(reportFile)
const passed = report.tests
.filter(({ status }) => status === 'pass')
.map(({
pair: {
viewportLabel,
selector,
},
}) => ({ selector, viewportLabel }))
.reduce((acc, { viewportLabel, selector }) => {
acc[selector] = acc[selector]?.add(viewportLabel) ?? new Set([viewportLabel]);
return acc;
}, {})
passedSelectors = Object.entries(passed)
.filter(([, set]) => set.size === 3)
.map(([selector]) => {
let pattern = /data-test="(\w+)"/;
let match = selector.match(pattern);
return (match[1]);
}).join('|') || 'nothing good found'
}
const config05 = {
...fontsConfig,
scenarios: fontsConfig.scenarios.filter(({ label }) => !!label.match(passedSelectors)),
}
await fs.writeFile('./test-config/backstop-test-05.config.json', JSON.stringify(config05, null, 2), 'utf8')

const config08 = {
...interactionConfig,
scenarios: interactionConfig.scenarios.filter(({ label }) => !!label.match(passedSelectors)),
}
await fs.writeFile('./test-config/backstop-test-08.config.json', JSON.stringify(config08, null, 2), 'utf8')

const config07 = {
...styleguideConfig,
scenarios: styleguideConfig.scenarios.filter(({ label }) => !!label.match(passedSelectors)),
}
await fs.writeFile('./test-config/backstop-test-07.config.json', JSON.stringify(config07, null, 2), 'utf8')

})()
60 changes: 60 additions & 0 deletions test-config/backstop-html-03.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
module.exports = {
"id": "drink2go html-03",
"viewports": [
{
"label": "desktop",
"width": 1440,
"height": 800,
},
{
"label": "tablet",
"width": 768,
"height": 800,
},
{
"label": "mobile",
"width": 320,
"height": 800,
},
],
"resembleOutputOptions": {
"ignoreAntialiasing": true,
"usePreciseMatching": true
},
"onReadyScript": "onReady.js",
"scenarios": [
{
"label": "index links",
"url": "http://localhost:3000/index.html",
"referenceUrl": "./reference/index.html",
showSelectors: ["a"],
hideSelectors: ["body > *"],
requireSameDimensions: false,
},
{
"label": "index buttons",
"url": "http://localhost:3000/index.html",
"referenceUrl": "./reference/index.html",
showSelectors: ["button"],
hideSelectors: ["body > *"],
requireSameDimensions: false,
},
],
fileNameTemplate: '{configId}_{scenarioIndex}_{scenarioLabel}_{selectorIndex}__{viewportIndex}_{viewportLabel}',
"paths": {
"bitmaps_reference": "backstop_data/bitmaps_reference/html-03",
"bitmaps_test": "backstop_data/bitmaps_test",
"engine_scripts": "engine_scripts",
"html_report": "backstop_data/html_report",
},
"report": ["browser"],
"engine": "puppeteer",
"engineOptions": {
"args": ["--no-sandbox"],
"gotoParameters": { "waitUntil": ["load", "networkidle0"], timeout: 20000 },
},
"asyncCaptureLimit": 10,
"asyncCompareLimit": 50,
"debug": false,
"debugWindow": false
}
57 changes: 57 additions & 0 deletions test-config/backstop-html-04.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* проверяем отправку формы
* todo прокликать контролы формы
* */

module.exports = {
"id": "drink2go form",
"viewports": [
{
"label": "desktop",
"width": 1440,
"height": 800,
},
],
"resembleOutputOptions": {
"ignoreAntialiasing": true,
"usePreciseMatching": true
},
"onReadyScript": "onReady.js",
"scenarios": [
{
"label": "index form send",
"url": "http://localhost:3000/index.html",
"referenceUrl": "./reference/index.html",
clickSelector: "[data-test=catalog] button[type='submit']",
selectors: ["viewport"],
"viewports": [
{
"label": "desktop",
"width": 800,
"height": 600,
},
],
// onReadyScript: "fill-email.js",
// email: "[email protected]",
// field: "[data-test=subscribe] input",
postInteractionWait: 1000,
},
],
fileNameTemplate: '{configId}_{scenarioIndex}_{scenarioLabel}_{selectorIndex}__{viewportIndex}_{viewportLabel}',
"paths": {
"bitmaps_reference": "backstop_data/bitmaps_reference/html-04",
"bitmaps_test": "backstop_data/bitmaps_test",
"engine_scripts": "engine_scripts",
"html_report": "backstop_data/html_report",
},
"report": ["browser"],
"engine": "puppeteer",
"engineOptions": {
"args": ["--no-sandbox"],
"gotoParameters": { "waitUntil": ["load", "networkidle0"], timeout: 20000 },
},
"asyncCaptureLimit": 10,
"asyncCompareLimit": 50,
"debug": false,
"debugWindow": false
}
59 changes: 59 additions & 0 deletions test-config/backstop-img-01.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
module.exports = {
"id": "drink2go img",
"viewports": [
{
"label": "desktop",
"width": 1440,
"height": 800,
},
{
"label": "tablet",
"width": 768,
"height": 800,
},
{
"label": "mobile",
"width": 320,
"height": 800,
},
],
"resembleOutputOptions": {
"ignoreAntialiasing": true,
"usePreciseMatching": true
},
"onReadyScript": "onReady.js",
"scenarios": [
{
"label": "index bg colors",
"url": "http://localhost:3000/index.html",
"referenceUrl": "./reference/index.html",
onReadyScript: "hide-bg.js",
requireSameDimensions: false,
},
{
"label": "index img",
"url": "http://localhost:3000/index.html",
"referenceUrl": "./reference/index.html",
hideSelectors: ["body > *"],
showSelectors: ["img", "svg"],
requireSameDimensions: false,
},
],
fileNameTemplate: '{configId}_{scenarioIndex}_{scenarioLabel}_{selectorIndex}__{viewportIndex}_{viewportLabel}',
"paths": {
"bitmaps_reference": "backstop_data/bitmaps_reference/img-01",
"bitmaps_test": "backstop_data/bitmaps_test",
"engine_scripts": "engine_scripts",
"html_report": "backstop_data/html_report",
},
"report": ["browser"],
"engine": "puppeteer",
"engineOptions": {
"args": ["--no-sandbox"],
"gotoParameters": { "waitUntil": ["load", "networkidle0"], timeout: 20000 },
},
"asyncCaptureLimit": 10,
"asyncCompareLimit": 50,
"debug": false,
"debugWindow": false
}
Loading

0 comments on commit 6fb5027

Please sign in to comment.