Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test(review-rating): screenshot tests #183

Merged
merged 6 commits into from
Apr 13, 2023
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
Binary file not shown.
Binary file not shown.
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
import {
createStorybookUrl,
setupScreenshotTesting,
} from '../../../screenshotUtils';

const packageName = 'review-rating';

const scores = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10];

const clip = { x: 0, y: 0, width: 500, height: 200 };
// the svg "donut" renders slightly different at its edges on different devices. the blur gets around that
const blur = 2;

const screenshotTesting = setupScreenshotTesting({
it,
beforeAll,
afterAll,
expect,
});

describe(
'ReviewRating variants size=XS',
screenshotTesting({
cases: scores.map(score => [
'sprite',
createStorybookUrl({
packageName,
knobs: {
score,
size: 'XS',
},
}),
]),
screenshotOpts: {
clip,
animations: 'disabled',
},
matchImageSnapshotOptions: { blur },
}),
);

describe(
'ReviewRating variants size=S',
screenshotTesting({
cases: scores.map(score => [
'sprite',
createStorybookUrl({
packageName,
knobs: {
score,
size: 'S',
},
}),
]),
screenshotOpts: { clip, animations: 'disabled' },
matchImageSnapshotOptions: { blur },
}),
);

describe(
'ReviewRating variants size=M',
screenshotTesting({
cases: scores.map(score => [
'sprite',
createStorybookUrl({
packageName,
knobs: {
score,
size: 'M',
},
}),
]),
screenshotOpts: { clip, animations: 'disabled' },
matchImageSnapshotOptions: { blur },
}),
);

describe(
'ReviewRating variants size=L',
screenshotTesting({
cases: scores.map(score => [
'sprite',
createStorybookUrl({
packageName,
knobs: {
score,
size: 'L',
},
}),
]),
screenshotOpts: { clip, animations: 'disabled' },
matchImageSnapshotOptions: { blur },
}),
);
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.
3 changes: 2 additions & 1 deletion packages/screenshotUtils/createStorybookUrl.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ export function createStorybookUrl({
.reduce((acc, knobName) => `${acc};${knobName}:${knobs[knobName]}`, '')
.substring(1);

const componentPath = `-${packageName}--${moduleName || packageName}`;
const noHyphenName = packageName ? packageName.replace(/-/g, '') : '';
const componentPath = `-${noHyphenName}--${moduleName || packageName}`;
const component = componentPath.split('--').pop() || '';

return `${url}?id=components-${
Expand Down