|
| 1 | +import { expect, test } from '@/e2e/helper'; |
| 2 | + |
| 3 | +test.describe('Acceptance | publish notifications', { tag: '@acceptance' }, () => { |
| 4 | + test('unsubscribe and resubscribe', async ({ page, mirage }) => { |
| 5 | + await mirage.addHook(server => { |
| 6 | + let user = server.create('user'); |
| 7 | + globalThis.user = user; |
| 8 | + authenticateAs(user); |
| 9 | + }); |
| 10 | + |
| 11 | + await page.goto('/settings/profile'); |
| 12 | + await expect(page).toHaveURL('/settings/profile'); |
| 13 | + await expect(page.locator('[data-test-notifications] input[type=checkbox]')).toBeChecked(); |
| 14 | + |
| 15 | + await page.click('[data-test-notifications] input[type=checkbox]'); |
| 16 | + await expect(page.locator('[data-test-notifications] input[type=checkbox]')).not.toBeChecked(); |
| 17 | + |
| 18 | + await page.click('[data-test-notifications] button'); |
| 19 | + await page.waitForFunction(() => globalThis.user.reload().publishNotifications === false); |
| 20 | + |
| 21 | + await page.click('[data-test-notifications] input[type=checkbox]'); |
| 22 | + await expect(page.locator('[data-test-notifications] input[type=checkbox]')).toBeChecked(); |
| 23 | + |
| 24 | + await page.click('[data-test-notifications] button'); |
| 25 | + await page.waitForFunction(() => globalThis.user.reload().publishNotifications === true); |
| 26 | + }); |
| 27 | + |
| 28 | + test('loading state', async ({ page, mirage }) => { |
| 29 | + await mirage.addHook(server => { |
| 30 | + let user = server.create('user'); |
| 31 | + authenticateAs(user); |
| 32 | + globalThis.user = user; |
| 33 | + |
| 34 | + globalThis.deferred = require('rsvp').defer(); |
| 35 | + server.put('/api/v1/users/:user_id', globalThis.deferred.promise); |
| 36 | + }); |
| 37 | + |
| 38 | + await page.goto('/settings/profile'); |
| 39 | + await expect(page).toHaveURL('/settings/profile'); |
| 40 | + |
| 41 | + await page.click('[data-test-notifications] input[type=checkbox]'); |
| 42 | + await page.click('[data-test-notifications] button'); |
| 43 | + await expect(page.locator('[data-test-notifications] [data-test-spinner]')).toBeVisible(); |
| 44 | + await expect(page.locator('[data-test-notifications] input[type=checkbox]')).toBeDisabled(); |
| 45 | + await expect(page.locator('[data-test-notifications] button')).toBeDisabled(); |
| 46 | + |
| 47 | + await page.evaluate(async () => globalThis.deferred.resolve()); |
| 48 | + await expect(page.locator('[data-test-notifications] [data-test-spinner]')).not.toBeVisible(); |
| 49 | + await expect(page.locator('[data-test-notification-message="error"]')).not.toBeVisible(); |
| 50 | + }); |
| 51 | + |
| 52 | + test('error state', async ({ page, mirage }) => { |
| 53 | + await mirage.addHook(server => { |
| 54 | + server.logging = true; |
| 55 | + let user = server.create('user'); |
| 56 | + authenticateAs(user); |
| 57 | + globalThis.user = user; |
| 58 | + |
| 59 | + server.put('/api/v1/users/:user_id', '', 500); |
| 60 | + }); |
| 61 | + |
| 62 | + await page.goto('/settings/profile'); |
| 63 | + await expect(page).toHaveURL('/settings/profile'); |
| 64 | + |
| 65 | + await page.click('[data-test-notifications] input[type=checkbox]'); |
| 66 | + await page.click('[data-test-notifications] button'); |
| 67 | + await expect(page.locator('[data-test-notifications] [data-test-spinner]')).not.toBeVisible(); |
| 68 | + await expect(page.locator('[data-test-notification-message="error"]')).toHaveText( |
| 69 | + 'Something went wrong while updating your notification settings. Please try again later!', |
| 70 | + ); |
| 71 | + }); |
| 72 | +}); |
0 commit comments