Database-BI

 view release on metacpan or  search on metacpan

t/model.t  view on Meta::CPAN

	like $b, qr/class="drag-handle"[^>]*aria-describedby="move-help"/s,
		'the handle is described by the instructions';
	like $b, qr/id="move-help"[^>]*>[^<]*arrow keys/s, 'the instructions name the arrow keys';
	like $b, qr/id="canvas-live"[^>]*role="status"/,  'there is a polite announcer for a move';

	# Dropping a cell and dropping on a card are the same gesture now, so the
	# native drag machinery is gone: the card is not a drag source and nothing
	# listens for a native drop.
	unlike $b, qr/<div class="visual-card[^"]*"[^>]*draggable/s,
		'the card is no longer a native drag source';
	# The template itself has no native drag machinery left.  The page as a whole
	# still has both, for the file-drop upload overlay in the shared layout, so
	# this is checked against the canvas template rather than the rendered page.
	my $src = $t->app->home->child('templates/web/en/canvas.html.tt')->to_string;
	open my $fh, '<', $src or die "Cannot read $src: $!";
	my $tt = do { local $/; <$fh> };
	close $fh;
	unlike $tt, qr/dataTransfer/, 'no native drag payload is read';
	unlike $tt, qr/\bdraggable\b/, 'nothing in the canvas is a native drag source';

	# The drag: pointer events, a ghost showing the landing cell, and the cards it
	# lands on pushed out of the way.
	like $b, qr/function onMoveStart/,      'the move handler is defined';
	like $b, qr/addEventListener\('pointermove'/, 'the drag tracks the pointer';
	like $b, qr/function placeGhost/,       'the landing cell is drawn while dragging';
	like $b, qr/function pushApart/,        'cards in the way are pushed down';
	like $b, qr/function commitMove/,       'the drop places the card and saves';
	like $b, qr/function overlaps/,         'overlap is what decides who moves';
	like $b, qr/\.visual-drop-ghost\s*\{[^}]*dashed/s, 'the ghost is outlined';
	like $b, qr/\.visual-card\.moving/,    'the card being dragged is marked';

	# The keyboard equivalent, and the announcement of where the card went.
	like $b, qr/function onMoveKey/,        'the keyboard move handler is defined';
	like $b, qr/e\.shiftKey/,              'Shift jumps to the edge of the canvas';
	like $b, qr/function gridBottom/,       'the bottom of the canvas is computed';
	like $b, qr/function announce/,         'each move is announced';
	like $b, qr/\.drag-handle:focus-visible/, 'the focused handle is visible';

	# The announcement covers the arrangement the move leaves behind, not just
	# the card that was moved: a reader who is told only about their own card
	# loses track of the one that was pushed out of its cell, and the next key
	# press starts from a canvas they do not have.
	like $b, qr/return moved;/, 'pushApart reports the cards it had to move down';
	like $b, qr/function displacedText/, 'the announcement has one place to name them';
	like $b, qr/titleOf\(m\.card\) \+ ' moved down to row ' \+ m\.to/,
		'each named with the row it was pushed to';
	my $displaced = () = $b =~ /displacedText\(moved\)/g;
	is $displaced, 3,
		'and both a move and a size change say what they pushed aside (one definition, two calls)';
};

# ---------------------------------------------------------------------------
# Phase 3.2 -- the size menu: a preset width per card, chosen without a drag
# ---------------------------------------------------------------------------

