Skip to content

Commit 125eb91

Browse files
author
RobJellinghaus
committed
Clean up deletion logic.
1 parent cc31f0e commit 125eb91

2 files changed

Lines changed: 31 additions & 45 deletions

File tree

frontend/src/containers/TodoGraphQLRelay.tsx

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,7 @@ export const TodoGraphQLRelay = () => {
5959
variables: { text },
6060
onCompleted: () => {
6161
setText('');
62-
// Relay will automatically update the cache and re-render
63-
window.location.reload(); // Simple refresh for now
62+
// Remove the reload - let Relay handle it automatically
6463
},
6564
onError: (error) => {
6665
console.error('Error creating todo:', error);

tests/relay.spec.ts

Lines changed: 30 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -4,36 +4,27 @@ import { loginAsTestUser } from '../testUtils';
44
test.describe('Relay Todo Tests', () => {
55
test.beforeEach(async ({ page }) => {
66
await loginAsTestUser(page);
7-
await page.click('text=Todos (REST)');
7+
await page.click('a:has-text("Todos (REST")');
88
await page.waitForLoadState('networkidle');
99

10+
await page.screenshot({ path: "before-each-todo-relay-test-debug.png" });
11+
12+
var n = 1;
13+
1014
// clean up any stale todos
11-
while (((await page.locator('text=delete').all()).length) > 0) {
12-
{
13-
// Get all elements matching the locator
14-
const deleteElements = await page.locator('text=delete').all();
15-
console.log(`Found ${deleteElements.length} delete elements`);
16-
17-
for (let i = 0; i < deleteElements.length; i++) {
18-
const element = deleteElements[i];
19-
console.log(`Element ${i}:`);
20-
console.log(` innerHTML: ${await element.innerHTML()}`);
21-
console.log(` textContent: ${await element.textContent()}`);
22-
console.log(` isVisible: ${await element.isVisible()}`);
23-
console.log(` outerHTML: ${await element.evaluate(el => el.outerHTML)}`);
24-
}
25-
}
26-
27-
await page.screenshot({ path: 'todos-rest-delete-debug.png' });
28-
console.log('text=delete is visible; clicking it');
29-
await page.locator('text=delete').first().click();
15+
while (((await page.locator('a:has-text("delete")').all()).length) > 0) {
16+
console.log('a:has-text("delete") is visible; clicking it');
17+
await page.locator('a:has-text("delete")').first().click();
3018
await page.waitForLoadState('networkidle');
3119
// Wait for stability, 1/10 sec
3220
await new Promise(resolve => setTimeout(resolve, 100));
21+
22+
await page.screenshot({ path: `after-todo-delete-number-${n}-debug.png`});
23+
n++;
3324
}
3425

3526
console.log('text=delete no longer visible, navigating to Todos (Relay)');
36-
await page.click('text=Todos (Relay)');
27+
await page.click('a:has-text("Todos (Relay")');
3728
});
3829

3930
test('should display Relay todos page', async ({ page }) => {
@@ -47,35 +38,30 @@ test.describe('Relay Todo Tests', () => {
4738

4839
test('should display existing todos', async ({ page }) => {
4940
// First add a todo via REST to ensure we have data
50-
await page.click('text=Todos (REST)');
41+
await page.click('a:has-text("Todos (REST")');
5142
await page.fill('input[placeholder="New todo..."]', 'Test Relay Display');
5243
await page.click('button:has-text("Add")');
5344
await expect(page.locator('text=Test Relay Display')).toBeVisible();
5445

5546
// Now check if it shows up in Relay version
56-
await page.click('text=Todos (Relay)');
57-
// Take a screenshot for debugging
58-
await page.screenshot({ path: 'todos-relay-page-1-debug.png' });
47+
await page.click('a:has-text("Todos (Relay")');
5948
// Flip back to REST and shoot that
60-
await page.click('text=Todos (REST)');
61-
await page.screenshot({ path: 'todos-rest-page-1-debug.png' });
49+
await page.click('a:has-text("Todos (REST)"');
6250
// And repeat
63-
await page.click('text=Todos (Relay)');
64-
await page.screenshot({ path: 'todos-relay-page-2-debug.png' });
51+
await page.click('a:has-text("Todos (Relay)"');
6552

6653
await expect(page.locator('text=Test Relay Display')).toBeVisible();
6754

6855
// Clean up - delete the todo via REST
69-
await page.click('text=Todos (REST)');
70-
await page.click('text=delete');
71-
await page.screenshot({ path: 'todos-rest-page-2-debug.png' });
56+
await page.click('a:has-text("Todos (REST)"');
57+
await page.click('a:has-text("delete)"');
7258

7359
// Verify the todo is gone from REST page
7460
await expect(page.locator('text=Test Relay Display')).not.toBeVisible();
7561
await expect(page.locator('text=No todos, create one!')).toBeVisible();
7662

7763
// Now verify that Relay page also shows empty state
78-
await page.click('text=Todos (Relay)');
64+
await page.click('a:has-text("Todos (Relay)"');
7965
await expect(page.locator('text=Test Relay Display')).not.toBeVisible();
8066
await expect(page.locator('text=No todos, create one!')).toBeVisible();
8167
});
@@ -101,33 +87,33 @@ test.describe('Relay Todo Tests', () => {
10187

10288
test('should show disabled edit and delete links', async ({ page }) => {
10389
// First add a todo via REST to have something to test
104-
await page.click('text=Todos (REST)');
90+
await page.click('a:has-text("Todos (REST)"');
10591
await page.fill('input[placeholder="New todo..."]', 'Test Relay Actions');
10692
await page.click('button:has-text("Add")');
10793
await expect(page.locator('text=Test Relay Actions')).toBeVisible();
10894

10995
// Go back to Relay page
110-
await page.click('text=Todos (Relay)');
96+
await page.click('a:has-text("Todos (Relay)"');
11197
await expect(page.locator('text=Test Relay Actions')).toBeVisible();
11298

11399
// Check that edit and delete links are present but don't have functionality
114100
await expect(page.locator('a:has-text("edit")')).toBeVisible();
115101
await expect(page.locator('a:has-text("delete")')).toBeVisible();
116102

117103
// Clean up
118-
await page.click('text=Todos (REST)');
104+
await page.click('a:has-text("Todos (REST)"');
119105
await page.click('text=delete');
120106
});
121107

122108
test('should display todo information correctly', async ({ page }) => {
123109
// Add a todo via REST
124-
await page.click('text=Todos (REST)');
110+
await page.click('a:has-text("Todos (REST)"');
125111
await page.fill('input[placeholder="New todo..."]', 'Test Relay Info Display');
126112
await page.click('button:has-text("Add")');
127113
await expect(page.locator('text=Test Relay Info Display')).toBeVisible();
128114

129115
// Check display in Relay version
130-
await page.click('text=Todos (Relay)');
116+
await page.click('a:has-text("Todos (Relay)"');
131117

132118
// Check that todo text is displayed
133119
await expect(page.locator('text=Test Relay Info Display')).toBeVisible();
@@ -136,7 +122,7 @@ test.describe('Relay Todo Tests', () => {
136122
await expect(page.locator('text=#')).toBeVisible();
137123

138124
// Clean up
139-
await page.click('text=Todos (REST)');
125+
await page.click('a:has-text("Todos (REST)"');
140126
await page.click('text=delete');
141127
});
142128

@@ -147,14 +133,14 @@ test.describe('Relay Todo Tests', () => {
147133

148134
test('should navigate properly between Todo implementations', async ({ page }) => {
149135
// Start at Relay page
150-
await expect(page.locator('h1:has-text("Todos (Relay)")')).toBeVisible();
136+
await expect(page.locator('h1:has-text("Todos (Relay)"')).toBeVisible();
151137

152138
// Navigate to REST
153-
await page.click('text=Todos (REST)');
139+
await page.click('a:has-text("Todos (REST)"');
154140
await expect(page.locator('h1:has-text("Todos")')).toBeVisible();
155141

156142
// Navigate back to Relay
157-
await page.click('text=Todos (Relay)');
143+
await page.click('a:has-text("Todos (Relay)"');
158144
await expect(page.locator('h1:has-text("Todos (Relay)")')).toBeVisible();
159145
});
160146

@@ -170,6 +156,7 @@ test.describe('Relay Todo Tests', () => {
170156
});
171157

172158
test('should allow adding a new todo item', async ({ page }) => {
159+
await page.screenshot({ path: "should-allow-add-debug.png" });
173160
// Initially should show empty state
174161
await expect(page.locator('text=No todos, create one!')).toBeVisible();
175162

@@ -194,7 +181,7 @@ test.describe('Relay Todo Tests', () => {
194181
await expect(page.locator('text=#')).toBeVisible();
195182

196183
// Clean up by deleting via REST (since Relay delete isn't implemented yet)
197-
await page.click('text=Todos (REST)');
184+
await page.click('a:has-text("Todos (REST)"');
198185
await page.click('text=delete');
199186
});
200187

0 commit comments

Comments
 (0)