diff options
author | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2018-02-20 17:07:26 +0100 |
---|---|---|
committer | Daniel Calviño Sánchez <danxuliu@gmail.com> | 2018-02-28 15:03:26 +0100 |
commit | acdf091f8463aadadd92be037e64102d2c8cf34c (patch) | |
tree | 8f209216104a0deeda9292cefee9a0de6f271db9 /apps/files/tests | |
parent | a37007f872df68dec9038cf43846f8bd998ff19b (diff) | |
download | nextcloud-server-acdf091f8463aadadd92be037e64102d2c8cf34c.tar.gz nextcloud-server-acdf091f8463aadadd92be037e64102d2c8cf34c.zip |
Compress siblings before calculating the available width for crumbs
When the parent element of the breadcrumbs was resized to a larger width
and the siblings of the breadcrumbs expanded to fill all the available
width some crumbs could be hidden even if there was enough room for
them. The reason was that the width of the siblings being used to
calculate the available width for the breadcrumbs was the expanded width
of the siblings. Now as many crumbs as possible (that is, fitting in the
parent, no matter the siblings) are first shown so the expanding
siblings are compressed before calculating the available width.
Due to the lack of support for flexboxes in PhantomJS the related unit
test is skipped; it has to be run in other browser, like Firefox.
Signed-off-by: Daniel Calviño Sánchez <danxuliu@gmail.com>
Diffstat (limited to 'apps/files/tests')
-rw-r--r-- | apps/files/tests/js/breadcrumbSpec.js | 87 |
1 files changed, 87 insertions, 0 deletions
diff --git a/apps/files/tests/js/breadcrumbSpec.js b/apps/files/tests/js/breadcrumbSpec.js index bae8370cd1d..392d4bf3fe1 100644 --- a/apps/files/tests/js/breadcrumbSpec.js +++ b/apps/files/tests/js/breadcrumbSpec.js @@ -238,6 +238,10 @@ describe('OCA.Files.BreadCrumb tests', function() { describe('Resizing', function() { var bc, dummyDir, widths; + // cit() will skip tests if running on PhantomJS because it does not + // have proper support for flexboxes. + var cit = window.isPhantom?xit:it; + beforeEach(function() { dummyDir = '/short name/longer name/looooooooooooonger/' + 'even longer long long long longer long/aaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/last one'; @@ -458,5 +462,88 @@ describe('OCA.Files.BreadCrumb tests', function() { expect($crumbs.eq(6).hasClass('hidden')).toEqual(false); expect($crumbs.eq(7).hasClass('hidden')).toEqual(false); }); + it('Updates the breadcrumbs when increasing available width', function() { + var $crumbs; + + // limited space + $('#controls').width(850); + bc._resize(); + + $crumbs = bc.$el.find('.crumb'); + + // Third and fourth crumb are hidden and everything else is visible + expect($crumbs.eq(0).hasClass('hidden')).toEqual(false); + expect($crumbs.eq(1).hasClass('hidden')).toEqual(false); + + expect($crumbs.eq(2).hasClass('hidden')).toEqual(false); + expect($crumbs.eq(3).hasClass('hidden')).toEqual(false); + expect($crumbs.eq(4).hasClass('hidden')).toEqual(true); + expect($crumbs.eq(5).hasClass('hidden')).toEqual(true); + expect($crumbs.eq(6).hasClass('hidden')).toEqual(false); + expect($crumbs.eq(7).hasClass('hidden')).toEqual(false); + + // simulate increase + $('#controls').width(1000); + bc._resize(); + + // Third crumb is hidden and everything else is visible + expect($crumbs.eq(0).hasClass('hidden')).toEqual(false); + expect($crumbs.eq(1).hasClass('hidden')).toEqual(false); + + expect($crumbs.eq(2).hasClass('hidden')).toEqual(false); + expect($crumbs.eq(3).hasClass('hidden')).toEqual(false); + expect($crumbs.eq(4).hasClass('hidden')).toEqual(true); + expect($crumbs.eq(5).hasClass('hidden')).toEqual(false); + expect($crumbs.eq(6).hasClass('hidden')).toEqual(false); + expect($crumbs.eq(7).hasClass('hidden')).toEqual(false); + }); + cit('Updates the breadcrumbs when increasing available width with an expanding sibling', function() { + var $crumbs; + + // The sibling expands to fill all the width left by the breadcrumbs + var $nextSibling = $('<div class="sibling"></div>'); + // Set both the width and the min-width to even differences in width + // handling in the browsers used to run the tests. + $nextSibling.css('width', '10px'); + $nextSibling.css('min-width', '10px'); + $nextSibling.css('display', 'flex'); + $nextSibling.css('flex', '1 1'); + var $nextSiblingChild = $('<div class="siblingChild"></div>'); + $nextSiblingChild.css('margin-left', 'auto'); + $nextSibling.append($nextSiblingChild); + $('#controls').append($nextSibling); + + // limited space + $('#controls').width(850); + bc._resize(); + + $crumbs = bc.$el.find('.crumb'); + + // Third and fourth crumb are hidden and everything else is visible + expect($crumbs.eq(0).hasClass('hidden')).toEqual(false); + expect($crumbs.eq(1).hasClass('hidden')).toEqual(false); + + expect($crumbs.eq(2).hasClass('hidden')).toEqual(false); + expect($crumbs.eq(3).hasClass('hidden')).toEqual(false); + expect($crumbs.eq(4).hasClass('hidden')).toEqual(true); + expect($crumbs.eq(5).hasClass('hidden')).toEqual(true); + expect($crumbs.eq(6).hasClass('hidden')).toEqual(false); + expect($crumbs.eq(7).hasClass('hidden')).toEqual(false); + + // simulate increase + $('#controls').width(1000); + bc._resize(); + + // Third crumb is hidden and everything else is visible + expect($crumbs.eq(0).hasClass('hidden')).toEqual(false); + expect($crumbs.eq(1).hasClass('hidden')).toEqual(false); + + expect($crumbs.eq(2).hasClass('hidden')).toEqual(false); + expect($crumbs.eq(3).hasClass('hidden')).toEqual(false); + expect($crumbs.eq(4).hasClass('hidden')).toEqual(true); + expect($crumbs.eq(5).hasClass('hidden')).toEqual(false); + expect($crumbs.eq(6).hasClass('hidden')).toEqual(false); + expect($crumbs.eq(7).hasClass('hidden')).toEqual(false); + }); }); }); |