Skip to content

Commit

Permalink
update backstop, add focus testing, add some tests for focus states
Browse files Browse the repository at this point in the history
  • Loading branch information
Lance Harper committed Jan 24, 2018
1 parent b7703fd commit 41f1a6c
Show file tree
Hide file tree
Showing 28 changed files with 98 additions and 110 deletions.
62 changes: 33 additions & 29 deletions backstop.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const scenariosArr = [];
let defs = [];
const scenarioDefaults = {
url: 'http://localhost:3000',
delay: 100,
misMatchThreshold: 0.1,
readyEvent: null,
onReadyScript: 'onReady.js',
};
Expand All @@ -18,49 +18,52 @@ function createScenario(def) {
scenariosArr.push(finalScenario);
}

function createHoverScenario(def) {
// handle normal selectors
if (Object.prototype.hasOwnProperty.call(def, 'selectors')) {
const normalScenario = Object.assign({}, def);
delete normalScenario.hoverSelectors;
createScenario(normalScenario);
}
// handle hover selectors
const hoverScenario = Object.assign({}, def);
hoverScenario.label = `${hoverScenario.label} Hover`;
hoverScenario.selectors = [];
hoverScenario.hoverWait = 2000;
const copy = Object.assign({}, hoverScenario);
delete copy.hoverSelectors;

hoverScenario.hoverSelectors.forEach((selector) => {
copy.hoverSelector = selector;
copy.selectors = [];
copy.selectors.push(selector);
createScenario(copy);
function splitScenario(def, type = '', selectorsArr, extraOptions = {}) {
const scenario = Object.assign({}, extraOptions, def);
scenario.label = `${def.label} ${type}`;
selectorsArr.forEach((s) => {
scenario[`${type}Selector`] = true;
scenario.selectors = [s];
createScenario(scenario);
});
}

// get backstop definition files and concat the contents
// leaving this here for testing
// const files = glob.sync(
// './src/components/anchor/*.backstop.js',
// // './src/**/*[!{cdr}].backstop.js',
// './src/**/testing.backstop.js',
// { ignore: './src/**/node_modules/**' },
// );
const files = glob.sync('./src/**/*.backstop.js', { ignore: './src/**/node_modules/**' });

// get backstop definition files and concat the contents
const files = glob.sync('./src/**/*.backstop.js', { ignore: ['./src/**/node_modules/**'] });

console.log(files.length);

files.forEach((file) => {
defs = defs.concat(require(file));
});


defs.forEach((def) => {
if (Object.prototype.hasOwnProperty.call(def, 'hoverSelectors')) {
createHoverScenario(def);
} else {
createScenario(def);
const currDef = def;

if (Object.prototype.hasOwnProperty.call(currDef, 'hoverSelectors')) {
const { hoverSelectors } = currDef;
delete currDef.hoverSelectors;
splitScenario(currDef, 'hover', hoverSelectors, { hoverWait: 1000 });
}

if (Object.prototype.hasOwnProperty.call(currDef, 'focusSelectors')) {
const { focusSelectors } = currDef;
delete currDef.focusSelectors;
splitScenario(currDef, 'focus', focusSelectors, { focusWait: 1000 });
}

createScenario(currDef);
});

console.log(scenariosArr);

module.exports = {
id: 'cedar',
viewports: [
Expand Down Expand Up @@ -99,4 +102,5 @@ module.exports = {
report: ['browser'],
debug: false,
debugWindow: false,
startingPort: 9350,
};
13 changes: 13 additions & 0 deletions backstop_data/engine_scripts/focus.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
module.exports = (chromy, scenario) => {
if (Object.prototype.hasOwnProperty.call(scenario, 'focusSelector')) {
const focusSelector = scenario.selectors[0];
const waitTime = scenario.focusWait || 0;
chromy.evaluate(`_selector = '${focusSelector}'`);
chromy
.wait(focusSelector)
.evaluate(() => {
document.querySelector(_selector).focus(); // eslint-disable-line
})
.wait(waitTime);
}
};
14 changes: 6 additions & 8 deletions backstop_data/engine_scripts/hover.js
Original file line number Diff line number Diff line change
@@ -1,15 +1,13 @@
module.exports = (chromy, scenario, vp) => {
const { hoverSelector } = scenario;
const waitTime = scenario.hoverWait || 0;


if (hoverSelector) {
module.exports = (chromy, scenario) => {
if (Object.prototype.hasOwnProperty.call(scenario, 'hoverSelector')) {
const waitTime = scenario.hoverWait || 0;
const hoverSelector = scenario.selectors[0];
chromy
.wait(hoverSelector)
.rect(hoverSelector)
.result((rect) => {
chromy.mouseMoved(rect.left, rect.top);
chromy.wait(waitTime);
});
})
.wait(waitTime);
}
};
2 changes: 2 additions & 0 deletions backstop_data/engine_scripts/onReady.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
const hover = require('./hover');
const focus = require('./focus');

module.exports = (chromy, scenario, vp) => {
hover(chromy, scenario);
focus(chromy, scenario);
// add more ready handlers here...
};
30 changes: 15 additions & 15 deletions build/webpack.dev.conf.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ const baseWebpackConfig = require('./webpack.common.conf')
const HtmlWebpackPlugin = require('html-webpack-plugin')
const FriendlyErrorsPlugin = require('friendly-errors-webpack-plugin')
const StyleLintPlugin = require('stylelint-webpack-plugin')
const BrowserSyncPlugin = require('browser-sync-webpack-plugin')
// const BrowserSyncPlugin = require('browser-sync-webpack-plugin')

// Define entries here so we can bind hot reloading below
const entryObj = {
Expand Down Expand Up @@ -47,19 +47,19 @@ module.exports = merge(baseWebpackConfig, {
files: ['**/*.postcss', '**/*.pcss', '**/*.vue'],
}),
new FriendlyErrorsPlugin(),
new BrowserSyncPlugin(
{
// browse to http://localhost:3000/ during development
host: 'localhost',
port: 3000,
// proxy the dev server endpoint through BrowserSync
proxy: 'http://localhost:8080/',
notify: false,
},
{
// prevent BrowserSync from reloading the page and let the dev server take care of this
reload: false,
}
),
// new BrowserSyncPlugin(
// {
// // browse to http://localhost:3000/ during development
// host: 'localhost',
// port: 3000,
// // proxy the dev server endpoint through BrowserSync
// proxy: 'http://localhost:8080/',
// notify: false,
// },
// {
// // prevent BrowserSync from reloading the page and let the dev server take care of this
// reload: false,
// }
// ),
]
})
4 changes: 2 additions & 2 deletions config/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ module.exports = {
},
dev: {
env: require('./dev.env'),
port: 8080,
autoOpenBrowser: false, // Set to false because using BrowserSync
port: 3000,
autoOpenBrowser: true, // Set to false if using BrowserSync
assetsSubDirectory: 'static',
assetsPublicPath: '/',
proxyTable: {},
Expand Down
2 changes: 0 additions & 2 deletions src/components/Utilities/utilities.backstop.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,5 @@ module.exports = [
'[data-backstop="visibility-utilities"]',
'[data-backstop="align-utilities"]',
],
delay: 0,
misMatchThreshold: 0.1,
},
];
2 changes: 0 additions & 2 deletions src/components/anchor/cdrA.backstop.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,4 @@ module.exports = [{
'[data-backstop="cdr-link"]',
'[data-backstop="cdr-link--standalone"]',
],
delay: 0,
misMatchThreshold: 0.1,
}];
5 changes: 3 additions & 2 deletions src/components/button/cdrButton.backstop.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ module.exports = [
selectors: [
'[data-backstop="buttons"]',
],
focusSelectors: [
'[data-backstop="cdr-button"]',
],
hoverSelectors: [
'[data-backstop="cdr-button"]',
'[data-backstop="cdr-button--secondary"]',
'[data-backstop="cdr-button--cta-sale"]',
],
delay: 0,
misMatchThreshold: 0.1,
},
];
2 changes: 0 additions & 2 deletions src/components/card/cdrCard.backstop.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ module.exports = [
selectors: [
'[data-backstop="simple-card"]',
],
delay: 0,
misMatchThreshold: 0.1,
},
];
5 changes: 3 additions & 2 deletions src/components/checkbox/cdrCheckbox.backstop.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ module.exports = [
hoverSelectors: [
'[data-backstop="checkbox-checked"]',
],
delay: 0,
misMatchThreshold: 0.1,
focusSelectors: [
'[data-backstop="checkbox-focus"]+label',
],
},
];
1 change: 1 addition & 0 deletions src/components/checkbox/examples/checkboxes.vue
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
<cdr-checkbox
v-model="ex1"
@change="logChange"
data-backstop="checkbox-focus"
>single</cdr-checkbox>
<p>single: {{ ex1 }}</p>
<span data-backstop="checkbox-checked">
Expand Down
2 changes: 0 additions & 2 deletions src/components/grid/grid.backstop.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,5 @@ module.exports = [
'[data-backstop="row-mosaic"]',
'[data-backstop="row-mosaic-list"]',
],
delay: 0,
misMatchThreshold: 0.1,
},
];
2 changes: 0 additions & 2 deletions src/components/heading/heading.backstop.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ module.exports = [
selectors: [
'[data-backstop="headings"]',
],
delay: 0,
misMatchThreshold: 0.1,
},
];
2 changes: 0 additions & 2 deletions src/components/icon/cdrIcon.backstop.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@ module.exports = [
hoverSelectors: [
'[data-backstop="cdr-icon-add"]',
],
delay: 0,
misMatchThreshold: 0.1,
},
];
2 changes: 0 additions & 2 deletions src/components/image/cdrImg.backstop.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@ module.exports = [
'[data-backstop="image-mods"]',
'[data-backstop="image-standard"]',
],
delay: 0,
misMatchThreshold: 0.1,
},
];
5 changes: 3 additions & 2 deletions src/components/input/cdrInput.backstop.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@ module.exports = [
selectors: [
'[data-backstop="inputs"]',
],
delay: 0,
misMatchThreshold: 0.1,
// focusSelectors: [
// '[data-backstop="text-input"]',
// ],
},
];
2 changes: 0 additions & 2 deletions src/components/list/lists.backstop.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ module.exports = [
selectors: [
'[data-backstop="lists"]',
],
delay: 0,
misMatchThreshold: 0.1,
},
];
2 changes: 0 additions & 2 deletions src/components/mediaObject/cdrMediaObject.backstop.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,5 @@ module.exports = [
'[data-backstop="media-shape-align"]',
'[data-backstop="media-object-overlay"]',
],
delay: 0,
misMatchThreshold: 0.1,
},
];
2 changes: 0 additions & 2 deletions src/components/radio/cdrRadio.backstop.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ module.exports = [
selectors: [
'[data-backstop="radios"]',
],
delay: 0,
misMatchThreshold: 0.1,
},
];
2 changes: 0 additions & 2 deletions src/components/rating/cdrRating.backstop.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ module.exports = [
selectors: [
'[data-backstop="ratings"]',
],
delay: 0,
misMatchThreshold: 0.1,
},
];
2 changes: 0 additions & 2 deletions src/components/select/cdrSelect.backstop.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ module.exports = [
selectors: [
'[data-backstop="selects"]',
],
delay: 0,
misMatchThreshold: 0.1,
},
];
3 changes: 1 addition & 2 deletions src/compositions/activityCard/cdrActivityCard.backstop.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ module.exports = [
hoverSelectors: [
'[data-backstop="activity-card"]',
],
delay: 0,
misMatchThreshold: 0.1,
hoverWait: 2000,
},
];
2 changes: 0 additions & 2 deletions src/compositions/search/cdrSearch.backstop.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,5 @@ module.exports = [
selectors: [
'[data-backstop="search"]',
],
delay: 0,
misMatchThreshold: 0.1,
},
];
16 changes: 6 additions & 10 deletions src/directives/mountain/mountain.backstop.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
module.exports = [
{
label: 'Mountains',
selectors: [
'[data-backstop="mountain-shapes"]',
],
delay: 0,
misMatchThreshold: 0.1,
},
];
module.exports = [{
label: 'Mountains',
selectors: [
'[data-backstop="mountain-shapes"]',
],
}];
2 changes: 1 addition & 1 deletion src/styles/dist/cedar-core.css

Large diffs are not rendered by default.

2 changes: 0 additions & 2 deletions templates/[name].backstop.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,4 @@
module.exports = [{
label: '{NAME-PASCAL}',
delay: 0,
misMatchThreshold: 0.1,
selectors: [],
}];
Loading

0 comments on commit 41f1a6c

Please sign in to comment.