From d5a9d57dbfb68107c0e4e13d303f9c6c22a8014c Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Wed, 13 Jan 2021 19:08:30 +0100 Subject: [PATCH 1/2] CrateRow: Add basic rendering tests --- app/components/crate-row.hbs | 1 + tests/components/crate-row-test.js | 42 ++++++++++++++++++++++++++++++ 2 files changed, 43 insertions(+) create mode 100644 tests/components/crate-row-test.js diff --git a/app/components/crate-row.hbs b/app/components/crate-row.hbs index 19dfb0173f9..8c05e8ff1dd 100644 --- a/app/components/crate-row.hbs +++ b/app/components/crate-row.hbs @@ -11,6 +11,7 @@ @copyText='{{@crate.name}} = "{{@crate.max_version}}"' title="Copy Cargo.toml snippet to clipboard" local-class="copy-button" + data-test-copy-toml-button > {{svg-jar "copy" alt="Copy Cargo.toml snippet to clipboard"}} diff --git a/tests/components/crate-row-test.js b/tests/components/crate-row-test.js new file mode 100644 index 00000000000..ea2bcde4dd7 --- /dev/null +++ b/tests/components/crate-row-test.js @@ -0,0 +1,42 @@ +import { render } from '@ember/test-helpers'; +import { setupRenderingTest } from 'ember-qunit'; +import { module, test } from 'qunit'; + +import { hbs } from 'ember-cli-htmlbars'; + +import setupMirage from '../helpers/setup-mirage'; + +module('Component | CrateRow', function (hooks) { + setupRenderingTest(hooks); + setupMirage(hooks); + + test('shows crate name and highest version', async function (assert) { + let crate = this.server.create('crate', { name: 'foo' }); + this.server.create('version', { crate, num: '1.0.0' }); + this.server.create('version', { crate, num: '1.2.3', yanked: true }); + this.server.create('version', { crate, num: '2.0.0-beta.1' }); + this.server.create('version', { crate, num: '1.1.2' }); + + let store = this.owner.lookup('service:store'); + this.crate = await store.findRecord('crate', crate.name); + + await render(hbs``); + assert.dom('[data-test-crate-link]').hasText('foo'); + assert.dom('[data-test-version]').hasText('v2.0.0-beta.1'); + assert.dom('[data-test-copy-toml-button]').exists(); + }); + + test('shows crate name and `0.0.0` version if all versions are yanked', async function (assert) { + let crate = this.server.create('crate', { name: 'foo' }); + this.server.create('version', { crate, num: '1.0.0', yanked: true }); + this.server.create('version', { crate, num: '1.2.3', yanked: true }); + + let store = this.owner.lookup('service:store'); + this.crate = await store.findRecord('crate', crate.name); + + await render(hbs``); + assert.dom('[data-test-crate-link]').hasText('foo'); + assert.dom('[data-test-version]').hasText('v0.0.0'); + assert.dom('[data-test-copy-toml-button]').exists(); + }); +}); From 86949fe1ce7c614fab02214dd3f9fbc05b673ff5 Mon Sep 17 00:00:00 2001 From: Tobias Bieniek Date: Wed, 13 Jan 2021 19:10:37 +0100 Subject: [PATCH 2/2] CrateRow: Display `defaultVersion` instead of `max_version` ... and hide the version if all versions are yanked --- app/components/crate-row.hbs | 20 +++++++++++--------- tests/components/crate-row-test.js | 25 ++++++++++++++++++++----- 2 files changed, 31 insertions(+), 14 deletions(-) diff --git a/app/components/crate-row.hbs b/app/components/crate-row.hbs index 8c05e8ff1dd..33673898a1d 100644 --- a/app/components/crate-row.hbs +++ b/app/components/crate-row.hbs @@ -6,15 +6,17 @@ {{@crate.name}} {{/let}} - v{{@crate.max_version}} - - {{svg-jar "copy" alt="Copy Cargo.toml snippet to clipboard"}} - + {{#if @crate.defaultVersion}} + v{{@crate.defaultVersion}} + + {{svg-jar "copy" alt="Copy Cargo.toml snippet to clipboard"}} + + {{/if}}
{{ truncate-text @crate.description }} diff --git a/tests/components/crate-row-test.js b/tests/components/crate-row-test.js index ea2bcde4dd7..29bf448974b 100644 --- a/tests/components/crate-row-test.js +++ b/tests/components/crate-row-test.js @@ -10,7 +10,7 @@ module('Component | CrateRow', function (hooks) { setupRenderingTest(hooks); setupMirage(hooks); - test('shows crate name and highest version', async function (assert) { + test('shows crate name and highest stable version', async function (assert) { let crate = this.server.create('crate', { name: 'foo' }); this.server.create('version', { crate, num: '1.0.0' }); this.server.create('version', { crate, num: '1.2.3', yanked: true }); @@ -22,11 +22,26 @@ module('Component | CrateRow', function (hooks) { await render(hbs``); assert.dom('[data-test-crate-link]').hasText('foo'); - assert.dom('[data-test-version]').hasText('v2.0.0-beta.1'); + assert.dom('[data-test-version]').hasText('v1.1.2'); assert.dom('[data-test-copy-toml-button]').exists(); }); - test('shows crate name and `0.0.0` version if all versions are yanked', async function (assert) { + test('shows crate name and highest version, if there is no stable version available', async function (assert) { + let crate = this.server.create('crate', { name: 'foo' }); + this.server.create('version', { crate, num: '1.0.0-beta.1' }); + this.server.create('version', { crate, num: '1.0.0-beta.3' }); + this.server.create('version', { crate, num: '1.0.0-beta.2' }); + + let store = this.owner.lookup('service:store'); + this.crate = await store.findRecord('crate', crate.name); + + await render(hbs``); + assert.dom('[data-test-crate-link]').hasText('foo'); + assert.dom('[data-test-version]').hasText('v1.0.0-beta.3'); + assert.dom('[data-test-copy-toml-button]').exists(); + }); + + test('shows crate name and no version if all versions are yanked', async function (assert) { let crate = this.server.create('crate', { name: 'foo' }); this.server.create('version', { crate, num: '1.0.0', yanked: true }); this.server.create('version', { crate, num: '1.2.3', yanked: true }); @@ -36,7 +51,7 @@ module('Component | CrateRow', function (hooks) { await render(hbs``); assert.dom('[data-test-crate-link]').hasText('foo'); - assert.dom('[data-test-version]').hasText('v0.0.0'); - assert.dom('[data-test-copy-toml-button]').exists(); + assert.dom('[data-test-version]').doesNotExist(); + assert.dom('[data-test-copy-toml-button]').doesNotExist(); }); });