Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions app/components/file-menu.js
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,9 @@ export default Ember.Component.extend({
fork(model) {
this.sendAction('fork', model);
},
copy() {
this.sendAction('copy');
},
deleteGist(model) {
this.attrs.deleteGist(model);
},
Expand Down
7 changes: 7 additions & 0 deletions app/gist/new/controller.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
import Ember from 'ember';

export default Ember.Controller.extend({
queryParams: ['copyCurrentTwiddle'],

copyCurrentTwiddle: false
});
16 changes: 10 additions & 6 deletions app/gist/new/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,18 @@ import GistRoute from "ember-twiddle/routes/gist-base-route";
export default GistRoute.extend({
emberCli: Ember.inject.service('ember-cli'),

model () {
this.store.unloadAll('gistFile');

model (params) {
var model = this.store.createRecord('gist', {description: 'New Twiddle'});

model.get('files').pushObject(this.get('emberCli').generate('controllers/application'));
model.get('files').pushObject(this.get('emberCli').generate('templates/application'));
model.get('files').pushObject(this.get('emberCli').generate('twiddle.json'));
if (params.copyCurrentTwiddle) {
this.store.peekAll('gistFile').setEach('gist', model);
} else {
this.store.unloadAll('gistFile');

model.get('files').pushObject(this.get('emberCli').generate('controllers/application'));
model.get('files').pushObject(this.get('emberCli').generate('templates/application'));
model.get('files').pushObject(this.get('emberCli').generate('twiddle.json'));
}

return model;
},
Expand Down
8 changes: 8 additions & 0 deletions app/gist/route.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ export default Ember.Route.extend({
}).catch(this.catchForkError.bind(this));
},

copy () {
this.transitionTo('gist.new', {
queryParams: {
copyCurrentTwiddle: true
}
});
},

signInViaGithub () {
this.session.open('github-oauth2').catch(function(error) {
alert('Could not sign you in: ' + error.message);
Expand Down
1 change: 1 addition & 0 deletions app/gist/template.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
removeFile=(action "removeFile")
saveGist="saveGist"
fork="fork"
copy="copy"
deleteGist=(action "deleteGist")
signInViaGithub="signInViaGithub"}}

Expand Down
2 changes: 2 additions & 0 deletions app/templates/components/file-menu.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@
<li><a {{action 'embed'}}>Embed Twiddle</a></li>
{{#unless belongsToUser}}
<li><a {{action 'fork' model}} class="test-fork-action">Fork Twiddle</a></li>
{{else}}
<li><a {{action 'copy'}} class="test-copy-action">Copy Twiddle</a></li>
{{/unless}}
<li><a {{action 'deleteGist' model}} class="test-delete-action">Delete Twiddle</a></li>
{{/unless}}
Expand Down
35 changes: 35 additions & 0 deletions tests/acceptance/gist-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { module, test } from 'qunit';
import startApp from 'ember-twiddle/tests/helpers/start-app';
import { findMapText } from 'ember-twiddle/tests/helpers/util';
import ErrorMessages from 'ember-twiddle/helpers/error-messages';
import { stubValidSession } from 'ember-twiddle/tests/helpers/torii';


const firstColumn = '.code:first-of-type';
Expand Down Expand Up @@ -223,3 +224,37 @@ test('unsaved indicator', function(assert) {
assert.equal(find(indicator).length, 1, "Unsaved indicator reappears after editing");
});
});

test('own gist can be copied into a new one', function(assert) {
// set owner of gist as currently logged in user
stubValidSession(this.application, {
currentUser: { login: "Gaurav0" },
"github-oauth2": {}
});

runGist([
{
filename: 'index/controller.js',
content: `import Ember from 'ember';
export default Ember.Controller.extend();`,
},
{
filename: 'index/route.js',
content: 'export default Ember.Route.extend();',
}
]);

fillIn('.title input', "my twiddle");
andThen(function() {
assert.equal(find('.title input').val(), "my twiddle");
assert.equal(find('.test-unsaved-indicator').length, 0, "No unsaved indicator shown");
});

click('.test-copy-action');

andThen(function() {
assert.equal(find('.title input').val(), "New Twiddle", "Description is reset");
assert.equal(find('.test-unsaved-indicator').length, 1, "Unsaved indicator appears when gist is copied");
assert.equal(find('.test-copy-action').length, 0, "Menu item to copy gist is not shown anymore");
});
});
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Really cool test!

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thx! But it currently misses assertions that all files have been copied correctly. Do you have any suggestions? Would it be sufficient to run the twiddle and check if the output is the same as the original one?

13 changes: 13 additions & 0 deletions tests/integration/components/file-menu-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ moduleForComponent('file-menu', 'Integration | Component | file menu', {
this.removeFileCalled = false;
this.saveGistCalled = false;
this.forkCalled = false;
this.copyCalled = false;
this.deleteGistCalled = false;
this.signInViaGithubCalled = false;

Expand Down Expand Up @@ -53,6 +54,7 @@ moduleForComponent('file-menu', 'Integration | Component | file menu', {
this.on('removeFile', (file) => { this.removeFileCalled = true; this.removedFile = file; });
this.on('saveGist', (gist) => { this.saveGistCalled = true; this.gistToSave = gist; });
this.on('fork', (gist) => { this.forkCalled = true; this.gistToFork = gist; });
this.on('copy', () => { this.copyCalled = true; });
this.on('deleteGist', (gist) => { this.deleteGistCalled = true; this.gistToDelete = gist; });
this.on('signInViaGithub', () => { this.signInViaGithubCalled = true; });

Expand All @@ -65,6 +67,7 @@ moduleForComponent('file-menu', 'Integration | Component | file menu', {
removeFile=(action "removeFile")
saveGist="saveGist"
fork="fork"
copy="copy"
deleteGist=(action "deleteGist")
signInViaGithub="signInViaGithub"}}`);
}
Expand Down Expand Up @@ -115,6 +118,16 @@ test("it calls fork on clicking 'Fork Twiddle'", function(assert) {
assert.equal(this.gistToFork, this.gist, 'fork was called with gist to fork');
});

test("it calls copy on clicking 'Copy Twiddle'", function(assert) {
assert.expect(1);

// logged in user is the same as the owner of the gist
this.set('session.currentUser.login', 'Gaurav0');
this.$('.test-copy-action').click();

assert.ok(this.copyCalled, 'copy was called');
});

test("it calls deleteGist on clicking 'Delete Twiddle'", function(assert) {
assert.expect(2);

Expand Down