Redesigns the testimonials section
A landscape photo overlaps a card with the shoot type, quote and names. The controls are two arrows with an X / Y counter; the dots are gone and nothing moves by itself. A change slides the whole slide horizontally, also on a swipe. Reviews get an optional imagePosition for the crop, normalised by normalizeImagePosition; slideCounter writes the counter. Both helpers have property tests next to example tests. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
+98
-22
@@ -228,17 +228,89 @@ export const uniqueShootTypes = fc.uniqueArray(shootType, {
|
||||
maxLength: 5,
|
||||
});
|
||||
|
||||
// A review that meets every invariant
|
||||
export const testimonial: fc.Arbitrary<Testimonial> = fc.record({
|
||||
id: fc.oneof(
|
||||
fc.constantFrom('majella-mark', 'demi-kevin'),
|
||||
fc.stringMatching(/^[a-z0-9-]{1,16}$/),
|
||||
// A crop position the way content may write it: two percentages from 0 to
|
||||
// 100 (whole or with up to two decimals) with any whitespace around and
|
||||
// between. x and y are the numbers, text is how they are written.
|
||||
export const imagePositionValid = fc
|
||||
.tuple(
|
||||
fc.integer({ min: 0, max: 10000 }),
|
||||
fc.integer({ min: 0, max: 10000 }),
|
||||
fc.constantFrom('', ' ', '\t', '\n '),
|
||||
fc.constantFrom(' ', ' ', '\t', ' \n '),
|
||||
fc.constantFrom('', ' ', '\t'),
|
||||
)
|
||||
.map(([hundredthsX, hundredthsY, before, between, after]) => {
|
||||
const [x, y] = [hundredthsX / 100, hundredthsY / 100];
|
||||
return {
|
||||
x,
|
||||
y,
|
||||
text: `${before}${x}%${between}${y}%${after}`,
|
||||
};
|
||||
});
|
||||
|
||||
// Crop positions that are not acceptable: out of range, one part, no percent
|
||||
// sign, a sign or exponent, extra parts, other text and non-strings
|
||||
export const imagePositionInvalid: fc.Arbitrary<unknown> = fc.oneof(
|
||||
fc
|
||||
.tuple(
|
||||
fc.integer({ min: 10001, max: 99999 }),
|
||||
fc.integer({ min: 0, max: 10000 }),
|
||||
)
|
||||
.map(([big, small]) => `${big / 100}% ${small / 100}%`),
|
||||
fc
|
||||
.tuple(
|
||||
fc.integer({ min: 0, max: 10000 }),
|
||||
fc.integer({ min: 10001, max: 99999 }),
|
||||
)
|
||||
.map(([small, big]) => `${small / 100}% ${big / 100}%`),
|
||||
fc.constantFrom(
|
||||
'',
|
||||
' ',
|
||||
'50%',
|
||||
'50 42',
|
||||
'50% 42',
|
||||
'50 42%',
|
||||
'-5% 10%',
|
||||
'+5% 10%',
|
||||
'1e1% 5%',
|
||||
'50% 42% 10%',
|
||||
'50%42%',
|
||||
'center',
|
||||
'top left',
|
||||
'50.% 42%',
|
||||
'.5% 42%',
|
||||
),
|
||||
shoot: nonBlank,
|
||||
quote: nonBlank,
|
||||
author: nonBlank,
|
||||
image,
|
||||
});
|
||||
fc.constantFrom(undefined, null, 50, true, {}, ['50% 42%']),
|
||||
);
|
||||
|
||||
// Anything content might hold in imagePosition: good and bad
|
||||
export const imagePositionAny: fc.Arbitrary<unknown> = fc.oneof(
|
||||
imagePositionValid.map(({ text }) => text),
|
||||
imagePositionInvalid,
|
||||
fc.string(),
|
||||
);
|
||||
|
||||
// The raw text of a crop position as a review field: valid, garbled or odd
|
||||
const imagePositionText = fc.oneof(
|
||||
imagePositionValid.map(({ text }) => text),
|
||||
fc.string(),
|
||||
);
|
||||
|
||||
// A review that meets every invariant, with or without a crop position
|
||||
export const testimonial: fc.Arbitrary<Testimonial> = fc.record(
|
||||
{
|
||||
id: fc.oneof(
|
||||
fc.constantFrom('majella-mark', 'demi-kevin'),
|
||||
fc.stringMatching(/^[a-z0-9-]{1,16}$/),
|
||||
),
|
||||
shoot: nonBlank,
|
||||
quote: nonBlank,
|
||||
author: nonBlank,
|
||||
image,
|
||||
imagePosition: imagePositionText,
|
||||
},
|
||||
{ requiredKeys: ['id', 'shoot', 'quote', 'author', 'image'] },
|
||||
);
|
||||
|
||||
// Valid reviews with unique ids
|
||||
export const uniqueTestimonials = fc.uniqueArray(testimonial, {
|
||||
@@ -249,18 +321,22 @@ export const uniqueTestimonials = fc.uniqueArray(testimonial, {
|
||||
// Valid and broken reviews mixed, as a CMS might deliver them
|
||||
export const anyTestimonial: fc.Arbitrary<Testimonial> = fc.oneof(
|
||||
testimonial,
|
||||
fc.record({
|
||||
id: fc.oneof(fc.constantFrom('majella-mark', '', ' '), fc.string()),
|
||||
shoot: fc.oneof(nonBlank, fc.constantFrom('', ' ')),
|
||||
quote: fc.oneof(nonBlank, fc.constantFrom('', ' ')),
|
||||
author: fc.oneof(nonBlank, fc.constantFrom('', ' ')),
|
||||
image: fc.record({
|
||||
src: fc.oneof(fc.constant(''), fc.constant('/a.jpg')),
|
||||
alt: fc.string({ maxLength: 10 }),
|
||||
width: fc.integer({ min: -1, max: 10 }),
|
||||
height: fc.integer({ min: -1, max: 10 }),
|
||||
}),
|
||||
}),
|
||||
fc.record(
|
||||
{
|
||||
id: fc.oneof(fc.constantFrom('majella-mark', '', ' '), fc.string()),
|
||||
shoot: fc.oneof(nonBlank, fc.constantFrom('', ' ')),
|
||||
quote: fc.oneof(nonBlank, fc.constantFrom('', ' ')),
|
||||
author: fc.oneof(nonBlank, fc.constantFrom('', ' ')),
|
||||
image: fc.record({
|
||||
src: fc.oneof(fc.constant(''), fc.constant('/a.jpg')),
|
||||
alt: fc.string({ maxLength: 10 }),
|
||||
width: fc.integer({ min: -1, max: 10 }),
|
||||
height: fc.integer({ min: -1, max: 10 }),
|
||||
}),
|
||||
imagePosition: imagePositionText,
|
||||
},
|
||||
{ requiredKeys: ['id', 'shoot', 'quote', 'author', 'image'] },
|
||||
),
|
||||
);
|
||||
|
||||
// Shoot values as the form offers them for the live packages
|
||||
|
||||
Reference in New Issue
Block a user