@@ -208,9 +208,9 @@ def test_the_rows_of_chosen_ids_say_which_the_listing_does_not_hold(self):
208208
209209
210210class TheTaskRows (unittest .TestCase ):
211- """A task is one line: its title cut to the width; its whole text in the row's tooltip and, while its box has the
212- keyboard's focus, in place; its id beside it on hover or focus. A click anywhere on the row ticks it ; its box, a
213- link or a button keeps its own action."""
211+ """A task is one line: its title cut to the width; its whole text in the row's tooltip and, while its box (its
212+ text in a read-only list, where the box is disabled) has the keyboard's focus, in place ; its id beside it on
213+ hover or focus. A click anywhere on the row ticks it; its box, a link or a button keeps its own action."""
214214
215215 def test_a_row_is_one_line_ticked_by_a_click_with_its_whole_text_on_hover_and_its_id_beside_it (self ):
216216 node = shutil .which ("node" )
@@ -227,7 +227,8 @@ def test_a_row_is_one_line_ticked_by_a_click_with_its_whole_text_on_hover_and_it
227227 });
228228 return elements.get(id);
229229}
230- element('tasks-page').dataset = {writable: 'true', listing: '/listing', rows: '/rows'};
230+ const writable = process.argv[2] === 'true';
231+ element('tasks-page').dataset = {writable: process.argv[2], listing: '/listing', rows: '/rows'};
231232const long = 'Open the report and ' + 'make the second table match the first one, '.repeat(6);
232233const tasks = [{id: 'os__a', title: long.slice(0, 99) + '…', text: long, categories: {}}, {id: 'b', title: '', text: '', categories: {}}];
233234const request = async () => ({json: async () => ({ok: true, ready: true, total: 2, of: 2, pages: 1, page: 1, categories: {}, described: true, tasks})});
@@ -241,24 +242,33 @@ def test_a_row_is_one_line_ticked_by_a_click_with_its_whole_text_on_hover_and_it
241242 for (let n = 0; n < 20; n++) await Promise.resolve();
242243 const rows = element('tasks-rows').innerHTML;
243244 assert.ok(rows.includes(`<tr data-id="os__a" title="${long}"><td class="tasks-tick">`), rows);
244- assert.ok(rows.includes(`<span class="tasks-row"><span class="tasks-title">${long.slice(0, 99)}…</span>`), rows);
245+ // the text takes the keyboard's focus only where the box cannot
246+ const text = writable ? '<span class="tasks-row">' : '<span class="tasks-row" tabindex="0">';
247+ assert.ok(rows.includes(`${text}<span class="tasks-title">${long.slice(0, 99)}…</span>`), rows);
245248 assert.ok(rows.includes(`<span class="tasks-whole">${long}</span><small class="tasks-id mono faint">os__a</small></span>`), rows);
246249 // an id alone is its own title, with nothing beside it
247250 assert.ok(rows.includes('<tr data-id="b" title="b">'), rows);
248251 assert.ok(rows.includes('<span class="tasks-title">b</span><span class="tasks-whole">b</span></span>'), rows);
249- // the row's box clicked, as the browser does: it turns and says so
252+ // the generated row's box, looked up and clicked as the browser does: an enabled checkbox turns and says so
253+ const input = (rows.match(/<tr data-id="os__a"[\s\S]*?<\/tr>/) || [''])[0].match(/<input\b[^>]*>/)?.[0] || '';
254+ const checkbox = /\stype="checkbox"/.test(input), enabled = checkbox && !/\sdisabled\b/.test(input);
255+ assert.ok(checkbox && enabled === writable, input);
250256 const box = {checked: false, closest: () => ({dataset: {id: 'os__a'}}),
251- click() { this.checked = !this.checked; element('tasks-rows').listeners.change({target: {closest: () => box}}); }};
252- const tr = {querySelector: s => s === 'input[type=checkbox]' ? box : null};
257+ click() { if (!enabled) return; this.checked = !this.checked; element('tasks-rows').listeners.change({target: {closest: () => box}}); }};
258+ const tr = {querySelector: s => s === 'input[type=checkbox]' && checkbox ? box : null};
253259 const click = own => element('tasks-rows').listeners.click({target: {closest: s => s === 'input, a, button' ? own : s === 'tr[data-id]' ? tr : null}});
260+ if (!writable) { click(null); assert.equal(box.checked, false); return; } // read-only: a click ticks nothing
254261 click(null); assert.equal(element('tasks-chosen').textContent, '1 chosen');
255262 click({}); assert.equal(element('tasks-chosen').textContent, '1 chosen'); // the box, a link or a button: its own action alone
256263 selected = 'the second table'; click(null); assert.equal(element('tasks-chosen').textContent, '1 chosen'); // words selected
257264 selected = ''; click(null); assert.equal(element('tasks-chosen').textContent, '0 chosen');
258265})().catch(error => { console.error(error); process.exitCode = 1; });
259266"""
260- got = subprocess .run ([node , "-e" , program , str (script )], stdin = subprocess .DEVNULL , capture_output = True , text = True , timeout = 10 )
261- self .assertEqual (got .returncode , 0 , got .stderr )
267+ for writable in ("true" , "false" ):
268+ with self .subTest (writable = writable ):
269+ got = subprocess .run ([node , "-e" , program , str (script ), writable ], stdin = subprocess .DEVNULL , capture_output = True ,
270+ text = True , timeout = 10 )
271+ self .assertEqual (got .returncode , 0 , got .stderr )
262272 css = (Path (__file__ ).resolve ().parents [1 ] / "static/catalogue/catalogue.css" ).read_text (encoding = "utf-8" )
263273 self .assertIn (".tasks-row .tasks-title { flex: 1 1 auto; min-width: 0; overflow: hidden; white-space: nowrap; text-overflow: ellipsis; }" , css )
264274 self .assertIn (".tasks-table tr:hover .tasks-id, .tasks-table tr:focus-within .tasks-id { display: inline; }" , css )
0 commit comments