Skip to content
This repository has been archived by the owner on Jan 8, 2024. It is now read-only.

Commit

Permalink
Add proper cancel method
Browse files Browse the repository at this point in the history
  • Loading branch information
gregone committed Aug 9, 2021
1 parent 250a7bb commit e3d5d59
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 4 deletions.
2 changes: 1 addition & 1 deletion ui/app/components/project-config-variables/list-item.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ export default class ProjectConfigVariablesListItemComponent extends Component<V
cancelCreate() {
this.isCreating = false;
this.isEditing = false;
this.deleteVariable(this.variable);
this.args.cancelCreate(this.variable);
}

@action
Expand Down
8 changes: 6 additions & 2 deletions ui/app/components/project-config-variables/list.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,12 @@
</div>
</li>
{{#each this.variablesList as |variable|}}
<ProjectConfigVariables::ListItem @variable={{variable}} @isEditing={{eq variable.name this.activeVariable.name}}
@isCreating={{this.isCreating}} @saveVariableSettings={{this.saveVariableSettings}}
<ProjectConfigVariables::ListItem
@variable={{variable}}
@isEditing={{eq variable.name this.activeVariable.name}}
@isCreating={{this.isCreating}}
@cancelCreate={{this.cancelCreate}}
@saveVariableSettings={{this.saveVariableSettings}}
@deleteVariable={{this.deleteVariable}} />
{{/each}}
</ul>
Expand Down
7 changes: 7 additions & 0 deletions ui/app/components/project-config-variables/list.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,13 @@ export default class ProjectConfigVariablesListComponent extends Component<Proje
this.isCreating = false;
}

@action
cancelCreate(variable) {
this.variablesList.splice(0, 1);
this.variablesList = [...this.variablesList];
this.isCreating = false;
}

@action
async deleteVariable(variable) {
await this.saveVariableSettings(variable, undefined, true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,46 @@ module('Integration | Component | project-config-variables-list', function (hook

test('it renders', async function (assert) {
let dbproj = await this.server.create('project', { name: 'Proj1' });
let proj = dbproj.toProtobuf().toObject();
let dbVariablesList = this.server.createList('config-variable', 10, 'random');
let varList = dbVariablesList.map(v => {
return v.toProtobuf().toObject();
});
this.set('variablesList', varList);
await render(hbs`<ProjectConfigVariables::List @variablesList={{this.variablesList}}/>`);
this.set('project', proj);
await render(
hbs`<ProjectConfigVariables::List @variablesList={{this.variablesList}} @project={{this.project}}/>`
);
assert.dom('.variables-list').exists('The list renders');
assert.equal(page.variablesList.length, 10, 'it renders: the list has the proper length');
});

test('adding and deleting variables works', async function (assert) {
let dbproj = await this.server.create('project', { name: 'Proj1' });
let proj = dbproj.toProtobuf().toObject();
let dbVariablesList = this.server.createList('config-variable', 3, 'random');
let varList = dbVariablesList.map(v => {
return v.toProtobuf().toObject();
});
this.set('variablesList', varList);
this.set('project', proj);
await render(
hbs`<ProjectConfigVariables::List @variablesList={{this.variablesList}} @project={{this.project}}/>`
);

assert.dom('.variables-list').exists('The list renders');
assert.equal(page.variablesList.length, 3, 'the list contains all variables');
await page.createButton();
assert.ok(page.hasForm, 'Attempt to create: the form appears when the Add Variable button is clicked');
await page.cancelButton();
assert.notOk(page.hasForm, 'Attempt to create: the form is hidden after canceling');
assert.equal(
page.variablesList.length,
3,
'Attempt to create: the list still has the normal count of variables after cancelling'
);
});

// test('only static variables are editable', async function (assert) {});
// test('internal variables', async function (assert) {});
// test('nameIsPath works', async function (assert) {});
Expand Down

0 comments on commit e3d5d59

Please sign in to comment.