@instructure/ui-position 9.0.1 → 9.0.2-snapshot-1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md CHANGED
@@ -3,6 +3,14 @@
3
3
  All notable changes to this project will be documented in this file.
4
4
  See [Conventional Commits](https://conventionalcommits.org) for commit guidelines.
5
5
 
6
+ ## [9.0.2-snapshot-1](https://github.com/instructure/instructure-ui/compare/v9.0.1...v9.0.2-snapshot-1) (2024-05-22)
7
+
8
+ **Note:** Version bump only for package @instructure/ui-position
9
+
10
+
11
+
12
+
13
+
6
14
  ## [9.0.1](https://github.com/instructure/instructure-ui/compare/v9.0.0...v9.0.1) (2024-05-09)
7
15
 
8
16
  **Note:** Version bump only for package @instructure/ui-position
@@ -0,0 +1,506 @@
1
+ var _Position, _Position2, _button, _div, _button2, _div2, _button3, _div3, _button4, _div4, _button5, _div5, _button6, _div6, _div7, _button7, _div8, _div9, _button8, _div10, _div11, _button9, _div12, _div13, _button10, _div14, _Position3, _div15, _button11, _div16, _Position4, _Position5;
2
+ /*
3
+ * The MIT License (MIT)
4
+ *
5
+ * Copyright (c) 2015 - present Instructure, Inc.
6
+ *
7
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
8
+ * of this software and associated documentation files (the "Software"), to deal
9
+ * in the Software without restriction, including without limitation the rights
10
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
11
+ * copies of the Software, and to permit persons to whom the Software is
12
+ * furnished to do so, subject to the following conditions:
13
+ *
14
+ * The above copyright notice and this permission notice shall be included in all
15
+ * copies or substantial portions of the Software.
16
+ *
17
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
18
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
19
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
20
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
21
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
22
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
23
+ * SOFTWARE.
24
+ */
25
+
26
+ import React from 'react';
27
+ import { render, screen, waitFor } from '@testing-library/react';
28
+ import '@testing-library/jest-dom';
29
+ import { within } from '@instructure/ui-utils';
30
+ import { Position } from '../index';
31
+ describe('<Position />', () => {
32
+ const parentDefaults = {
33
+ width: 500,
34
+ height: 150,
35
+ padding: 100,
36
+ overflow: 'auto'
37
+ };
38
+ it('should render', () => {
39
+ render( /*#__PURE__*/React.createElement("div", {
40
+ style: {
41
+ padding: '50px'
42
+ }
43
+ }, /*#__PURE__*/React.createElement("div", {
44
+ style: {
45
+ ...parentDefaults
46
+ }
47
+ }, _Position || (_Position = /*#__PURE__*/React.createElement(Position, {
48
+ constrain: "window",
49
+ renderTarget: /*#__PURE__*/React.createElement("button", {
50
+ "data-testid": "target-btn"
51
+ }, "Target")
52
+ }, /*#__PURE__*/React.createElement("div", {
53
+ "data-testid": "content"
54
+ }, /*#__PURE__*/React.createElement("div", null, "Content")))))));
55
+ const target = screen.getByTestId('target-btn');
56
+ const content = screen.getByTestId('content');
57
+ expect(target).toBeInTheDocument();
58
+ expect(target).toHaveTextContent('Target');
59
+ expect(content).toBeInTheDocument();
60
+ expect(content).toHaveTextContent('Content');
61
+ });
62
+ it('should absolutely position content', () => {
63
+ render( /*#__PURE__*/React.createElement("div", {
64
+ style: {
65
+ padding: '50px'
66
+ }
67
+ }, /*#__PURE__*/React.createElement("div", {
68
+ style: {
69
+ ...parentDefaults
70
+ }
71
+ }, _Position2 || (_Position2 = /*#__PURE__*/React.createElement(Position, {
72
+ constrain: "window",
73
+ renderTarget: /*#__PURE__*/React.createElement("button", {
74
+ "data-testid": "target"
75
+ }, "Target")
76
+ }, /*#__PURE__*/React.createElement("div", {
77
+ "data-testid": "content"
78
+ }, /*#__PURE__*/React.createElement("div", null, "Content")))))));
79
+ const content = screen.getByTestId('content');
80
+ const style = window.getComputedStyle(content);
81
+ expect(style.position).toBe('absolute');
82
+ });
83
+ it('should render right of target', async () => {
84
+ const onPositionChanged = jest.fn();
85
+ render( /*#__PURE__*/React.createElement("div", {
86
+ style: {
87
+ padding: '50px'
88
+ }
89
+ }, /*#__PURE__*/React.createElement("div", {
90
+ style: {
91
+ ...parentDefaults
92
+ }
93
+ }, /*#__PURE__*/React.createElement(Position, {
94
+ placement: "end",
95
+ onPositionChanged: onPositionChanged,
96
+ renderTarget: _button || (_button = /*#__PURE__*/React.createElement("button", {
97
+ "data-testid": "target"
98
+ }, "Target"))
99
+ }, _div || (_div = /*#__PURE__*/React.createElement("div", {
100
+ "data-testid": "content"
101
+ }, /*#__PURE__*/React.createElement("div", null, "Content")))))));
102
+ const target = screen.getByTestId('target');
103
+ const content = screen.getByTestId('content');
104
+ await waitFor(() => {
105
+ expect(onPositionChanged).toHaveBeenCalled();
106
+ });
107
+ const targetRect = target.getBoundingClientRect();
108
+ const contentRect = content.getBoundingClientRect();
109
+ expect(within(Math.floor(contentRect.left), Math.floor(targetRect.right))).toBe(true);
110
+ });
111
+ it('should render below target', async () => {
112
+ const onPositionChanged = jest.fn();
113
+ render( /*#__PURE__*/React.createElement("div", {
114
+ style: {
115
+ padding: '50px'
116
+ }
117
+ }, /*#__PURE__*/React.createElement("div", {
118
+ style: {
119
+ ...parentDefaults
120
+ }
121
+ }, /*#__PURE__*/React.createElement(Position, {
122
+ placement: "bottom",
123
+ onPositionChanged: onPositionChanged,
124
+ renderTarget: _button2 || (_button2 = /*#__PURE__*/React.createElement("button", {
125
+ "data-testid": "target"
126
+ }, "Target"))
127
+ }, _div2 || (_div2 = /*#__PURE__*/React.createElement("div", {
128
+ "data-testid": "content"
129
+ }, /*#__PURE__*/React.createElement("div", null, "Content")))))));
130
+ const target = screen.getByTestId('target');
131
+ const content = screen.getByTestId('content');
132
+ await waitFor(() => {
133
+ expect(onPositionChanged).toHaveBeenCalled();
134
+ });
135
+ const targetRect = target.getBoundingClientRect();
136
+ const contentRect = content.getBoundingClientRect();
137
+ expect(within(Math.floor(contentRect.top), Math.floor(targetRect.bottom), 1)).toBe(true);
138
+ });
139
+ it('should render left of target', async () => {
140
+ const onPositionChanged = jest.fn();
141
+ render( /*#__PURE__*/React.createElement("div", {
142
+ style: {
143
+ padding: '50px'
144
+ }
145
+ }, /*#__PURE__*/React.createElement("div", {
146
+ style: {
147
+ ...parentDefaults
148
+ }
149
+ }, /*#__PURE__*/React.createElement(Position, {
150
+ placement: "start",
151
+ onPositionChanged: onPositionChanged,
152
+ renderTarget: _button3 || (_button3 = /*#__PURE__*/React.createElement("button", {
153
+ "data-testid": "target"
154
+ }, "Target"))
155
+ }, _div3 || (_div3 = /*#__PURE__*/React.createElement("div", {
156
+ "data-testid": "content"
157
+ }, /*#__PURE__*/React.createElement("div", null, "Content")))))));
158
+ const target = screen.getByTestId('target');
159
+ const content = screen.getByTestId('content');
160
+ await waitFor(() => {
161
+ expect(onPositionChanged).toHaveBeenCalled();
162
+ });
163
+ const targetRect = target.getBoundingClientRect();
164
+ const contentRect = content.getBoundingClientRect();
165
+ expect(within(Math.floor(contentRect.right), Math.floor(targetRect.left))).toBe(true);
166
+ });
167
+ it('should render above target', async () => {
168
+ const onPositionChanged = jest.fn();
169
+ render( /*#__PURE__*/React.createElement("div", {
170
+ style: {
171
+ padding: '50px'
172
+ }
173
+ }, /*#__PURE__*/React.createElement("div", {
174
+ style: {
175
+ ...parentDefaults
176
+ }
177
+ }, /*#__PURE__*/React.createElement(Position, {
178
+ placement: "top",
179
+ onPositionChanged: onPositionChanged,
180
+ renderTarget: _button4 || (_button4 = /*#__PURE__*/React.createElement("button", {
181
+ "data-testid": "target"
182
+ }, "Target"))
183
+ }, _div4 || (_div4 = /*#__PURE__*/React.createElement("div", {
184
+ "data-testid": "content"
185
+ }, /*#__PURE__*/React.createElement("div", null, "Content")))))));
186
+ const target = screen.getByTestId('target');
187
+ const content = screen.getByTestId('content');
188
+ await waitFor(() => {
189
+ expect(onPositionChanged).toHaveBeenCalled();
190
+ });
191
+ const targetRect = target.getBoundingClientRect();
192
+ const contentRect = content.getBoundingClientRect();
193
+ expect(Math.floor(contentRect.bottom)).toEqual(Math.floor(targetRect.top));
194
+ });
195
+ it('should center vertically', async () => {
196
+ const onPositionChanged = jest.fn();
197
+ render( /*#__PURE__*/React.createElement("div", {
198
+ style: {
199
+ padding: '50px'
200
+ }
201
+ }, /*#__PURE__*/React.createElement("div", {
202
+ style: {
203
+ ...parentDefaults
204
+ }
205
+ }, /*#__PURE__*/React.createElement(Position, {
206
+ placement: "end",
207
+ onPositionChanged: onPositionChanged,
208
+ renderTarget: _button5 || (_button5 = /*#__PURE__*/React.createElement("button", {
209
+ "data-testid": "target"
210
+ }, "Target"))
211
+ }, _div5 || (_div5 = /*#__PURE__*/React.createElement("div", {
212
+ "data-testid": "content"
213
+ }, /*#__PURE__*/React.createElement("div", null, "Content")))))));
214
+ const target = screen.getByTestId('target');
215
+ const content = screen.getByTestId('content');
216
+ await waitFor(() => {
217
+ expect(onPositionChanged).toHaveBeenCalled();
218
+ });
219
+ const targetRect = target.getBoundingClientRect();
220
+ const contentRect = content.getBoundingClientRect();
221
+ const top = Math.floor(contentRect.top);
222
+ const center = Math.floor(targetRect.top + (targetRect.height / 2 - contentRect.height / 2));
223
+ expect(within(top, center)).toBe(true);
224
+ });
225
+ it('should center horizontally', async () => {
226
+ const onPositionChanged = jest.fn();
227
+ render( /*#__PURE__*/React.createElement("div", {
228
+ style: {
229
+ padding: '50px'
230
+ }
231
+ }, /*#__PURE__*/React.createElement("div", {
232
+ style: {
233
+ ...parentDefaults
234
+ }
235
+ }, /*#__PURE__*/React.createElement(Position, {
236
+ placement: "bottom",
237
+ onPositionChanged: onPositionChanged,
238
+ renderTarget: _button6 || (_button6 = /*#__PURE__*/React.createElement("button", {
239
+ "data-testid": "target"
240
+ }, "Target"))
241
+ }, _div6 || (_div6 = /*#__PURE__*/React.createElement("div", {
242
+ "data-testid": "content"
243
+ }, /*#__PURE__*/React.createElement("div", null, "Content")))))));
244
+ const target = screen.getByTestId('target');
245
+ const content = screen.getByTestId('content');
246
+ await waitFor(() => {
247
+ expect(onPositionChanged).toHaveBeenCalled();
248
+ });
249
+ const targetRect = target.getBoundingClientRect();
250
+ const contentRect = content.getBoundingClientRect();
251
+ const left = Math.floor(contentRect.left);
252
+ const targetCenter = targetRect.width / 2;
253
+ const contentCenter = contentRect.width / 2;
254
+ const center = Math.floor(targetRect.left + (targetCenter - contentCenter));
255
+ expect(within(left, center)).toBe(true);
256
+ });
257
+ describe('when constrained to scroll-parent', () => {
258
+ it('should re-position below target', async () => {
259
+ const onPositionChanged = jest.fn();
260
+ render( /*#__PURE__*/React.createElement("div", {
261
+ style: {
262
+ padding: '50px'
263
+ }
264
+ }, _div7 || (_div7 = /*#__PURE__*/React.createElement("div", {
265
+ "data-testid": "mountNode"
266
+ }, "mount")), /*#__PURE__*/React.createElement("div", {
267
+ style: {
268
+ width: '50px',
269
+ height: '50px',
270
+ overflow: 'scroll',
271
+ padding: '0 50px 50px 50px'
272
+ }
273
+ }, /*#__PURE__*/React.createElement(Position, {
274
+ placement: "top",
275
+ constrain: "scroll-parent",
276
+ mountNode: () => document.getElementById('mountNode'),
277
+ onPositionChanged: onPositionChanged,
278
+ renderTarget: _button7 || (_button7 = /*#__PURE__*/React.createElement("button", {
279
+ "data-testid": "target"
280
+ }, "Target"))
281
+ }, _div8 || (_div8 = /*#__PURE__*/React.createElement("div", {
282
+ "data-testid": "content"
283
+ }, /*#__PURE__*/React.createElement("div", null, "Content")))))));
284
+ const target = screen.getByTestId('target');
285
+ const content = screen.getByTestId('content');
286
+ await waitFor(() => {
287
+ expect(onPositionChanged).toHaveBeenCalled();
288
+ });
289
+ const targetRect = target.getBoundingClientRect();
290
+ const contentRect = content.getBoundingClientRect();
291
+ expect(within(Math.floor(contentRect.top), Math.floor(targetRect.bottom), 1)).toBe(true);
292
+ });
293
+ it('should re-position above target', async () => {
294
+ const onPositionChanged = jest.fn();
295
+ render( /*#__PURE__*/React.createElement("div", {
296
+ style: {
297
+ padding: '50px'
298
+ }
299
+ }, _div9 || (_div9 = /*#__PURE__*/React.createElement("div", {
300
+ id: "mountNode"
301
+ }, "mount")), /*#__PURE__*/React.createElement("div", {
302
+ style: {
303
+ width: '50px',
304
+ height: '0px',
305
+ overflow: 'scroll',
306
+ padding: '50px 50px 0 50px'
307
+ }
308
+ }, /*#__PURE__*/React.createElement(Position, {
309
+ placement: "bottom",
310
+ constrain: "scroll-parent",
311
+ mountNode: () => document.getElementById('mountNode'),
312
+ onPositionChanged: onPositionChanged,
313
+ renderTarget: _button8 || (_button8 = /*#__PURE__*/React.createElement("button", {
314
+ "data-testid": "target"
315
+ }, "Target"))
316
+ }, _div10 || (_div10 = /*#__PURE__*/React.createElement("div", {
317
+ "data-testid": "content"
318
+ }, /*#__PURE__*/React.createElement("div", null, "Content")))))));
319
+ const target = screen.getByTestId('target');
320
+ const content = screen.getByTestId('content');
321
+ await waitFor(() => {
322
+ expect(onPositionChanged).toHaveBeenCalled();
323
+ });
324
+ const targetRect = target.getBoundingClientRect();
325
+ const contentRect = content.getBoundingClientRect();
326
+ expect(within(Math.floor(contentRect.bottom), Math.floor(targetRect.top), 1)).toBe(true);
327
+ });
328
+ it('should re-position after target', async () => {
329
+ const onPositionChanged = jest.fn();
330
+ render( /*#__PURE__*/React.createElement("div", {
331
+ style: {
332
+ padding: '50px'
333
+ }
334
+ }, _div11 || (_div11 = /*#__PURE__*/React.createElement("div", {
335
+ id: "mountNode"
336
+ }, "mount")), /*#__PURE__*/React.createElement("div", {
337
+ style: {
338
+ width: '50px',
339
+ height: '50px',
340
+ overflow: 'scroll',
341
+ padding: '50px 80px 50px 0'
342
+ }
343
+ }, /*#__PURE__*/React.createElement(Position, {
344
+ placement: "start",
345
+ constrain: "scroll-parent",
346
+ mountNode: () => document.getElementById('mountNode'),
347
+ onPositionChanged: onPositionChanged,
348
+ renderTarget: _button9 || (_button9 = /*#__PURE__*/React.createElement("button", {
349
+ "data-testid": "target"
350
+ }, "Target"))
351
+ }, _div12 || (_div12 = /*#__PURE__*/React.createElement("div", {
352
+ "data-testid": "content"
353
+ }, /*#__PURE__*/React.createElement("div", null, "Content")))))));
354
+ const target = screen.getByTestId('target');
355
+ const content = screen.getByTestId('content');
356
+ await waitFor(() => {
357
+ expect(onPositionChanged).toHaveBeenCalled();
358
+ });
359
+ const targetRect = target.getBoundingClientRect();
360
+ const contentRect = content.getBoundingClientRect();
361
+ expect(within(Math.floor(contentRect.left), Math.floor(targetRect.right), 1)).toBe(true);
362
+ });
363
+ it('should re-position before target', async () => {
364
+ const onPositionChanged = jest.fn();
365
+ render( /*#__PURE__*/React.createElement("div", {
366
+ style: {
367
+ padding: '50px'
368
+ }
369
+ }, _div13 || (_div13 = /*#__PURE__*/React.createElement("div", {
370
+ id: "mountNode"
371
+ }, "mount")), /*#__PURE__*/React.createElement("div", {
372
+ style: {
373
+ width: '50px',
374
+ height: '50px',
375
+ overflow: 'scroll',
376
+ padding: '50px 0px 50px 80px'
377
+ }
378
+ }, /*#__PURE__*/React.createElement(Position, {
379
+ placement: "end",
380
+ constrain: "scroll-parent",
381
+ mountNode: () => document.getElementById('mountNode'),
382
+ onPositionChanged: onPositionChanged,
383
+ renderTarget: _button10 || (_button10 = /*#__PURE__*/React.createElement("button", {
384
+ "data-testid": "target"
385
+ }, "Target"))
386
+ }, _div14 || (_div14 = /*#__PURE__*/React.createElement("div", {
387
+ "data-testid": "content"
388
+ }, /*#__PURE__*/React.createElement("div", null, "Content")))))));
389
+ const target = screen.getByTestId('target');
390
+ const content = screen.getByTestId('content');
391
+ await waitFor(() => {
392
+ expect(onPositionChanged).toHaveBeenCalled();
393
+ });
394
+ const targetRect = target.getBoundingClientRect();
395
+ const contentRect = content.getBoundingClientRect();
396
+ expect(within(Math.floor(contentRect.right), Math.floor(targetRect.left), 1)).toBe(true);
397
+ });
398
+ });
399
+ describe('when the documentElement is offset', () => {
400
+ beforeEach(() => {
401
+ document.documentElement.style.position = 'fixed';
402
+ document.documentElement.style.top = '-100px';
403
+ });
404
+ afterEach(() => {
405
+ document.documentElement.style.position = '';
406
+ document.documentElement.style.top = '';
407
+ });
408
+ it('should position correctly', async () => {
409
+ render( /*#__PURE__*/React.createElement("div", {
410
+ style: {
411
+ padding: '100px'
412
+ }
413
+ }, _Position3 || (_Position3 = /*#__PURE__*/React.createElement(Position, {
414
+ placement: "bottom",
415
+ renderTarget: /*#__PURE__*/React.createElement("button", {
416
+ "data-testid": "target"
417
+ }, "Target")
418
+ }, /*#__PURE__*/React.createElement("div", {
419
+ "data-testid": "content"
420
+ }, /*#__PURE__*/React.createElement("div", null, "Content"))))));
421
+ const target = screen.getByTestId('target');
422
+ const content = screen.getByTestId('content');
423
+ await waitFor(() => {
424
+ expect(content.getBoundingClientRect().top).toEqual(target.getBoundingClientRect().bottom);
425
+ });
426
+ });
427
+ it('should position correctly with mountNode', async () => {
428
+ render( /*#__PURE__*/React.createElement("div", {
429
+ style: {
430
+ padding: '100px'
431
+ }
432
+ }, _div15 || (_div15 = /*#__PURE__*/React.createElement("div", {
433
+ "data-testid": "mountNode"
434
+ }, "mount")), /*#__PURE__*/React.createElement("div", {
435
+ style: {
436
+ width: '50px',
437
+ height: '50px',
438
+ overflow: 'scroll',
439
+ padding: '50px'
440
+ }
441
+ }, /*#__PURE__*/React.createElement(Position, {
442
+ placement: "bottom",
443
+ constrain: "scroll-parent",
444
+ mountNode: () => document.getElementById('mountNode'),
445
+ renderTarget: _button11 || (_button11 = /*#__PURE__*/React.createElement("button", {
446
+ "data-testid": "target"
447
+ }, "Target"))
448
+ }, _div16 || (_div16 = /*#__PURE__*/React.createElement("div", {
449
+ "data-testid": "content"
450
+ }, /*#__PURE__*/React.createElement("div", null, "Content")))))));
451
+ const target = screen.getByTestId('target');
452
+ const content = screen.getByTestId('content');
453
+ await waitFor(() => {
454
+ expect(content.getBoundingClientRect().top).toEqual(target.getBoundingClientRect().bottom);
455
+ });
456
+ });
457
+ });
458
+ describe('containerDisplay prop', () => {
459
+ it('should apply "inline-block"', () => {
460
+ const _render = render( /*#__PURE__*/React.createElement("div", {
461
+ style: {
462
+ padding: '50px'
463
+ }
464
+ }, /*#__PURE__*/React.createElement("div", {
465
+ style: {
466
+ ...parentDefaults
467
+ }
468
+ }, _Position4 || (_Position4 = /*#__PURE__*/React.createElement(Position, {
469
+ constrain: "window",
470
+ renderTarget: /*#__PURE__*/React.createElement("button", {
471
+ "data-testid": "target"
472
+ }, "Target"),
473
+ containerDisplay: "inline-block"
474
+ }, /*#__PURE__*/React.createElement("div", {
475
+ "data-testid": "content"
476
+ }, /*#__PURE__*/React.createElement("div", null, "Content"))))))),
477
+ container = _render.container;
478
+ const position = container.querySelector("span[class$='-position']");
479
+ const style = getComputedStyle(position);
480
+ expect(style.display).toEqual('inline-block');
481
+ });
482
+ it('should apply "block"', () => {
483
+ const _render2 = render( /*#__PURE__*/React.createElement("div", {
484
+ style: {
485
+ padding: '50px'
486
+ }
487
+ }, /*#__PURE__*/React.createElement("div", {
488
+ style: {
489
+ ...parentDefaults
490
+ }
491
+ }, _Position5 || (_Position5 = /*#__PURE__*/React.createElement(Position, {
492
+ constrain: "window",
493
+ renderTarget: /*#__PURE__*/React.createElement("button", {
494
+ "data-testid": "target"
495
+ }, "Target"),
496
+ containerDisplay: "block"
497
+ }, /*#__PURE__*/React.createElement("div", {
498
+ "data-testid": "content"
499
+ }, /*#__PURE__*/React.createElement("div", null, "Content"))))))),
500
+ container = _render2.container;
501
+ const position = container.querySelector("span[class$='-position']");
502
+ const style = getComputedStyle(position);
503
+ expect(style.display).toEqual('block');
504
+ });
505
+ });
506
+ });
@@ -0,0 +1,68 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import { mirrorHorizontalPlacement } from '../mirrorHorizontalPlacement';
26
+ import { placementPropValues } from '../PositionPropTypes';
27
+ import '@testing-library/jest-dom';
28
+ const mirrorHorizontallyAsArrayMap = [['top'], ['bottom'], ['end'], ['start'], ['top', 'end'], ['top', 'center'], ['top', 'start'], ['top', 'stretch'], ['bottom', 'end'], ['bottom', 'center'], ['bottom', 'start'], ['bottom', 'stretch'], ['end', 'top'], ['end', 'center'], ['end', 'bottom'], ['end', 'stretch'], ['start', 'top'], ['start', 'center'], ['start', 'bottom'], ['start', 'stretch'], ['center', 'end'], ['center', 'start'], ['offscreen']];
29
+ describe('mirrorHorizontalPlacement', () => {
30
+ describe('when string is passed', () => {
31
+ describe('without delimiter should return mirrored values as array', () => {
32
+ placementPropValues.forEach((placement, idx) => {
33
+ it(placement, () => {
34
+ const mirrored = mirrorHorizontalPlacement(placement);
35
+ expect(mirrored[0]).toEqual(mirrorHorizontallyAsArrayMap[idx][0]);
36
+ expect(mirrored[1]).toEqual(mirrorHorizontallyAsArrayMap[idx][1]);
37
+ });
38
+ });
39
+ });
40
+ describe('with delimiter should return mirrored values as string', () => {
41
+ placementPropValues.forEach((placement, idx) => {
42
+ it(placement, () => {
43
+ const mirrored = mirrorHorizontalPlacement(placement, ' ');
44
+ expect(mirrored).toEqual(mirrorHorizontallyAsArrayMap[idx].join(' '));
45
+ });
46
+ });
47
+ });
48
+ });
49
+ describe('when array is passed', () => {
50
+ describe('without delimiter should return mirrored values as array', () => {
51
+ placementPropValues.forEach((placement, idx) => {
52
+ it(placement, () => {
53
+ const mirrored = mirrorHorizontalPlacement(placement.split(' '));
54
+ expect(mirrored[0]).toEqual(mirrorHorizontallyAsArrayMap[idx][0]);
55
+ expect(mirrored[1]).toEqual(mirrorHorizontallyAsArrayMap[idx][1]);
56
+ });
57
+ });
58
+ });
59
+ describe('with delimiter should return mirrored values as string', () => {
60
+ placementPropValues.forEach((placement, idx) => {
61
+ it(placement, () => {
62
+ const mirrored = mirrorHorizontalPlacement(placement.split(' '), ' ');
63
+ expect(mirrored).toEqual(mirrorHorizontallyAsArrayMap[idx].join(' '));
64
+ });
65
+ });
66
+ });
67
+ });
68
+ });
@@ -0,0 +1,68 @@
1
+ /*
2
+ * The MIT License (MIT)
3
+ *
4
+ * Copyright (c) 2015 - present Instructure, Inc.
5
+ *
6
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ * of this software and associated documentation files (the "Software"), to deal
8
+ * in the Software without restriction, including without limitation the rights
9
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ * copies of the Software, and to permit persons to whom the Software is
11
+ * furnished to do so, subject to the following conditions:
12
+ *
13
+ * The above copyright notice and this permission notice shall be included in all
14
+ * copies or substantial portions of the Software.
15
+ *
16
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ * SOFTWARE.
23
+ */
24
+
25
+ import { mirrorPlacement } from '../mirrorPlacement';
26
+ import { placementPropValues } from '../PositionPropTypes';
27
+ import '@testing-library/jest-dom';
28
+ const mirrorVertiallyAsArrayMap = [['bottom'], ['top'], ['end'], ['start'], ['bottom', 'start'], ['bottom', 'center'], ['bottom', 'end'], ['bottom', 'stretch'], ['top', 'start'], ['top', 'center'], ['top', 'end'], ['top', 'stretch'], ['end', 'top'], ['end', 'center'], ['end', 'bottom'], ['end', 'stretch'], ['start', 'top'], ['start', 'center'], ['start', 'bottom'], ['start', 'stretch'], ['center', 'start'], ['center', 'end'], ['offscreen']];
29
+ describe('mirrorPlacement', () => {
30
+ describe('when string is passed', () => {
31
+ describe('without delimiter should return mirrored values as array', () => {
32
+ placementPropValues.forEach((placement, idx) => {
33
+ it(placement, () => {
34
+ const mirrored = mirrorPlacement(placement);
35
+ expect(mirrored[0]).toEqual(mirrorVertiallyAsArrayMap[idx][0]);
36
+ expect(mirrored[1]).toEqual(mirrorVertiallyAsArrayMap[idx][1]);
37
+ });
38
+ });
39
+ });
40
+ describe('with delimiter should return mirrored values as string', () => {
41
+ placementPropValues.forEach((placement, idx) => {
42
+ it(placement, () => {
43
+ const mirrored = mirrorPlacement(placement, ' ');
44
+ expect(mirrored).toEqual(mirrorVertiallyAsArrayMap[idx].join(' '));
45
+ });
46
+ });
47
+ });
48
+ });
49
+ describe('when array is passed', () => {
50
+ describe('without delimiter should return mirrored values as array', () => {
51
+ placementPropValues.forEach((placement, idx) => {
52
+ it(placement, () => {
53
+ const mirrored = mirrorPlacement(placement.split(' '));
54
+ expect(mirrored[0]).toEqual(mirrorVertiallyAsArrayMap[idx][0]);
55
+ expect(mirrored[1]).toEqual(mirrorVertiallyAsArrayMap[idx][1]);
56
+ });
57
+ });
58
+ });
59
+ describe('with delimiter should return mirrored values as string', () => {
60
+ placementPropValues.forEach((placement, idx) => {
61
+ it(placement, () => {
62
+ const mirrored = mirrorPlacement(placement.split(' '), ' ');
63
+ expect(mirrored).toEqual(mirrorVertiallyAsArrayMap[idx].join(' '));
64
+ });
65
+ });
66
+ });
67
+ });
68
+ });