|
| 1 | +import { currentURL } from '@ember/test-helpers'; |
| 2 | +import { module, test } from 'qunit'; |
| 3 | + |
| 4 | +import { setupApplicationTest } from 'crates-io/tests/helpers'; |
| 5 | + |
| 6 | +import { visit } from '../../helpers/visit-ignoring-abort'; |
| 7 | + |
| 8 | +module('Route | crate.settings', hooks => { |
| 9 | + setupApplicationTest(hooks, { msw: true }); |
| 10 | + |
| 11 | + function prepare(context) { |
| 12 | + const user = context.db.user.create(); |
| 13 | + |
| 14 | + const crate = context.db.crate.create({ name: 'foo' }); |
| 15 | + context.db.version.create({ crate }); |
| 16 | + context.db.crateOwnership.create({ crate, user }); |
| 17 | + |
| 18 | + return { crate, user }; |
| 19 | + } |
| 20 | + |
| 21 | + test('unauthenticated', async function (assert) { |
| 22 | + const crate = this.db.crate.create({ name: 'foo' }); |
| 23 | + this.db.version.create({ crate }); |
| 24 | + |
| 25 | + await visit('/crates/foo/settings'); |
| 26 | + assert.strictEqual(currentURL(), '/crates/foo/settings'); |
| 27 | + assert.dom('[data-test-title]').hasText('This page requires authentication'); |
| 28 | + assert.dom('[data-test-login]').exists(); |
| 29 | + }); |
| 30 | + |
| 31 | + test('not an owner', async function (assert) { |
| 32 | + const { crate } = prepare(this); |
| 33 | + |
| 34 | + const otherUser = this.db.user.create(); |
| 35 | + this.authenticateAs(otherUser); |
| 36 | + |
| 37 | + await visit(`/crates/${crate.name}/settings`); |
| 38 | + assert.strictEqual(currentURL(), `/crates/${crate.name}/settings`); |
| 39 | + assert.dom('[data-test-title]').hasText('This page is only accessible by crate owners'); |
| 40 | + assert.dom('[data-test-go-back]').exists(); |
| 41 | + }); |
| 42 | + |
| 43 | + test('happy path', async function (assert) { |
| 44 | + const { crate, user } = prepare(this); |
| 45 | + this.authenticateAs(user); |
| 46 | + |
| 47 | + await visit(`/crates/${crate.name}/settings`); |
| 48 | + assert.strictEqual(currentURL(), `/crates/${crate.name}/settings`); |
| 49 | + // This is the Add Owner button. |
| 50 | + assert.dom('[data-test-save-button]').exists(); |
| 51 | + assert.dom('[data-test-owners]').exists(); |
| 52 | + assert.dom(`[data-test-owner-user="${user.login}"]`).exists(); |
| 53 | + assert.dom('[data-test-remove-owner-button]').exists(); |
| 54 | + assert.dom('[data-test-delete-button]').exists(); |
| 55 | + }); |
| 56 | +}); |
0 commit comments