Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Léo-Paul Géneau
gitlab-ce
Commits
b1ec3cb8
Commit
b1ec3cb8
authored
Oct 26, 2016
by
Filipa Lacerda
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Adds tests for environment store.
parent
dcafd476
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
56 additions
and
90 deletions
+56
-90
app/assets/javascripts/environments/stores/environmnets_store.js.es6
...javascripts/environments/stores/environmnets_store.js.es6
+6
-8
spec/javascripts/environments/environments_store_spec.js.es6
spec/javascripts/environments/environments_store_spec.js.es6
+44
-7
spec/javascripts/environments/mock_data.js.es6
spec/javascripts/environments/mock_data.js.es6
+6
-75
No files found.
app/assets/javascripts/environments/stores/environmnets_store.js.es6
View file @
b1ec3cb8
...
...
@@ -54,7 +54,7 @@
//humanizes actions names if there are any actions
if (environment.last_deployment.manual_actions) {
environment.last_deployment.manual_actions = environment.last_deployment.manual_actions.map((action) =>
Object.assign({}, action, {name: gl.text.humanize(action.name)}
));
environment.last_deployment.manual_actions = environment.last_deployment.manual_actions.map((action) =>
action.name = gl.text.humanize(action.name
));
}
//transforms created date for deployment in a human readable format
...
...
@@ -64,21 +64,19 @@
}
if (environment.environment_type !== null) {
const occurs = acc.fi
nd
((element, index, array) => {
const occurs = acc.fi
lter
((element, index, array) => {
return element.children && element.name === environment.environment_type;
});
environment["vue-isChildren"] = true;
if (occurs
!== undefined
) {
acc[acc.indexOf(occurs)].children.push(environment);
acc[acc.indexOf(occurs)].children.sort(this.sortByName)
if (occurs
.length
) {
acc[acc.indexOf(occurs
[0]
)].children.push(environment);
acc[acc.indexOf(occurs
[0]
)].children.sort(this.sortByName)
} else {
acc.push({
name: environment.environment_type,
children: [
Object.assign(environment)
]
children: [environment]
});
}
} else {
...
...
spec/javascripts/environments/environments_store_spec.js.es6
View file @
b1ec3cb8
//= require vue
//= require vue-resource
//= require lib/utils/url_utility
//= require environments/services/environments_service
//= require environments/stores/environments_store
//= require environments/stores/environmnets_store
//= require ./mock_data
//
(() => {
beforeEach(() => {
gl.environmentsService = new EnvironmentsService('test/environments');
gl.environmentsList.EnvironmentsStore.create();
});
describe('Store', () => {
it('s
tarts
with a blank state', () => {
it('s
hould start
with a blank state', () => {
expect(gl.environmentsList.EnvironmentsStore.state.environments.length).toBe(0);
expect(gl.environmentsList.EnvironmentsStore.state.stoppedCounter).toBe(0);
expect(gl.environmentsList.EnvironmentsStore.state.availableCounter).toBe(0)
});
describe('store environments', () => {
beforeEach(() => {
gl.environmentsList.EnvironmentsStore.storeEnvironments(environmentsList);
});
it('should count stopped environments and save the count in the state', () => {
expect(gl.environmentsList.EnvironmentsStore.state.stoppedCounter).toBe(1);
});
it('should count available environments and save the count in the state', () => {
expect(gl.environmentsList.EnvironmentsStore.state.availableCounter).toBe(2);
});
it('should store environments with same environment_type as sibilings', () => {
expect(gl.environmentsList.EnvironmentsStore.state.environments.length).toBe(2);
const parentFolder = gl.environmentsList.EnvironmentsStore.state.environments.filter((env) => {
return env.children && env.children.length > 0;
});
expect(parentFolder[0].children.length).toBe(2);
expect(parentFolder[0].children[0].environment_type).toBe('review');
expect(parentFolder[0].children[1].environment_type).toBe('review');
expect(parentFolder[0].children[0].name).toBe('review/test-environment')
expect(parentFolder[0].children[1].name).toBe('review/test-environment-1');
});
it('should sort the environments alphabetically', () => {
const { environments } = gl.environmentsList.EnvironmentsStore.state;
expect(environments[0].name).toBe('production');
expect(environments[1].children[0].name).toBe('review/test-environment');
expect(environments[1].children[1].name).toBe('review/test-environment-1');
});
});
});
})();
spec/javascripts/environments/mock_data.js.es6
View file @
b1ec3cb8
...
...
@@ -3,93 +3,24 @@ const environmentsList = [
"id": 15,
"project_id": 11,
"name": "production",
"created_at": "2016-10-18T10:47:46.840Z",
"updated_at": "2016-10-19T15:49:24.378Z",
"external_url": "https://test.com",
"environment_type": null,
"state": "available",
"last_deployment": {
"id": 57,
"iid": 5,
"project_id": 11,
"environment_id": 15,
"ref": "master",
"tag": false,
"sha": "edf8704ba6cea79be4634b82927e9ff534068428",
"user_id": 1,
"deployable_id": 1170,
"deployable_type": "CommitStatus",
"on_stop": null,
"short_sha": "edf8704b",
"commit_title": "Update .gitlab-ci.yml",
"commit": {
"id": "edf8704ba6cea79be4634b82927e9ff534068428",
"message": "Update .gitlab-ci.yml",
"parent_ids": ["f215999006bd3d5c89b9b1e8c0873c9aca0f913a"],
"authored_date": "2016-10-19T16:49:09.000+01:00",
"author_name": "Administrator",
"author_email": "admin@example.com",
"committed_date": "2016-10-19T16:49:09.000+01:00",
"committer_name": "Administrator",
"committer_email": "admin@example.com"
},
"user": {
"id": 1,
"name": "Administrator",
"username": "root",
"avatar_url": "http://www.gravatar.com/avatar/e64c7d89f26bd1972efa854d13d7dd61?s=80\u0026d=identicon"
},
"deployable": {
"id": 1170,
"name": "deploy",
"tag": false,
"ref": "master"
}
},
"project": {
"id": 11,
"name": "review-apps",
"path": "review-apps",
"namespace_id": 1,
"namespace": {
"id": 1,
"name": "root"
}
}
},{
"state": "available"
},
{
"id": 18,
"project_id": 11,
"name": "review/test-environment",
"created_at": "2016-10-19T14:59:59.303Z",
"updated_at": "2016-10-19T14:59:59.303Z",
"external_url": "http://test1.com",
"environment_type": "review",
"state": "available",
"project": {
"id": 11,
"name": "review-apps",
"namespace": {
"id": 1,
"name": "root"
}
}
"state": "available"
},
{
"id": 1
8
,
"id": 1
9
,
"project_id": 11,
"name": "review/test-environment-1",
"created_at": "2016-10-19T14:59:59.303Z",
"updated_at": "2016-10-19T14:59:59.303Z",
"external_url": "http://test-1.com",
"environment_type": "review",
"state": "stopped",
"project": {
"id": 11,
"name": "review-apps",
"namespace": {
"id": 1,
"name": "root"
}
}
"state": "stopped"
}
];
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment