|
| 1 | +import { module, test } from 'qunit'; |
| 2 | +import { setupApplicationTest } from 'ember-qunit'; |
| 3 | +import { currentURL } from '@ember/test-helpers'; |
| 4 | +import window, { setupWindowMock } from 'ember-window-mock'; |
| 5 | +import { percySnapshot } from 'ember-percy'; |
| 6 | + |
| 7 | +import setupMirage from '../helpers/setup-mirage'; |
| 8 | +import { visit } from '../helpers/visit-ignoring-abort'; |
| 9 | + |
| 10 | +module('Acceptance | Dashboard', function(hooks) { |
| 11 | + setupApplicationTest(hooks); |
| 12 | + setupWindowMock(hooks); |
| 13 | + setupMirage(hooks); |
| 14 | + |
| 15 | + test('redirects to / when not logged in', async function(assert) { |
| 16 | + await visit('/dashboard'); |
| 17 | + assert.equal(currentURL(), '/'); |
| 18 | + assert.dom('[data-test-flash-message]').hasText('Please log in to proceed'); |
| 19 | + }); |
| 20 | + |
| 21 | + test('shows the dashboard when logged in', async function(assert) { |
| 22 | + window.localStorage.setItem('isLoggedIn', '1'); |
| 23 | + |
| 24 | + { |
| 25 | + let crate = this.server.create('crate', { name: 'rand' }); |
| 26 | + this.server.create('version', { crate, num: '1.0.0' }); |
| 27 | + this.server.create('version', { crate, num: '1.1.0' }); |
| 28 | + } |
| 29 | + |
| 30 | + { |
| 31 | + let crate = this.server.create('crate', { name: 'nanomsg', _owner_users: [42] }); |
| 32 | + this.server.create('version', { crate, num: '0.1.0' }); |
| 33 | + } |
| 34 | + |
| 35 | + this.server.get('/api/v1/me', { |
| 36 | + user: { |
| 37 | + id: 42, |
| 38 | + login: 'johnnydee', |
| 39 | + email_verified: true, |
| 40 | + email_verification_sent: true, |
| 41 | + name: 'John Doe', |
| 42 | + |
| 43 | + avatar: 'https://avatars2.githubusercontent.com/u/1234567?v=4', |
| 44 | + url: 'https://github.com/johnnydee', |
| 45 | + }, |
| 46 | + owned_crates: [ |
| 47 | + { id: 123, name: 'foo-bar', email_notifications: true }, |
| 48 | + { id: 56456, name: 'barrrrr', email_notifications: false }, |
| 49 | + ], |
| 50 | + }); |
| 51 | + |
| 52 | + this.server.get('/api/v1/me/updates', { |
| 53 | + versions: [ |
| 54 | + { |
| 55 | + id: 152946, |
| 56 | + crate: 'geo', |
| 57 | + num: '0.12.2', |
| 58 | + dl_path: '/api/v1/crates/geo/0.12.2/download', |
| 59 | + readme_path: '/api/v1/crates/geo/0.12.2/readme', |
| 60 | + updated_at: '2019-05-26T14:47:10.220868+00:00', |
| 61 | + created_at: '2019-05-26T14:47:10.220868+00:00', |
| 62 | + downloads: 19372, |
| 63 | + features: { |
| 64 | + default: [], |
| 65 | + 'postgis-integration': ['postgis'], |
| 66 | + 'use-proj': ['proj'], |
| 67 | + 'use-serde': ['serde', 'geo-types/serde'], |
| 68 | + }, |
| 69 | + yanked: false, |
| 70 | + license: 'MIT/Apache-2.0', |
| 71 | + links: { |
| 72 | + dependencies: '/api/v1/crates/geo/0.12.2/dependencies', |
| 73 | + version_downloads: '/api/v1/crates/geo/0.12.2/downloads', |
| 74 | + authors: '/api/v1/crates/geo/0.12.2/authors', |
| 75 | + }, |
| 76 | + crate_size: 179841, |
| 77 | + published_by: { |
| 78 | + id: 227, |
| 79 | + login: 'frewsxcv', |
| 80 | + name: 'Corey Farwell', |
| 81 | + avatar: 'https://avatars2.githubusercontent.com/u/416575?v=4', |
| 82 | + url: 'https://github.com/frewsxcv', |
| 83 | + }, |
| 84 | + audit_actions: [], |
| 85 | + }, |
| 86 | + { |
| 87 | + id: 143262, |
| 88 | + crate: 'geo', |
| 89 | + num: '0.12.1', |
| 90 | + dl_path: '/api/v1/crates/geo/0.12.1/download', |
| 91 | + readme_path: '/api/v1/crates/geo/0.12.1/readme', |
| 92 | + updated_at: '2019-04-05T09:00:59.629392+00:00', |
| 93 | + created_at: '2019-04-05T09:00:59.629392+00:00', |
| 94 | + downloads: 2940, |
| 95 | + features: { |
| 96 | + default: [], |
| 97 | + 'postgis-integration': ['postgis'], |
| 98 | + 'use-proj': ['proj'], |
| 99 | + 'use-serde': ['serde', 'geo-types/serde'], |
| 100 | + }, |
| 101 | + yanked: false, |
| 102 | + license: 'MIT/Apache-2.0', |
| 103 | + links: { |
| 104 | + dependencies: '/api/v1/crates/geo/0.12.1/dependencies', |
| 105 | + version_downloads: '/api/v1/crates/geo/0.12.1/downloads', |
| 106 | + authors: '/api/v1/crates/geo/0.12.1/authors', |
| 107 | + }, |
| 108 | + crate_size: 179259, |
| 109 | + published_by: { |
| 110 | + id: 227, |
| 111 | + login: 'frewsxcv', |
| 112 | + name: 'Corey Farwell', |
| 113 | + avatar: 'https://avatars2.githubusercontent.com/u/416575?v=4', |
| 114 | + url: 'https://github.com/frewsxcv', |
| 115 | + }, |
| 116 | + audit_actions: [], |
| 117 | + }, |
| 118 | + { |
| 119 | + id: 134231, |
| 120 | + crate: 'geo', |
| 121 | + num: '0.12.0', |
| 122 | + dl_path: '/api/v1/crates/geo/0.12.0/download', |
| 123 | + readme_path: '/api/v1/crates/geo/0.12.0/readme', |
| 124 | + updated_at: '2019-02-17T03:19:08.118477+00:00', |
| 125 | + created_at: '2019-02-17T03:19:08.118477+00:00', |
| 126 | + downloads: 4420, |
| 127 | + features: { |
| 128 | + default: [], |
| 129 | + 'postgis-integration': ['postgis'], |
| 130 | + 'use-proj': ['proj'], |
| 131 | + 'use-serde': ['serde', 'geo-types/serde'], |
| 132 | + }, |
| 133 | + yanked: false, |
| 134 | + license: 'MIT/Apache-2.0', |
| 135 | + links: { |
| 136 | + dependencies: '/api/v1/crates/geo/0.12.0/dependencies', |
| 137 | + version_downloads: '/api/v1/crates/geo/0.12.0/downloads', |
| 138 | + authors: '/api/v1/crates/geo/0.12.0/authors', |
| 139 | + }, |
| 140 | + crate_size: 178368, |
| 141 | + published_by: null, |
| 142 | + audit_actions: [], |
| 143 | + }, |
| 144 | + ], |
| 145 | + meta: { more: true }, |
| 146 | + }); |
| 147 | + |
| 148 | + this.server.get('/api/v1/users/42/stats', { total_downloads: 3892 }); |
| 149 | + |
| 150 | + await visit('/dashboard'); |
| 151 | + assert.equal(currentURL(), '/dashboard'); |
| 152 | + percySnapshot(assert); |
| 153 | + }); |
| 154 | +}); |
0 commit comments