Database-BI

 view release on metacpan or  search on metacpan

t/model.t  view on Meta::CPAN

	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 },
		] })
	)->status_is(200, 'a full-width card, and the neighbour pushed below it, is accepted');

	my $accepted = [
		{ visual => 0, x => 1, y => 1, w => 12, h => 1 },
		{ visual => 1, x => 1, y => 2, w => 12, h => 1 },
	];

	$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 => 7, y => 1, w => 6,  h => 1 },
		] })
	)->status_is(400,
		'the same growth without the push is refused, which is why commitSize pushes');

	$t->get_ok("/api/analyses/$cid")->status_is(200);
	is_deeply $t->tx->res->json->{layout}, $accepted,
		'and the refused layout left the saved one alone';

	# The size on the card, rendered: the numbers are the card's own saved spans,
	# written by the template, so a reload shows them with no JavaScript involved
	# - a card a drag left at a width no preset names says which width that was.
	$t->get_ok("/a/$cid")->status_is(200);
	$b = $t->tx->res->body;



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