Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit fdc015e

Browse files
committedMay 3, 2021
Last changes
1 parent b24b05d commit fdc015e

File tree

8 files changed

+59
-32
lines changed

8 files changed

+59
-32
lines changed
 
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1 @@
1-
2-
console.log("Hello");
1+
function camelize(str) {return str.split('-').map((word, index) => index == 0 ? word : word[0].toUpperCase() + word.slice(1)).join('');}
Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,10 @@
11
function camelize(str) {
2-
/* your code */
3-
}
2+
return str
3+
.split('-') // разбивает 'my-long-word' на массив ['my', 'long', 'word']
4+
.map(
5+
// Переводит в верхний регистр первые буквы всех элементом массива за исключением первого
6+
// превращает ['my', 'long', 'word'] в ['my', 'Long', 'Word']
7+
(word, index) => index == 0 ? word : word[0].toUpperCase() + word.slice(1)
8+
)
9+
.join(''); // соединяет ['my', 'Long', 'Word'] в 'myLongWord'
10+
}
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,18 @@
11
describe("camelize", function() {
22

33
it("leaves an empty line as is", function() {
4-
assert.equal(camelize(""), "");
4+
expect(camelize("")).toEqual("");
55
});
66

77
it("turns background-color into backgroundColor", function() {
8-
assert.equal(camelize("background-color"), "backgroundColor");
8+
expect(camelize("background-color")).toEqual(["background", "color"])
99
});
1010

1111
it("turns list-style-image into listStyleImage", function() {
12-
assert.equal(camelize("list-style-image"), "listStyleImage");
12+
expect(camelize("list-style-image")).toEqual("listStyleImage");
1313
});
1414

1515
it("turns -webkit-transition into WebkitTransition", function() {
16-
assert.equal(camelize("-webkit-transition"), "WebkitTransition");
16+
expect(camelize("-webkit-transition")).toEqual("WebkitTransition")
1717
});
18-
19-
});
18+
});

‎1-js/02-b/1-b1/2-hoverintent/solution/hoverIntent.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
class HoverIntent {
1+
export default class HoverIntent {
22

33
constructor({
44
sensitivity = 0.1, // speed less than 0.1px/ms means "hovering over an element"

‎1-js/02-b/1-b1/2-hoverintent/source/hoverIntent.js

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
// Here's a brief sketch of the class
22
// with things that you'll need anyway
3-
class HoverIntent {
3+
export default class HoverIntent {
44

55
constructor({
66
sensitivity = 0.1, // speed less than 0.1px/ms means "hovering over an element"
@@ -25,12 +25,9 @@ class HoverIntent {
2525
elem.addEventListener("mouseout", this.onMouseOut);
2626

2727
// continue from this point
28-
2928
}
3029

3130
onMouseOver(event) {
32-
console.error(console.log);
33-
3431
console.log("OVER", event);
3532
/* ... */
3633
}

‎1-js/02-b/1-b1/2-hoverintent/source/index.html

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
<link rel="stylesheet" href="style.css">
2-
<script src="hoverIntent.js"></script>
32

43
<div id="elem" class="clock">
54
<span class="hours">12</span> :
@@ -9,7 +8,9 @@
98

109
<div id="tooltip" hidden>Tooltip</div>
1110

12-
<script>
11+
<script type="module">
12+
import HoverIntent from './hoverIntent.js';
13+
1314
new HoverIntent({
1415
elem,
1516
over() {
@@ -21,4 +22,4 @@
2122
tooltip.hidden = true;
2223
}
2324
});
24-
</script>
25+
</script>
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
<!DOCTYPE html>
2+
<link rel="stylesheet" href="style.css">
3+
<link rel="stylesheet" href="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.5.0/jasmine.css">
4+
5+
<!--<script src="https://cdnjs.cloudflare.com/ajax/libs/sinon.js/9.0.3/sinon.min.js"></script>-->
6+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.5.0/jasmine.js"></script>
7+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.5.0/jasmine-html.js"></script>
8+
<script src="https://cdnjs.cloudflare.com/ajax/libs/jasmine/3.5.0/boot.js"></script>
9+
10+
<link rel="stylesheet" href="style.css">
11+
12+
<script type="module" src="test.js"></script>
13+
14+
<div id="elem" class="clock">
15+
<span class="hours">12</span> :
16+
<span class="minutes">30</span> :
17+
<span class="seconds">00</span>
18+
</div>
19+
20+
21+
<div id="tooltip" hidden>Tooltip</div>
22+

‎1-js/02-b/1-b1/2-hoverintent/source/test.js

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
describe("hoverIntent", function() {
1+
import HoverIntent from './hoverIntent.js';
22

3+
describe("hoverIntent", function() {
34
function mouse(eventType, x, y, options) {
45
let eventOptions = Object.assign({
56
bubbles: true,
@@ -16,14 +17,15 @@ describe("hoverIntent", function() {
1617

1718
let isOver;
1819
let hoverIntent;
20+
let clock;
1921

2022

21-
before(function() {
22-
this.clock = sinon.useFakeTimers();
23+
beforeAll(function() {
24+
clock = jasmine.clock().install();
2325
});
2426

25-
after(function() {
26-
this.clock.restore();
27+
afterAll(function() {
28+
clock.uninstall();
2729
});
2830

2931

@@ -49,13 +51,13 @@ describe("hoverIntent", function() {
4951

5052
it("mouseover -> when the pointer just arrived, no tooltip", function() {
5153
mouse('mouseover', 10, 10);
52-
assert.isFalse(isOver);
54+
expect(isOver).toBeFalse();
5355
});
5456

5557
it("mouseover -> after a delay, the tooltip shows up", function() {
5658
mouse('mouseover', 10, 10);
57-
this.clock.tick(100);
58-
assert.isTrue(isOver);
59+
clock.tick(100);
60+
expect(isOver).toBeTrue();
5961
});
6062

6163
it("mouseover -> followed by fast mouseout leads doesn't show tooltip", function() {
@@ -64,8 +66,8 @@ describe("hoverIntent", function() {
6466
() => mouse('mouseout', 300, 300, { relatedTarget: document.body}),
6567
30
6668
);
67-
this.clock.tick(100);
68-
assert.isFalse(isOver);
69+
clock.tick(100);
70+
expect(isOver).toBeFalse();
6971
});
7072

7173

@@ -77,8 +79,8 @@ describe("hoverIntent", function() {
7779
i
7880
);
7981
}
80-
this.clock.tick(200);
81-
assert.isTrue(isOver);
82+
clock.tick(200);
83+
expect(isOver).toBeTrue();
8284
});
8385

8486
it("mouseover -> fast move -> no tooltip", function() {
@@ -89,8 +91,8 @@ describe("hoverIntent", function() {
8991
i
9092
);
9193
}
92-
this.clock.tick(200);
93-
assert.isFalse(isOver);
94+
clock.tick(200);
95+
expect(isOver).toBeTrue();
9496
});
9597

9698
});

0 commit comments

Comments
 (0)
Please sign in to comment.