-
Notifications
You must be signed in to change notification settings - Fork 2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
UI: Collapsable job summary visualization #4504
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,17 @@ | ||
import Component from '@ember/component'; | ||
import { inject as service } from '@ember/service'; | ||
import { alias } from '@ember/object/computed'; | ||
import { computed } from '@ember/object'; | ||
|
||
export default Component.extend({ | ||
store: service(), | ||
|
||
job: null, | ||
classNames: ['boxed-section'], | ||
|
||
summary: alias('job.summary'), | ||
isExpanded: computed(function() { | ||
const storageValue = window.localStorage.nomadExpandJobSummary; | ||
return storageValue != null ? JSON.parse(storageValue) : true; | ||
}), | ||
|
||
classNames: ['boxed-section'], | ||
persist(item, isOpen) { | ||
window.localStorage.nomadExpandJobSummary = isOpen; | ||
this.notifyPropertyChange('isExpanded'); | ||
}, | ||
}); |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
|
||
.accordion-head-content { | ||
width: 100%; | ||
margin-right: 1.5em; | ||
} | ||
|
||
.accordion-toggle { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { getOwner } from '@ember/application'; | ||
import hbs from 'htmlbars-inline-precompile'; | ||
import wait from 'ember-test-helpers/wait'; | ||
import { find } from 'ember-native-dom-helpers'; | ||
import { find, click } from 'ember-native-dom-helpers'; | ||
import { test, moduleForComponent } from 'ember-qunit'; | ||
import { startMirage } from 'nomad-ui/initializers/ember-cli-mirage'; | ||
import { initialize as fragmentSerializerInitializer } from 'nomad-ui/initializers/fragment-serializer'; | ||
|
@@ -152,3 +152,130 @@ test('the children diagram lists all children status figures', function(assert) | |
}); | ||
}); | ||
}); | ||
|
||
test('the summary block can be collapsed', function(assert) { | ||
this.server.create('job', { | ||
createAllocations: false, | ||
}); | ||
|
||
this.store.findAll('job'); | ||
|
||
return wait() | ||
.then(() => { | ||
this.set('job', this.store.peekAll('job').get('firstObject')); | ||
|
||
this.render(hbs` | ||
{{job-page/parts/summary job=job}} | ||
`); | ||
|
||
return wait(); | ||
}) | ||
.then(() => { | ||
click('[data-test-accordion-toggle]'); | ||
return wait(); | ||
}) | ||
.then(() => { | ||
assert.notOk(find('[data-test-accordion-body]'), 'No accordion body'); | ||
assert.notOk(find('[data-test-legend]'), 'No legend'); | ||
}); | ||
}); | ||
|
||
test('when collapsed, the summary block includes an inline version of the chart', function(assert) { | ||
this.server.create('job', { | ||
createAllocations: false, | ||
}); | ||
|
||
this.store.findAll('job'); | ||
|
||
return wait() | ||
.then(() => { | ||
this.set('job', this.store.peekAll('job').get('firstObject')); | ||
|
||
this.render(hbs` | ||
{{job-page/parts/summary job=job}} | ||
`); | ||
|
||
return wait(); | ||
}) | ||
.then(() => { | ||
click('[data-test-accordion-toggle]'); | ||
return wait(); | ||
}) | ||
.then(() => { | ||
assert.ok(find('[data-test-allocation-status-bar]'), 'Allocation bar still existed'); | ||
assert.ok( | ||
find('.inline-chart [data-test-allocation-status-bar]'), | ||
'Allocation bar is rendered in an inline-chart container' | ||
); | ||
}); | ||
}); | ||
|
||
test('the collapsed/expanded state is persisted to localStorage', function(assert) { | ||
this.server.create('job', { | ||
createAllocations: false, | ||
}); | ||
|
||
this.store.findAll('job'); | ||
|
||
return wait() | ||
.then(() => { | ||
this.set('job', this.store.peekAll('job').get('firstObject')); | ||
|
||
this.render(hbs` | ||
{{job-page/parts/summary job=job}} | ||
`); | ||
|
||
return wait(); | ||
}) | ||
.then(() => { | ||
assert.notOk(window.localStorage.nomadExpandJobSummary, 'No value in localStorage yet'); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think this is going to result in flaky tests due to localStorage state retention. We initially worked around this in TFE by wiping localStorage in our There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I clear I'll look into ember-window-mock though. It's good to be consistent across codebases. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just my 2 cents here, I'd use mocking in unit or integration tests, but if its not complicated to use the real thing in an acceptance test then I would. All browsers have localStorage so I'd say ideally it'd be used during acceptance - just my take. |
||
click('[data-test-accordion-toggle]'); | ||
return wait(); | ||
}) | ||
.then(() => { | ||
assert.equal( | ||
window.localStorage.nomadExpandJobSummary, | ||
'false', | ||
'Value is stored for the collapsed state' | ||
); | ||
}); | ||
}); | ||
|
||
test('the collapsed/expanded state from localStorage is used for the initial state when available', function(assert) { | ||
this.server.create('job', { | ||
createAllocations: false, | ||
}); | ||
|
||
this.store.findAll('job'); | ||
|
||
window.localStorage.nomadExpandJobSummary = 'false'; | ||
|
||
return wait() | ||
.then(() => { | ||
this.set('job', this.store.peekAll('job').get('firstObject')); | ||
|
||
this.render(hbs` | ||
{{job-page/parts/summary job=job}} | ||
`); | ||
|
||
return wait(); | ||
}) | ||
.then(() => { | ||
assert.ok(find('[data-test-allocation-status-bar]'), 'Allocation bar still existed'); | ||
assert.ok( | ||
find('.inline-chart [data-test-allocation-status-bar]'), | ||
'Allocation bar is rendered in an inline-chart container' | ||
); | ||
|
||
click('[data-test-accordion-toggle]'); | ||
return wait(); | ||
}) | ||
.then(() => { | ||
assert.equal( | ||
window.localStorage.nomadExpandJobSummary, | ||
'true', | ||
'localStorage value still toggles' | ||
); | ||
assert.ok(find('[data-test-accordion-body]'), 'Summary still expands'); | ||
}); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
👌