|
| 1 | +import { click, currentURL, visit } from '@ember/test-helpers'; |
| 2 | +import { module, test } from 'qunit'; |
| 3 | + |
| 4 | +import { setupApplicationTest } from 'crates-io/tests/helpers'; |
| 5 | + |
| 6 | +module('Bug #11772', function (hooks) { |
| 7 | + setupApplicationTest(hooks); |
| 8 | + |
| 9 | + function prepare(context) { |
| 10 | + let { db } = context; |
| 11 | + |
| 12 | + // Create a crate that will appear in "New Crates" section |
| 13 | + let newCrate = db.crate.create({ name: 'test-crate' }); |
| 14 | + db.version.create({ crate: newCrate, num: '1.2.3' }); |
| 15 | + } |
| 16 | + |
| 17 | + test('crate versions should remain correct after navigating back from crate details', async function (assert) { |
| 18 | + prepare(this); |
| 19 | + |
| 20 | + // Visit homepage |
| 21 | + await visit('/'); |
| 22 | + assert.strictEqual(currentURL(), '/'); |
| 23 | + |
| 24 | + // Verify initial correct version displays |
| 25 | + assert.dom('[data-test-new-crates] [data-test-crate-link]').containsText('test-crate v1.2.3'); |
| 26 | + assert.dom('[data-test-just-updated] [data-test-crate-link]').containsText('test-crate v1.2.3'); |
| 27 | + |
| 28 | + // Click on a crate to navigate to its details page |
| 29 | + await click('[data-test-new-crates] [data-test-crate-link]'); |
| 30 | + |
| 31 | + // Verify we're on the crate details page |
| 32 | + assert.strictEqual(currentURL(), '/crates/test-crate'); |
| 33 | + |
| 34 | + await visit('/'); // Re-visit to simulate the back navigation |
| 35 | + |
| 36 | + // Versions should still be displayed correctly, not v0.0.0 |
| 37 | + assert.dom('[data-test-new-crates] [data-test-crate-link]').containsText('test-crate v1.2.3'); |
| 38 | + assert.dom('[data-test-just-updated] [data-test-crate-link]').containsText('test-crate v1.2.3'); |
| 39 | + }); |
| 40 | + |
| 41 | + test('crates with actual v0.0.0 versions should display correctly', async function (assert) { |
| 42 | + let { db } = this; |
| 43 | + |
| 44 | + // Create a crate with an actual v0.0.0 version |
| 45 | + let zeroCrate = db.crate.create({ name: 'test-zero-crate' }); |
| 46 | + db.version.create({ crate: zeroCrate, num: '0.0.0' }); |
| 47 | + |
| 48 | + // Visit homepage |
| 49 | + await visit('/'); |
| 50 | + assert.strictEqual(currentURL(), '/'); |
| 51 | + |
| 52 | + // Should correctly display v0.0.0 for crates that actually have that version |
| 53 | + assert.dom('[data-test-new-crates] [data-test-crate-link]').containsText('test-zero-crate v0.0.0'); |
| 54 | + |
| 55 | + // Click on the crate to navigate to its details page |
| 56 | + await click('[data-test-new-crates] [data-test-crate-link]'); |
| 57 | + |
| 58 | + // Verify we're on the crate details page |
| 59 | + assert.strictEqual(currentURL(), '/crates/test-zero-crate'); |
| 60 | + |
| 61 | + await visit('/'); // Re-visit to simulate the back navigation |
| 62 | + |
| 63 | + // Should still display v0.0.0 correctly (this is the intended behavior) |
| 64 | + assert.dom('[data-test-new-crates] [data-test-crate-link]').containsText('test-zero-crate v0.0.0'); |
| 65 | + }); |
| 66 | +}); |
0 commit comments