|
| 1 | +import { click, currentURL, findAll } 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('Acceptance | rebuild docs page', function (hooks) { |
| 9 | + setupApplicationTest(hooks); |
| 10 | + |
| 11 | + test('navigates to rebuild docs confirmation page', async function (assert) { |
| 12 | + let user = this.db.user.create(); |
| 13 | + this.authenticateAs(user); |
| 14 | + |
| 15 | + let crate = this.db.crate.create({ name: 'nanomsg' }); |
| 16 | + this.db.crateOwnership.create({ crate, user }); |
| 17 | + |
| 18 | + this.db.version.create({ crate, num: '0.1.0', created_at: '2017-01-01' }); |
| 19 | + this.db.version.create({ crate, num: '0.2.0', created_at: '2018-01-01' }); |
| 20 | + this.db.version.create({ crate, num: '0.3.0', created_at: '2019-01-01', rust_version: '1.69' }); |
| 21 | + this.db.version.create({ crate, num: '0.2.1', created_at: '2020-01-01' }); |
| 22 | + |
| 23 | + await visit('/crates/nanomsg/versions'); |
| 24 | + assert.strictEqual(currentURL(), '/crates/nanomsg/versions'); |
| 25 | + |
| 26 | + let versions = findAll('[data-test-version]').map(it => it.dataset.testVersion); |
| 27 | + assert.deepEqual(versions, ['0.2.1', '0.3.0', '0.2.0', '0.1.0']); |
| 28 | + |
| 29 | + await click('[data-test-version="0.2.1"] [data-test-actions-toggle]'); |
| 30 | + await click('[data-test-version="0.2.1"] [data-test-id="btn-rebuild-docs"]'); |
| 31 | + |
| 32 | + assert.strictEqual(currentURL(), '/crates/nanomsg/0.2.1/rebuild-docs'); |
| 33 | + assert.dom('[data-test-title]').hasText('Rebuild Documentation'); |
| 34 | + }); |
| 35 | + |
| 36 | + test('rebuild docs confirmation page shows crate info and allows confirmation', async function (assert) { |
| 37 | + let user = this.db.user.create(); |
| 38 | + this.authenticateAs(user); |
| 39 | + |
| 40 | + let crate = this.db.crate.create({ name: 'nanomsg' }); |
| 41 | + this.db.crateOwnership.create({ crate, user }); |
| 42 | + |
| 43 | + this.db.version.create({ crate, num: '0.2.1', created_at: '2020-01-01' }); |
| 44 | + |
| 45 | + await visit('/crates/nanomsg/0.2.1/rebuild-docs'); |
| 46 | + assert.strictEqual(currentURL(), '/crates/nanomsg/0.2.1/rebuild-docs'); |
| 47 | + |
| 48 | + assert.dom('[data-test-title]').hasText('Rebuild Documentation'); |
| 49 | + assert.dom('[data-test-crate-name]').hasText('nanomsg'); |
| 50 | + assert.dom('[data-test-version-num]').hasText('0.2.1'); |
| 51 | + |
| 52 | + await click('[data-test-confirm-rebuild-button]'); |
| 53 | + |
| 54 | + let message = 'Docs rebuild task was enqueued successfully!'; |
| 55 | + assert.dom('[data-test-notification-message="success"]').hasText(message); |
| 56 | + assert.strictEqual(currentURL(), '/crates/nanomsg/versions'); |
| 57 | + }); |
| 58 | + |
| 59 | + test('rebuilds docs confirmation page redirects non-owners to error page', async function (assert) { |
| 60 | + let user = this.db.user.create(); |
| 61 | + this.authenticateAs(user); |
| 62 | + |
| 63 | + let crate = this.db.crate.create({ name: 'nanomsg' }); |
| 64 | + this.db.version.create({ crate, num: '0.2.1', created_at: '2020-01-01' }); |
| 65 | + |
| 66 | + await visit('/crates/nanomsg/0.2.1/rebuild-docs'); |
| 67 | + assert.dom('[data-test-title]').hasText('This page is only accessible by crate owners'); |
| 68 | + assert.dom('[data-test-go-back]').exists(); |
| 69 | + }); |
| 70 | + |
| 71 | + test('rebuild docs confirmation page shows authentication error for unauthenticated users', async function (assert) { |
| 72 | + let crate = this.db.crate.create({ name: 'nanomsg' }); |
| 73 | + this.db.version.create({ crate, num: '0.2.1', created_at: '2020-01-01' }); |
| 74 | + |
| 75 | + await visit('/crates/nanomsg/0.2.1/rebuild-docs'); |
| 76 | + |
| 77 | + // Unauthenticated users should see authentication error |
| 78 | + assert.strictEqual(currentURL(), '/crates/nanomsg/0.2.1/rebuild-docs'); |
| 79 | + assert.dom('[data-test-title]').hasText('This page requires authentication'); |
| 80 | + assert.dom('[data-test-login]').exists(); |
| 81 | + }); |
| 82 | +}); |
0 commit comments