|
1 | 1 | import { expect, test } from '@/e2e/helper'; |
| 2 | +import { click } from '@ember/test-helpers'; |
| 3 | +import { http, HttpResponse } from 'msw'; |
2 | 4 |
|
3 | 5 | test.describe('Route | crate.settings', { tag: '@routes' }, () => { |
4 | 6 | async function prepare(msw) { |
@@ -90,12 +92,55 @@ test.describe('Route | crate.settings', { tag: '@routes' }, () => { |
90 | 92 | await expect(details).toContainText('Repository: rust-lang/crates.io'); |
91 | 93 | await expect(details).toContainText('Workflow: ci.yml'); |
92 | 94 | await expect(details).not.toContainText('Environment'); |
| 95 | + await expect(page.locator('[data-test-github-config="1"] [data-test-remove-config-button]')).toBeVisible(); |
93 | 96 | await expect(page.locator('[data-test-github-config="2"] td:nth-child(1)')).toHaveText('GitHub'); |
94 | 97 | details = page.locator('[data-test-github-config="2"] td:nth-child(2)'); |
95 | 98 | await expect(details).toContainText('Repository: johndoe/crates.io'); |
96 | 99 | await expect(details).toContainText('Workflow: release.yml'); |
97 | 100 | await expect(details).toContainText('Environment: release'); |
| 101 | + await expect(page.locator('[data-test-github-config="2"] [data-test-remove-config-button]')).toBeVisible(); |
98 | 102 | await expect(page.locator('[data-test-no-config]')).not.toBeVisible(); |
| 103 | + |
| 104 | + // Click the remove button |
| 105 | + await page.click('[data-test-github-config="2"] [data-test-remove-config-button]'); |
| 106 | + |
| 107 | + // Check that the config is no longer displayed |
| 108 | + await expect(page.locator('[data-test-github-config]')).toHaveCount(1); |
| 109 | + details = page.locator('[data-test-github-config="1"] td:nth-child(2)'); |
| 110 | + await expect(details).toContainText('Repository: rust-lang/crates.io'); |
| 111 | + await expect(page.locator('[data-test-notification-message]')).toHaveText( |
| 112 | + 'Trusted Publishing configuration removed successfully', |
| 113 | + ); |
| 114 | + }); |
| 115 | + |
| 116 | + test('deletion failure', async ({ msw, page, percy }) => { |
| 117 | + let { crate } = await prepare(msw); |
| 118 | + |
| 119 | + // Create a GitHub config for the crate |
| 120 | + let config = msw.db.trustpubGithubConfig.create({ |
| 121 | + crate, |
| 122 | + repository_owner: 'rust-lang', |
| 123 | + repository_name: 'crates.io', |
| 124 | + workflow_filename: 'ci.yml', |
| 125 | + environment: 'release', |
| 126 | + }); |
| 127 | + |
| 128 | + // Mock the server to return an error when trying to delete the config |
| 129 | + await msw.worker.use( |
| 130 | + http.delete(`/api/v1/trusted_publishing/github_configs/${config.id}`, () => { |
| 131 | + return HttpResponse.json({ errors: [{ detail: 'Server error' }] }, { status: 500 }); |
| 132 | + }), |
| 133 | + ); |
| 134 | + |
| 135 | + await page.goto(`/crates/${crate.name}/settings`); |
| 136 | + await expect(page).toHaveURL(`/crates/${crate.name}/settings`); |
| 137 | + await expect(page.locator('[data-test-github-config]')).toHaveCount(1); |
| 138 | + |
| 139 | + await page.click('[data-test-remove-config-button]'); |
| 140 | + await expect(page.locator('[data-test-github-config]')).toHaveCount(1); |
| 141 | + await expect(page.locator('[data-test-notification-message]')).toHaveText( |
| 142 | + 'Failed to remove Trusted Publishing configuration: Server error', |
| 143 | + ); |
99 | 144 | }); |
100 | 145 | }); |
101 | 146 | }); |
0 commit comments