|
1 | | -import { test, expect, Widget } from '../fixtures.js' |
2 | | -import { |
3 | | - DitoListView, |
4 | | - DitoForm, |
5 | | - DitoNestedList |
6 | | -} from '../../../utils/pages.js' |
7 | | - |
8 | | -test.describe('nested-list', () => { |
9 | | - test('add items, save, reload, delete one, reload', async ({ |
10 | | - page, |
11 | | - url |
12 | | - }) => { |
13 | | - // Seed a widget with no items initially. |
14 | | - const widget = await Widget.query().insert({ name: 'Widget A' }) |
15 | | - |
16 | | - const list = new DitoListView(page, url, 'Widget') |
17 | | - const form = new DitoForm(page) |
18 | | - const items = new DitoNestedList(page, 'Items') |
19 | | - |
20 | | - await list.navigate('/widgets') |
21 | | - await list.list.edit('Widget A') |
22 | | - |
23 | | - // Add two items via the nested list. Each Add click appends a new |
24 | | - // row whose inline form contains a Label field. Fill by row index |
25 | | - // to disambiguate from the previously-added row. |
26 | | - await items.add() |
27 | | - await items.rows |
28 | | - .nth(0) |
29 | | - .getByLabel('Label', { exact: true }) |
30 | | - .fill('first') |
31 | | - await items.add() |
32 | | - await items.rows |
33 | | - .nth(1) |
34 | | - .getByLabel('Label', { exact: true }) |
35 | | - .fill('second') |
36 | | - |
37 | | - await form.save() |
38 | | - |
39 | | - // Reload via the list and confirm the items rehydrated with the |
40 | | - // typed labels. |
41 | | - await list.navigate('/widgets') |
42 | | - await list.list.edit('Widget A') |
43 | | - await expect(items.rows).toHaveCount(2) |
44 | | - await expect(items.rows.nth(0).getByLabel('Label')).toHaveValue('first') |
45 | | - await expect(items.rows.nth(1).getByLabel('Label')).toHaveValue('second') |
46 | | - |
47 | | - // Confirm DB state matches. |
48 | | - const persisted = await Widget.query() |
49 | | - .findById(widget.$id() as number) |
50 | | - .withGraphFetched('items') |
51 | | - const persistedLabels = (persisted?.items ?? []) |
52 | | - .map(i => i.label) |
53 | | - .sort() |
54 | | - expect(persistedLabels).toEqual(['first', 'second']) |
55 | | - |
56 | | - // Delete the first item, save, reload, assert one remains with the |
57 | | - // surviving label. |
58 | | - await items.delete(0) |
59 | | - await form.save() |
60 | | - await list.navigate('/widgets') |
61 | | - await list.list.edit('Widget A') |
62 | | - await expect(items.rows).toHaveCount(1) |
63 | | - await expect(items.rows.nth(0).getByLabel('Label')).toHaveValue('second') |
64 | | - |
65 | | - const remaining = await Widget.query() |
66 | | - .findById(widget.$id() as number) |
67 | | - .withGraphFetched('items') |
68 | | - const remainingLabels = (remaining?.items ?? []).map(i => i.label) |
69 | | - expect(remainingLabels).toEqual(['second']) |
70 | | - }) |
71 | | -}) |
| 1 | +import './crud.js' |
| 2 | +import './drag-reorder.js' |
0 commit comments