subtest '3.2: each card has a size menu that sets its width without a drag' => sub {
	my $sales_path = $t->app->home->child('data/sales.csv')->to_string;
	plan skip_all => 'data/sales.csv not found' unless -f $sales_path;

	my $spec = {
		name     => 'SizeMenu',
		datasets => [ { spec => "path:$sales_path", alias => 'left' } ],
		visuals  => [
			{ kind => 'table', encode => {}, title => 'Left'  },
			{ kind => 'table', encode => {}, title => 'Right' },
		],
	};
	my $cid = $t->post_ok('/api/analyses',
		{ 'Content-Type' => 'application/json' },
		encode_json($spec)
	)->status_is(201)->tx->res->json->{id};

	$t->get_ok("/a/$cid")->status_is(200);
	my $b = $t->tx->res->body;

	# One menu per card, in the card's own header, named for the card it sizes.
	my $menus = () = $b =~ /class="visual-size-select"/g;
	is $menus, 2, 'one size menu per visual';
	like $b, qr/<select class="visual-size-select" id="visual-size-0"/,
		'the menu belongs to its own card';
	like $b, qr/visual-card-header">[\s\S]*?visual-size-select[\s\S]*?visual-card-body">/,
		'and sits in the card header';

	# The size is on the card as well as in the menu (3.2): one badge per card,
	# in the header it sizes, beside the menu it mirrors.  Neither of these cards
	# has a saved span, so the browser places them and there is no size to print
	# yet: the badge is rendered empty, and :empty is what keeps that from being
	# a small blank pill of padding rather than nothing.  The script fills it in.
	my $badges = () = $b =~ /class="visual-size-badge"/g;
	is $badges, 2, 'one size badge per visual, on the same cards as the menus';
	like $b, qr{<span class="visual-size-badge" data-size-badge="1"></span>},
		'a card with no saved span is rendered with an empty badge';
	like $b, qr{visual-size-select[\s\S]*?visual-size-badge[\s\S]*?visual-card-body">},
		'which sits in the header beside the menu it mirrors';
	like $b, qr/\.visual-size-badge:empty \{ display: none; \}/,
		'and takes no room while it is empty';
	like $b, qr/\.visual-size-badge \{[^}]*flex-shrink:\s*0/s,
		'it does not shrink, where the menu it sits beside does';
	like $b, qr/id="visual-size-0"[^>]*aria-label="Size of Left"/s,
		'it is named for the visual it sizes';
	like $b, qr/id="visual-size-0"[^>]*aria-describedby="size-help"/s,
		'with the way to use it described for anyone who needs telling';
	like $b, qr/<p class="sr-only" id="size-help">Size a visual without dragging/,
		'the help is on the page, and takes no room on it';

	# The presets, as widths in grid columns: full, half, a third and a quarter.
	like $b, qr/<option value="12">Full width<\/option>/,   'full width is a preset';
	like $b, qr/<option value="6">Half width<\/option>/,    'half width is a preset';
	like $b, qr/<option value="4">Third width<\/option>/,   'third width is a preset';
	like $b, qr/<option value="3">Quarter width<\/option>/, 'quarter width is a preset';
	like $b, qr/GRID_COLS\s*=\s*12/, 'and full width is the whole twelve-column grid';
	like $b, qr/<optgroup label="Width">/, 'the widths are grouped under their name';

	# Height presets in the same menu, so the second dimension needs no drag
	# either.  The values are prefixed, because a select carries one value and
	# "2" would be read as a width.
	like $b, qr/<optgroup label="Height">/, 'the heights are grouped too';
	like $b, qr/<option value="h1">1 row high<\/option>/, 'one row is a preset';
	like $b, qr/<option value="h2">2 rows high<\/option>/, 'two rows is a preset';
	like $b, qr/<option value="h3">3 rows high<\/option>/, 'three rows is a preset';
	like $b, qr/<option value="h6">6 rows high<\/option>/,  'and six, the tallest a card can be';
	like $b, qr/MAX_ROW_SPAN\s*=\s*6/, 'which is the row span limit';

	# One option is not a choice but the size the card is, written by the script
	# from the measured span so a drag cannot leave the menu lying.
	like $b, qr/<option value="" data-current="1">Size<\/option>/,
		'the first option is the size the card actually is';
	like $b, qr/function sizeSummary/,
		'which is written from both dimensions';
	like $b, qr/function presetLabel/, 'in the preset words, where the card is on one';
	like $b, qr/current\.textContent = sizeSummary\(sel, st\.w, st\.h\);/,
		'width and height together';

	# The menu and the corner grip are two ways to the same write.
	like $b, qr/function commitSize\(card, w, h\)/,
		'a chosen width and height are applied by commitSize';
	like $b, qr/h = clampSpan\(h, 1, MAX_ROW_SPAN\);/, 'the height within the row limit';
	like $b, qr/var isRow   = raw\.charAt\(0\) === 'h';/,
		'a prefixed value is a height, a bare one a width';
	like $b, qr/if \(isRow\) commitSize\(card, st\.w, value\);/, 'a height keeps the width';
	like $b, qr/else       commitSize\(card, value, st\.h\);/, 'a width keeps the height';
	like $b, qr/function initSizeMenus/,
		'each menu is wired up';
	like $b, qr/^\s*initSizeMenus\(\);\r?$/m, 'at load';
	like $b, qr/function updateSizeSelect/,
		'the menu shows the size the card actually is';
	like $b, qr/function updateSizeBadge\(card, state\)/,
		'and the card shows it too, rather than only the menu';
	like $b, qr/option\[data-current="1"\]/,
		'and the option that says what the card is is found by its own marker';
	like $b, qr/id="size-help"[^>]*>[^<]*height to one, two, three or six rows/s,
		'the help says the menu sets the height as well';
	like $b, qr/badge\.textContent = st\.w \+ ' \\u00D7 ' \+ st\.h;/,
		'as the two numbers the menu spells out in words';
	like $b, qr/\? sizeSummary\(sel, st\.w, st\.h\)/,
		'with the menu words for the presets as the title';
	like $b, qr/function updateSizeControls\(card, state\) \{/,
		'both readings of the size are written through one function';
	like $b, qr/^\t\tupdateSizeSelect\(card, state\);\r?$/m,
		'which writes the menu';
	like $b, qr/^\t\tupdateSizeBadge\(card, state\);\r?$/m,
		'and the card, so the two cannot disagree';
	like $b, qr/updateSizeControls\(card, st\)/,
		'so a drag, which leaves any width, is reflected in the menu and on the card';
	like $b, qr/updateSizeBadge\(card, \{ w: w, h: h \}\);/,
		'and the size on the card follows the grip while it is being dragged';
	like $b, qr/if \(w !== shownW \|\| h !== shownH\) \{/,
		'written only when the drag crosses a column or a row';
	like $b, qr/if \(isNaN\(value\) \|\| value === \(isRow \? st\.h : st\.w\)\) return;/,
		'choosing the size it already is does nothing at all';
	like $b, qr/var index = sel\.selectedIndex;/, 'the entry that was chosen is remembered';
	like $b, qr/sel\.selectedIndex = index;/,
		'and stays selected, so the arrow keys walk the list rather than being pulled back';
	like $b, qr/announce\(titleOf\(card\) \+ ' is now ' \+/, 'the new size is announced';
	like $b, qr/lowerFirst\(sel \? sizeSummary\(sel, w, h\)/,
		'both dimensions of it, in the menu words, not just drawn';
	like $b, qr/closest\('\.visual-resize-handle, button, a, select'\)/,
		'a press on the menu does not start a card drag';
	like $b, qr/\@media print.*?\.visual-size-select[^{]*\{[^}]*display\s*:\s*none/s,
		'the menu is not printed';
	like $b, qr/\@media print.*?\.visual-size-badge[^{]*\{[^}]*display\s*:\s*none/s,
		'and neither is the size on the card: the printed canvas is two columns';
	like $b, qr/\.visual-size-select \{[^}]*max-width:\s*11\.5rem/s,
		'and is wide enough to read the longest size it can report';
	like $b, qr/Size menu\s+in\s+its header to set its width and height without a drag/,
		'and the first-visit tip names it too';
	like $b, qr/same size is written on the card itself, beside the\s+menu/,
		'and the size help says where the size is written';

	# A card that has to move to be the width that was chosen is moved, and what
	# it grew over is pushed down - the same fix the resize paths now make.
	my $pushes = () = $b =~ /pushApart\(card\);/g;
	is $pushes, 4,
		'growing over a neighbour is resolved in the menu, both resize paths and a drop';

	# That push is not decoration: without it the grown layout is two cards
	# sharing cells 7-12, which the server refuses, so the width would be lost at
	# the next reload.  With it, the layout the menu produces is accepted.
	$t->patch_ok("/api/analyses/$cid",
		{ 'Content-Type' => 'application/json' },
		encode_json({ layout => [
			{ visual => 0, x => 1, y => 1, w => 12, h => 1 },
			{ visual => 1, x => 1, y => 2, w => 12, h => 1 },
		] })



( run in 0.922 second using v1.01-cache-2.11-cpan-60884a8df76 )