forked from keystonejs/keystone
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
6261/delete alert tests (keystonejs#6382)
* new deletion logic in Listview * add crud-notifications test project * update deletion solution to be more pragmatic at scale * update bug fix to be more verbose * minor updates to copy * remove log * init * updated delete notif tests * update usage of deleteAll utility * update test.yml to include new test file * remove onconnect and unnecessary try catch * comments * update gitignore * update tests and schema.graphql * remove headless false flag * remove unnecessary closure, update failing test * remove unnecessary try/catch block * fix test add throw statement to errors * add waitForNaigation to beforeEach to avoid navigation destroying evaluation context * remove navigation in beforeAll altogether * add acess control headers to fix ff preflight errors * sub out fetch for node-fetch and circumvent weird preflight issues via page.evaluate * remove page argument from seedData fn * update yarn.lock * simplify code by exporting deleteAllData and moving projectRoot resolution
- Loading branch information
1 parent
2e3f366
commit 3ecbd0c
Showing
6 changed files
with
145 additions
and
25 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -121,6 +121,7 @@ temp/ | |
|
||
# SQLite databases | ||
*.db | ||
*.db-journal | ||
|
||
# Generated files from build process | ||
robots.txt | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,126 @@ | ||
import { Browser, Page } from 'playwright'; | ||
import fetch from 'node-fetch'; | ||
import { adminUITests, deleteAllData } from './utils'; | ||
|
||
adminUITests('./tests/test-projects/crud-notifications', browserType => { | ||
let browser: Browser = undefined as any; | ||
let page: Page = undefined as any; | ||
const seedData = async (query: string, variables?: Record<string, any>) => { | ||
try { | ||
const { errors } = await fetch('http://localhost:3000/api/graphql', { | ||
method: 'POST', | ||
headers: { | ||
'Content-Type': 'application/json', | ||
}, | ||
body: JSON.stringify({ | ||
query, | ||
variables, | ||
}), | ||
}).then(res => res.json()); | ||
if (errors) { | ||
throw errors; | ||
} | ||
} catch (e) { | ||
console.log(e); | ||
throw e; | ||
} | ||
}; | ||
|
||
beforeAll(async () => { | ||
browser = await browserType.launch(); | ||
page = await browser.newPage(); | ||
}); | ||
beforeEach(async () => { | ||
// Drop the database | ||
await deleteAllData('./tests/test-projects/crud-notifications'); | ||
}); | ||
|
||
test('Complete deletion success, only shows the successful deletion prompt', async () => { | ||
// hack for gql syntax highlighting | ||
const gql = String.raw; | ||
const query = gql` | ||
mutation CreateTaskItem { | ||
createTask(data: { label: "you can delete me" }) { | ||
id | ||
label | ||
} | ||
} | ||
`; | ||
await seedData(query); | ||
await Promise.all([page.waitForNavigation(), page.goto('http://localhost:3000/tasks')]); | ||
await page.waitForSelector('tbody tr:first-of-type td:first-of-type label'); | ||
await page.click('tbody tr:first-of-type td:first-of-type label'); | ||
await page.waitForSelector('button:has-text("Delete")'); | ||
await page.click('button:has-text("Delete")'); | ||
await page.click('div[role="dialog"] button:has-text("Delete")'); | ||
await page.waitForSelector( | ||
'div[role="alert"] h3:has-text("Deleted 1 of 1 Tasks successfully")' | ||
); | ||
const dialogs = await page.$$('div[role="alert"] > div'); | ||
expect(dialogs.length).toBe(1); | ||
}); | ||
|
||
test('Complete deletion failure, only shows the successful failure prompt', async () => { | ||
// hack for gql syntax highlighting | ||
const gql = String.raw; | ||
const query = gql` | ||
mutation CreateTaskItem { | ||
createTask(data: { label: "do not delete" }) { | ||
id | ||
label | ||
} | ||
} | ||
`; | ||
await seedData(query); | ||
await Promise.all([page.waitForNavigation(), page.goto('http://localhost:3000/tasks')]); | ||
await page.click('tbody tr:first-of-type td:first-of-type label'); | ||
await page.click('button:has-text("Delete")'); | ||
await page.click('div[role="dialog"] button:has-text("Delete")'); | ||
await page.waitForSelector('div[role="alert"] h3:has-text("Failed to delete 1 of 1 Tasks")'); | ||
const dialogs = await page.$$('div[role="alert"] > div'); | ||
expect(dialogs.length).toBe(1); | ||
}); | ||
|
||
test('Partial deletion failure', async () => { | ||
// hack for gql syntax highlighting | ||
const gql = String.raw; | ||
const query = gql` | ||
mutation CreateTaskItems($data: [TaskCreateInput!]!) { | ||
createTasks(data: $data) { | ||
id | ||
label | ||
} | ||
} | ||
`; | ||
const variables = { | ||
data: Array.from(Array(75).keys()).map(key => { | ||
if (key >= 50) { | ||
return { | ||
label: `delete me ${key - 50}`, | ||
}; | ||
} else { | ||
return { | ||
label: `do not delete ${key}`, | ||
}; | ||
} | ||
}), | ||
}; | ||
await seedData(query, variables); | ||
await Promise.all([ | ||
page.waitForNavigation(), | ||
page.goto('http://localhost:3000/tasks?sortBy=label&page=1'), | ||
]); | ||
await page.click('thead th:first-of-type label'); | ||
await page.click('button:has-text("Delete")'); | ||
await page.click('div[role="dialog"] button:has-text("Delete")'); | ||
await page.waitForSelector('div[role="alert"] h3:has-text("Failed to delete 25 of 50 Tasks")'); | ||
await page.waitForSelector( | ||
'div[role="alert"] h3:has-text("Deleted 25 of 50 Tasks successfully")' | ||
); | ||
const dialogs = await page.$$('div[role="alert"] > div'); | ||
expect(dialogs.length).toBe(2); | ||
}); | ||
afterAll(async () => { | ||
await browser.close(); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters