ui_utils_spec.js 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630
  1. /**
  2. * @licstart The following is the entire license notice for the
  3. * Javascript code in this page
  4. *
  5. * Copyright 2021 Mozilla Foundation
  6. *
  7. * Licensed under the Apache License, Version 2.0 (the "License");
  8. * you may not use this file except in compliance with the License.
  9. * You may obtain a copy of the License at
  10. *
  11. * http://www.apache.org/licenses/LICENSE-2.0
  12. *
  13. * Unless required by applicable law or agreed to in writing, software
  14. * distributed under the License is distributed on an "AS IS" BASIS,
  15. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  16. * See the License for the specific language governing permissions and
  17. * limitations under the License.
  18. *
  19. * @licend The above is the entire license notice for the
  20. * Javascript code in this page
  21. */
  22. "use strict";
  23. var _ui_utils = require("../../web/ui_utils.js");
  24. var _is_node = require("../../shared/is_node.js");
  25. describe("ui_utils", function () {
  26. describe("binary search", function () {
  27. function isTrue(boolean) {
  28. return boolean;
  29. }
  30. function isGreater3(number) {
  31. return number > 3;
  32. }
  33. it("empty array", function () {
  34. expect((0, _ui_utils.binarySearchFirstItem)([], isTrue)).toEqual(0);
  35. });
  36. it("single boolean entry", function () {
  37. expect((0, _ui_utils.binarySearchFirstItem)([false], isTrue)).toEqual(1);
  38. expect((0, _ui_utils.binarySearchFirstItem)([true], isTrue)).toEqual(0);
  39. });
  40. it("three boolean entries", function () {
  41. expect((0, _ui_utils.binarySearchFirstItem)([true, true, true], isTrue)).toEqual(0);
  42. expect((0, _ui_utils.binarySearchFirstItem)([false, true, true], isTrue)).toEqual(1);
  43. expect((0, _ui_utils.binarySearchFirstItem)([false, false, true], isTrue)).toEqual(2);
  44. expect((0, _ui_utils.binarySearchFirstItem)([false, false, false], isTrue)).toEqual(3);
  45. });
  46. it("three numeric entries", function () {
  47. expect((0, _ui_utils.binarySearchFirstItem)([0, 1, 2], isGreater3)).toEqual(3);
  48. expect((0, _ui_utils.binarySearchFirstItem)([2, 3, 4], isGreater3)).toEqual(2);
  49. expect((0, _ui_utils.binarySearchFirstItem)([4, 5, 6], isGreater3)).toEqual(0);
  50. });
  51. });
  52. describe("EventBus", function () {
  53. it("dispatch event", function () {
  54. const eventBus = new _ui_utils.EventBus();
  55. let count = 0;
  56. eventBus.on("test", function (evt) {
  57. expect(evt).toEqual(undefined);
  58. count++;
  59. });
  60. eventBus.dispatch("test");
  61. expect(count).toEqual(1);
  62. });
  63. it("dispatch event with arguments", function () {
  64. const eventBus = new _ui_utils.EventBus();
  65. let count = 0;
  66. eventBus.on("test", function (evt) {
  67. expect(evt).toEqual({
  68. abc: 123
  69. });
  70. count++;
  71. });
  72. eventBus.dispatch("test", {
  73. abc: 123
  74. });
  75. expect(count).toEqual(1);
  76. });
  77. it("dispatch different event", function () {
  78. const eventBus = new _ui_utils.EventBus();
  79. let count = 0;
  80. eventBus.on("test", function () {
  81. count++;
  82. });
  83. eventBus.dispatch("nottest");
  84. expect(count).toEqual(0);
  85. });
  86. it("dispatch event multiple times", function () {
  87. const eventBus = new _ui_utils.EventBus();
  88. let count = 0;
  89. eventBus.dispatch("test");
  90. eventBus.on("test", function () {
  91. count++;
  92. });
  93. eventBus.dispatch("test");
  94. eventBus.dispatch("test");
  95. expect(count).toEqual(2);
  96. });
  97. it("dispatch event to multiple handlers", function () {
  98. const eventBus = new _ui_utils.EventBus();
  99. let count = 0;
  100. eventBus.on("test", function () {
  101. count++;
  102. });
  103. eventBus.on("test", function () {
  104. count++;
  105. });
  106. eventBus.dispatch("test");
  107. expect(count).toEqual(2);
  108. });
  109. it("dispatch to detached", function () {
  110. const eventBus = new _ui_utils.EventBus();
  111. let count = 0;
  112. const listener = function () {
  113. count++;
  114. };
  115. eventBus.on("test", listener);
  116. eventBus.dispatch("test");
  117. eventBus.off("test", listener);
  118. eventBus.dispatch("test");
  119. expect(count).toEqual(1);
  120. });
  121. it("dispatch to wrong detached", function () {
  122. const eventBus = new _ui_utils.EventBus();
  123. let count = 0;
  124. eventBus.on("test", function () {
  125. count++;
  126. });
  127. eventBus.dispatch("test");
  128. eventBus.off("test", function () {
  129. count++;
  130. });
  131. eventBus.dispatch("test");
  132. expect(count).toEqual(2);
  133. });
  134. it("dispatch to detached during handling", function () {
  135. const eventBus = new _ui_utils.EventBus();
  136. let count = 0;
  137. const listener1 = function () {
  138. eventBus.off("test", listener2);
  139. count++;
  140. };
  141. const listener2 = function () {
  142. eventBus.off("test", listener1);
  143. count++;
  144. };
  145. eventBus.on("test", listener1);
  146. eventBus.on("test", listener2);
  147. eventBus.dispatch("test");
  148. eventBus.dispatch("test");
  149. expect(count).toEqual(2);
  150. });
  151. it("dispatch event to handlers with/without 'once' option", function () {
  152. const eventBus = new _ui_utils.EventBus();
  153. let multipleCount = 0,
  154. onceCount = 0;
  155. eventBus.on("test", function () {
  156. multipleCount++;
  157. });
  158. eventBus.on("test", function () {
  159. onceCount++;
  160. }, {
  161. once: true
  162. });
  163. eventBus.dispatch("test");
  164. eventBus.dispatch("test");
  165. eventBus.dispatch("test");
  166. expect(multipleCount).toEqual(3);
  167. expect(onceCount).toEqual(1);
  168. });
  169. it("should not re-dispatch to DOM", function (done) {
  170. if (_is_node.isNodeJS) {
  171. pending("Document in not supported in Node.js.");
  172. }
  173. const eventBus = new _ui_utils.EventBus();
  174. let count = 0;
  175. eventBus.on("test", function (evt) {
  176. expect(evt).toEqual(undefined);
  177. count++;
  178. });
  179. function domEventListener() {
  180. done.fail("shall not dispatch DOM event.");
  181. }
  182. document.addEventListener("test", domEventListener);
  183. eventBus.dispatch("test");
  184. Promise.resolve().then(() => {
  185. expect(count).toEqual(1);
  186. document.removeEventListener("test", domEventListener);
  187. done();
  188. });
  189. });
  190. });
  191. describe("isValidRotation", function () {
  192. it("should reject non-integer angles", function () {
  193. expect((0, _ui_utils.isValidRotation)()).toEqual(false);
  194. expect((0, _ui_utils.isValidRotation)(null)).toEqual(false);
  195. expect((0, _ui_utils.isValidRotation)(NaN)).toEqual(false);
  196. expect((0, _ui_utils.isValidRotation)([90])).toEqual(false);
  197. expect((0, _ui_utils.isValidRotation)("90")).toEqual(false);
  198. expect((0, _ui_utils.isValidRotation)(90.5)).toEqual(false);
  199. });
  200. it("should reject non-multiple of 90 degree angles", function () {
  201. expect((0, _ui_utils.isValidRotation)(45)).toEqual(false);
  202. expect((0, _ui_utils.isValidRotation)(-123)).toEqual(false);
  203. });
  204. it("should accept valid angles", function () {
  205. expect((0, _ui_utils.isValidRotation)(0)).toEqual(true);
  206. expect((0, _ui_utils.isValidRotation)(90)).toEqual(true);
  207. expect((0, _ui_utils.isValidRotation)(-270)).toEqual(true);
  208. expect((0, _ui_utils.isValidRotation)(540)).toEqual(true);
  209. });
  210. });
  211. describe("isPortraitOrientation", function () {
  212. it("should be portrait orientation", function () {
  213. expect((0, _ui_utils.isPortraitOrientation)({
  214. width: 200,
  215. height: 400
  216. })).toEqual(true);
  217. expect((0, _ui_utils.isPortraitOrientation)({
  218. width: 500,
  219. height: 500
  220. })).toEqual(true);
  221. });
  222. it("should be landscape orientation", function () {
  223. expect((0, _ui_utils.isPortraitOrientation)({
  224. width: 600,
  225. height: 300
  226. })).toEqual(false);
  227. });
  228. });
  229. describe("waitOnEventOrTimeout", function () {
  230. let eventBus;
  231. beforeAll(function (done) {
  232. eventBus = new _ui_utils.EventBus();
  233. done();
  234. });
  235. afterAll(function () {
  236. eventBus = null;
  237. });
  238. it("should reject invalid parameters", function (done) {
  239. const invalidTarget = (0, _ui_utils.waitOnEventOrTimeout)({
  240. target: "window",
  241. name: "DOMContentLoaded"
  242. }).then(function () {
  243. throw new Error("Should reject invalid parameters.");
  244. }, function (reason) {
  245. expect(reason instanceof Error).toEqual(true);
  246. });
  247. const invalidName = (0, _ui_utils.waitOnEventOrTimeout)({
  248. target: eventBus,
  249. name: ""
  250. }).then(function () {
  251. throw new Error("Should reject invalid parameters.");
  252. }, function (reason) {
  253. expect(reason instanceof Error).toEqual(true);
  254. });
  255. const invalidDelay = (0, _ui_utils.waitOnEventOrTimeout)({
  256. target: eventBus,
  257. name: "pagerendered",
  258. delay: -1000
  259. }).then(function () {
  260. throw new Error("Should reject invalid parameters.");
  261. }, function (reason) {
  262. expect(reason instanceof Error).toEqual(true);
  263. });
  264. Promise.all([invalidTarget, invalidName, invalidDelay]).then(done, done.fail);
  265. });
  266. it("should resolve on event, using the DOM", function (done) {
  267. if (_is_node.isNodeJS) {
  268. pending("Document in not supported in Node.js.");
  269. }
  270. const button = document.createElement("button");
  271. const buttonClicked = (0, _ui_utils.waitOnEventOrTimeout)({
  272. target: button,
  273. name: "click",
  274. delay: 10000
  275. });
  276. button.click();
  277. buttonClicked.then(function (type) {
  278. expect(type).toEqual(_ui_utils.WaitOnType.EVENT);
  279. done();
  280. }, done.fail);
  281. });
  282. it("should resolve on timeout, using the DOM", function (done) {
  283. if (_is_node.isNodeJS) {
  284. pending("Document in not supported in Node.js.");
  285. }
  286. const button = document.createElement("button");
  287. const buttonClicked = (0, _ui_utils.waitOnEventOrTimeout)({
  288. target: button,
  289. name: "click",
  290. delay: 10
  291. });
  292. buttonClicked.then(function (type) {
  293. expect(type).toEqual(_ui_utils.WaitOnType.TIMEOUT);
  294. done();
  295. }, done.fail);
  296. });
  297. it("should resolve on event, using the EventBus", function (done) {
  298. const pageRendered = (0, _ui_utils.waitOnEventOrTimeout)({
  299. target: eventBus,
  300. name: "pagerendered",
  301. delay: 10000
  302. });
  303. eventBus.dispatch("pagerendered");
  304. pageRendered.then(function (type) {
  305. expect(type).toEqual(_ui_utils.WaitOnType.EVENT);
  306. done();
  307. }, done.fail);
  308. });
  309. it("should resolve on timeout, using the EventBus", function (done) {
  310. const pageRendered = (0, _ui_utils.waitOnEventOrTimeout)({
  311. target: eventBus,
  312. name: "pagerendered",
  313. delay: 10
  314. });
  315. pageRendered.then(function (type) {
  316. expect(type).toEqual(_ui_utils.WaitOnType.TIMEOUT);
  317. done();
  318. }, done.fail);
  319. });
  320. });
  321. describe("getPageSizeInches", function () {
  322. it("gets page size (in inches)", function () {
  323. const page = {
  324. view: [0, 0, 595.28, 841.89],
  325. userUnit: 1.0,
  326. rotate: 0
  327. };
  328. const {
  329. width,
  330. height
  331. } = (0, _ui_utils.getPageSizeInches)(page);
  332. expect(+width.toPrecision(3)).toEqual(8.27);
  333. expect(+height.toPrecision(4)).toEqual(11.69);
  334. });
  335. it("gets page size (in inches), for non-default /Rotate entry", function () {
  336. const pdfPage1 = {
  337. view: [0, 0, 612, 792],
  338. userUnit: 1,
  339. rotate: 0
  340. };
  341. const {
  342. width: width1,
  343. height: height1
  344. } = (0, _ui_utils.getPageSizeInches)(pdfPage1);
  345. expect(width1).toEqual(8.5);
  346. expect(height1).toEqual(11);
  347. const pdfPage2 = {
  348. view: [0, 0, 612, 792],
  349. userUnit: 1,
  350. rotate: 90
  351. };
  352. const {
  353. width: width2,
  354. height: height2
  355. } = (0, _ui_utils.getPageSizeInches)(pdfPage2);
  356. expect(width2).toEqual(11);
  357. expect(height2).toEqual(8.5);
  358. });
  359. });
  360. describe("getVisibleElements", function () {
  361. const BORDER_WIDTH = 9;
  362. const SPACING = 2 * BORDER_WIDTH - 7;
  363. function makePages(lines) {
  364. const result = [];
  365. let lineTop = 0,
  366. id = 0;
  367. for (const line of lines) {
  368. const lineHeight = line.reduce(function (maxHeight, pair) {
  369. return Math.max(maxHeight, pair[1]);
  370. }, 0);
  371. let offsetLeft = -BORDER_WIDTH;
  372. for (const [clientWidth, clientHeight] of line) {
  373. const offsetTop = lineTop + (lineHeight - clientHeight) / 2 - BORDER_WIDTH;
  374. const div = {
  375. offsetLeft,
  376. offsetTop,
  377. clientWidth,
  378. clientHeight,
  379. clientLeft: BORDER_WIDTH,
  380. clientTop: BORDER_WIDTH
  381. };
  382. result.push({
  383. id,
  384. div
  385. });
  386. ++id;
  387. offsetLeft += clientWidth + SPACING;
  388. }
  389. lineTop += lineHeight + SPACING;
  390. }
  391. return result;
  392. }
  393. function slowGetVisibleElements(scroll, pages) {
  394. const views = [];
  395. const {
  396. scrollLeft,
  397. scrollTop
  398. } = scroll;
  399. const scrollRight = scrollLeft + scroll.clientWidth;
  400. const scrollBottom = scrollTop + scroll.clientHeight;
  401. for (const view of pages) {
  402. const {
  403. div
  404. } = view;
  405. const viewLeft = div.offsetLeft + div.clientLeft;
  406. const viewRight = viewLeft + div.clientWidth;
  407. const viewTop = div.offsetTop + div.clientTop;
  408. const viewBottom = viewTop + div.clientHeight;
  409. if (viewLeft < scrollRight && viewRight > scrollLeft && viewTop < scrollBottom && viewBottom > scrollTop) {
  410. const hiddenHeight = Math.max(0, scrollTop - viewTop) + Math.max(0, viewBottom - scrollBottom);
  411. const hiddenWidth = Math.max(0, scrollLeft - viewLeft) + Math.max(0, viewRight - scrollRight);
  412. const fractionHeight = (div.clientHeight - hiddenHeight) / div.clientHeight;
  413. const fractionWidth = (div.clientWidth - hiddenWidth) / div.clientWidth;
  414. const percent = fractionHeight * fractionWidth * 100 | 0;
  415. views.push({
  416. id: view.id,
  417. x: viewLeft,
  418. y: viewTop,
  419. view,
  420. percent,
  421. widthPercent: fractionWidth * 100 | 0
  422. });
  423. }
  424. }
  425. return {
  426. first: views[0],
  427. last: views[views.length - 1],
  428. views
  429. };
  430. }
  431. function scrollOverDocument(pages, horizontal = false, rtl = false) {
  432. const size = pages.reduce(function (max, {
  433. div
  434. }) {
  435. return Math.max(max, horizontal ? Math.abs(div.offsetLeft + div.clientLeft + div.clientWidth) : div.offsetTop + div.clientTop + div.clientHeight);
  436. }, 0);
  437. for (let i = -size; i < size; i += 7) {
  438. for (let j = i + 5; j < size; j += j - i) {
  439. const scrollEl = horizontal ? {
  440. scrollTop: 0,
  441. scrollLeft: i,
  442. clientHeight: 10000,
  443. clientWidth: j - i
  444. } : {
  445. scrollTop: i,
  446. scrollLeft: 0,
  447. clientHeight: j - i,
  448. clientWidth: 10000
  449. };
  450. expect((0, _ui_utils.getVisibleElements)({
  451. scrollEl,
  452. views: pages,
  453. sortByVisibility: false,
  454. horizontal,
  455. rtl
  456. })).toEqual(slowGetVisibleElements(scrollEl, pages));
  457. }
  458. }
  459. }
  460. it("with pages of varying height", function () {
  461. const pages = makePages([[[50, 20], [20, 50]], [[30, 12], [12, 30]], [[20, 50], [50, 20]], [[50, 20], [20, 50]]]);
  462. scrollOverDocument(pages);
  463. });
  464. it("widescreen challenge", function () {
  465. const pages = makePages([[[10, 50], [10, 60], [10, 70], [10, 80], [10, 90]], [[10, 90], [10, 80], [10, 70], [10, 60], [10, 50]], [[10, 50], [10, 60], [10, 70], [10, 80], [10, 90]]]);
  466. scrollOverDocument(pages);
  467. });
  468. it("works with horizontal scrolling", function () {
  469. const pages = makePages([[[10, 50], [20, 20], [30, 10]]]);
  470. scrollOverDocument(pages, true);
  471. });
  472. it("works with horizontal scrolling with RTL-documents", function () {
  473. const pages = makePages([[[-10, 50], [-20, 20], [-30, 10]]]);
  474. scrollOverDocument(pages, true, true);
  475. });
  476. it("handles `sortByVisibility` correctly", function () {
  477. const scrollEl = {
  478. scrollTop: 75,
  479. scrollLeft: 0,
  480. clientHeight: 750,
  481. clientWidth: 1500
  482. };
  483. const views = makePages([[[100, 150]], [[100, 150]], [[100, 150]]]);
  484. const visible = (0, _ui_utils.getVisibleElements)({
  485. scrollEl,
  486. views
  487. });
  488. const visibleSorted = (0, _ui_utils.getVisibleElements)({
  489. scrollEl,
  490. views,
  491. sortByVisibility: true
  492. });
  493. const viewsOrder = [],
  494. viewsSortedOrder = [];
  495. for (const view of visible.views) {
  496. viewsOrder.push(view.id);
  497. }
  498. for (const view of visibleSorted.views) {
  499. viewsSortedOrder.push(view.id);
  500. }
  501. expect(viewsOrder).toEqual([0, 1, 2]);
  502. expect(viewsSortedOrder).toEqual([1, 2, 0]);
  503. });
  504. it("handles views being empty", function () {
  505. const scrollEl = {
  506. scrollTop: 10,
  507. scrollLeft: 0,
  508. clientHeight: 750,
  509. clientWidth: 1500
  510. };
  511. const views = [];
  512. expect((0, _ui_utils.getVisibleElements)({
  513. scrollEl,
  514. views
  515. })).toEqual({
  516. first: undefined,
  517. last: undefined,
  518. views: []
  519. });
  520. });
  521. it("handles all views being hidden (without errors)", function () {
  522. const scrollEl = {
  523. scrollTop: 100000,
  524. scrollLeft: 0,
  525. clientHeight: 750,
  526. clientWidth: 1500
  527. };
  528. const views = makePages([[[100, 150]], [[100, 150]], [[100, 150]]]);
  529. expect((0, _ui_utils.getVisibleElements)({
  530. scrollEl,
  531. views
  532. })).toEqual({
  533. first: undefined,
  534. last: undefined,
  535. views: []
  536. });
  537. });
  538. describe("backtrackBeforeAllVisibleElements", function () {
  539. const tallPage = [10, 50];
  540. const shortPage = [10, 10];
  541. const top1 = 20 + SPACING + 40;
  542. const top2 = 20 + SPACING + 10;
  543. it("handles case 1", function () {
  544. const pages = makePages([[[10, 20], [10, 20], [10, 20], [10, 20]], [tallPage, shortPage, tallPage, shortPage], [[10, 50], [10, 50], [10, 50], [10, 50]], [[10, 20], [10, 20], [10, 20], [10, 20]], [[10, 20]]]);
  545. const bsResult = 4;
  546. expect((0, _ui_utils.backtrackBeforeAllVisibleElements)(bsResult, pages, top1)).toEqual(4);
  547. });
  548. it("handles case 2", function () {
  549. const pages = makePages([[[10, 20], [10, 20], [10, 20], [10, 20]], [tallPage, shortPage, tallPage, tallPage], [[10, 50], [10, 50], [10, 50], [10, 50]], [[10, 20], [10, 20], [10, 20], [10, 20]]]);
  550. const bsResult = 6;
  551. expect((0, _ui_utils.backtrackBeforeAllVisibleElements)(bsResult, pages, top1)).toEqual(4);
  552. });
  553. it("handles case 3", function () {
  554. const pages = makePages([[[10, 20], [10, 20], [10, 20], [10, 20]], [tallPage, shortPage, tallPage, shortPage], [[10, 50], [10, 50], [10, 50], [10, 50]], [[10, 20], [10, 20], [10, 20], [10, 20]]]);
  555. const bsResult = 8;
  556. expect((0, _ui_utils.backtrackBeforeAllVisibleElements)(bsResult, pages, top1)).toEqual(4);
  557. });
  558. it("handles case 4", function () {
  559. const pages = makePages([[[10, 20], [10, 20], [10, 20], [10, 20]], [tallPage, shortPage, tallPage, shortPage], [[10, 50], [10, 50], [10, 50], [10, 50]], [[10, 20], [10, 20], [10, 20], [10, 20]]]);
  560. const bsResult = 4;
  561. expect((0, _ui_utils.backtrackBeforeAllVisibleElements)(bsResult, pages, top2)).toEqual(4);
  562. });
  563. });
  564. });
  565. describe("moveToEndOfArray", function () {
  566. it("works on empty arrays", function () {
  567. const data = [];
  568. (0, _ui_utils.moveToEndOfArray)(data, function () {});
  569. expect(data).toEqual([]);
  570. });
  571. it("works when moving everything", function () {
  572. const data = [1, 2, 3, 4, 5];
  573. (0, _ui_utils.moveToEndOfArray)(data, function () {
  574. return true;
  575. });
  576. expect(data).toEqual([1, 2, 3, 4, 5]);
  577. });
  578. it("works when moving some things", function () {
  579. const data = [1, 2, 3, 4, 5];
  580. (0, _ui_utils.moveToEndOfArray)(data, function (x) {
  581. return x % 2 === 0;
  582. });
  583. expect(data).toEqual([1, 3, 5, 2, 4]);
  584. });
  585. it("works when moving one thing", function () {
  586. const data = [1, 2, 3, 4, 5];
  587. (0, _ui_utils.moveToEndOfArray)(data, function (x) {
  588. return x === 1;
  589. });
  590. expect(data).toEqual([2, 3, 4, 5, 1]);
  591. });
  592. it("works when moving nothing", function () {
  593. const data = [1, 2, 3, 4, 5];
  594. (0, _ui_utils.moveToEndOfArray)(data, function (x) {
  595. return x === 0;
  596. });
  597. expect(data).toEqual([1, 2, 3, 4, 5]);
  598. });
  599. });
  600. });