Skip to content

Commit 41d0787

Browse files
authored
components/crate-sidebar: Remove build metadata within the toml snippet (#8082)
1 parent 87c3fce commit 41d0787

File tree

2 files changed

+39
-1
lines changed

2 files changed

+39
-1
lines changed

app/components/crate-sidebar.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@ export default class CrateSidebar extends Component {
2121
}
2222

2323
get tomlSnippet() {
24-
return `${this.args.crate.name} = "${this.args.version.num}"`;
24+
let version = this.args.version.num.split('+')[0];
25+
return `${this.args.crate.name} = "${version}"`;
2526
}
2627

2728
get playgroundLink() {
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import { render } from '@ember/test-helpers';
2+
import { module, test } from 'qunit';
3+
4+
import { hbs } from 'ember-cli-htmlbars';
5+
6+
import { setupRenderingTest } from 'crates-io/tests/helpers';
7+
8+
import setupMirage from '../../helpers/setup-mirage';
9+
10+
module('Component | CrateSidebar | toml snippet', function (hooks) {
11+
setupRenderingTest(hooks);
12+
setupMirage(hooks);
13+
14+
test('show version number without build metadata', async function (assert) {
15+
let crate = this.server.create('crate', { name: 'foo' });
16+
this.server.create('version', { crate, num: '1.0.0+abcdef' });
17+
18+
let store = this.owner.lookup('service:store');
19+
this.crate = await store.findRecord('crate', crate.name);
20+
this.version = (await this.crate.versions).firstObject;
21+
22+
await render(hbs`<CrateSidebar @crate={{this.crate}} @version={{this.version}} />`);
23+
assert.dom('[title="Copy Cargo.toml snippet to clipboard"]').exists().hasText('foo = "1.0.0"');
24+
});
25+
26+
test('show pre-release version number without build', async function (assert) {
27+
let crate = this.server.create('crate', { name: 'foo' });
28+
this.server.create('version', { crate, num: '1.0.0-alpha+abcdef' });
29+
30+
let store = this.owner.lookup('service:store');
31+
this.crate = await store.findRecord('crate', crate.name);
32+
this.version = (await this.crate.versions).firstObject;
33+
34+
await render(hbs`<CrateSidebar @crate={{this.crate}} @version={{this.version}} />`);
35+
assert.dom('[title="Copy Cargo.toml snippet to clipboard"]').exists().hasText('foo = "1.0.0-alpha"');
36+
});
37+
});

0 commit comments

Comments
 (0)