-
-
Notifications
You must be signed in to change notification settings - Fork 149
/
sortable-item-mixin-test.js
211 lines (171 loc) · 5.51 KB
/
sortable-item-mixin-test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import EmberObject from '@ember/object';
import { run } from '@ember/runloop';
import { module, test } from 'qunit';
import { setupRenderingTest } from 'ember-qunit';
import hbs from 'htmlbars-inline-precompile';
import Component from '@ember/component'
import SortableItemMixin from 'ember-sortable/mixins/sortable-item'
import { render } from '@ember/test-helpers';
const MockEvent = { originalEvent: null };
const MockModel = { name: 'Mock Model' };
const MockGroup = EmberObject.extend({
direction: 'y',
registerItem(item) {
this.item = item;
},
deregisterItem() {
delete this.item;
},
commit() {},
prepare() {},
update() {},
});
let group;
let subject;
module('sortable-item-mixin', function(hooks) {
// setupTest(hooks);
setupRenderingTest(hooks);
hooks.beforeEach(async function() {
const mockComponent = Component.extend(SortableItemMixin, {
classNames: ['test-mock-cmpt'],
didInsertElement() {
this._super()
subject = this
}
})
await run(async () => {
this.owner.register('component:test-mock', mockComponent)
group = MockGroup.create();
this.set('group', group)
this.set('rendered', true)
await render(hbs`{{#if rendered}}{{test-mock group=group}}{{/if}}`)
// run(() => subject.set('group', group))
});
});
test('isAnimated', async function(assert) {
// console.log({isAnimated: subject.get(('isAnimated'))})
subject.$().css({ transition: 'all' });
assert.equal(subject.get('isAnimated'), true);
subject.$().css({ transition: 'transform' });
assert.equal(subject.get('isAnimated'), true);
subject.$().css({ transition: 'color' });
assert.equal(subject.get('isAnimated'), false);
subject.$().css({ transition: 'none' });
assert.equal(subject.get('isAnimated'), false);
});
test('isDragging is disabled when destroyed', function(assert) {
assert.expect(2);
run(() => {
subject.set('model', MockModel);
assert.equal(subject.get('isDragging'), false, 'isDragging = false');
subject._startDrag(MockEvent);
assert.equal(subject.get('isDragging'), true, 'isDragging = true w/ Mocvvent');
});
});
test('transitionDuration', function(assert) {
subject.$().css({ transition: 'all .25s' });
assert.equal(subject.get('transitionDuration'), 250);
subject.$().css({ transition: 'all 250ms' });
assert.equal(subject.get('transitionDuration'), 250);
subject.$().css({ transition: 'all 0s' });
assert.equal(subject.get('transitionDuration'), 0);
subject.$().css({ transition: 'all 0ms' });
assert.equal(subject.get('transitionDuration'), 0);
subject.$().css({ transition: 'none' });
assert.equal(subject.get('transitionDuration'), 0);
});
test('get y', function(assert) {
assert.equal(subject.get('y'), subject.element.offsetTop,
'expected y to be element.offsetTop');
});
test('get x', function(assert) {
assert.equal(subject.get('x'), subject.element.offsetLeft,
'expected x to be element.offsetLeft');
});
test('set y', function(assert) {
run(() => {
subject.set('y', 50);
});
let transform = getTransform(subject.element);
assert.equal(transform, 'translateY(50px)',
'expected transform to be set');
assert.equal(subject.get('y'), 50,
'expected y to retain value');
});
test('set x', function(assert) {
run(() => {
group.set('direction', 'x');
subject.set('x', 50);
});
let transform = getTransform(subject.element);
assert.equal(transform, 'translateX(50px)',
'expected transform to be set to translateX');
assert.equal(subject.get('x'), 50,
'expected x to retain value');
});
test('height', function(assert) {
subject.$().css({
height: '50px',
marginTop: '10px',
marginBottom: '10px'
});
assert.equal(subject.get('height'), 60,
'expected height to be height + margin-bottom');
});
test('width', function(assert) {
subject.$().css({
width: '50px',
marginLeft: '10px',
marginRight: '10px'
});
assert.equal(subject.get('width'), 70,
'expected width to be width + margin-right + margin-left (like outerWidth)');
});
test('registers itself with group', function(assert) {
assert.equal(group.item, subject,
'expected to be registered with group');
});
test('deregisters itself when removed', function(assert) {
run(() => {
this.set('rendered', false)
});
assert.equal(group.item, undefined,
'expected to be deregistered with group');
});
test('dragStart fires an action if provided', function(assert) {
assert.expect(1);
const target = {
action(passedModel) {
assert.equal(passedModel, MockModel);
}
};
run(() => {
subject.set('model', MockModel);
subject.set('target', target);
subject.set('onDragStart', 'action');
subject._startDrag(MockEvent);
});
});
test('dragStop fires an action if provided', function(assert) {
assert.expect(1);
const target = {
action(passedModel) {
assert.equal(passedModel, MockModel);
}
};
run(() => {
subject.set('model', MockModel);
subject.set('target', target);
subject.set('onDragStop', 'action');
subject._complete();
});
});
function getTransform(element) {
let style = element.style;
return style.transform ||
style.mozTransform ||
style.msTransform ||
style.oTransform ||
style.webkitTransform;
}
});