Skip to content

Commit 992e777

Browse files
committed
Test dropNLastRounds
1 parent bf81c5b commit 992e777

File tree

1 file changed

+151
-0
lines changed

1 file changed

+151
-0
lines changed

tests/dropNLastRounds.test.js

+151
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,151 @@
1+
/**
2+
* @jest-environment jsdom
3+
*/
4+
5+
global.ResizeObserver = require('resize-observer-polyfill')
6+
const { init } = require('./utils.js')
7+
8+
afterEach(jest.clearAllMocks)
9+
10+
test(`renders normal number of rounds when dropNLastRounds is not specified`, () => {
11+
12+
const data = {
13+
rounds: [{}, {}, {}],
14+
matches: [],
15+
}
16+
const { wrapper } = init(data)
17+
expect(wrapper.querySelectorAll('.round-wrapper').length).toBe(data.rounds.length)
18+
})
19+
20+
test(`renders normal number of rounds when dropNLastRounds is provided as 0`, () => {
21+
22+
const data = {
23+
rounds: [{}, {}, {}],
24+
matches: [],
25+
}
26+
const { wrapper } = init(data, { dropNLastRounds: 0 })
27+
expect(wrapper.querySelectorAll('.round-wrapper').length).toBe(data.rounds.length)
28+
})
29+
30+
test(`renders a number of rounds reduced by dropNLastRounds`, () => {
31+
32+
const data = {
33+
rounds: [{}, {}, {}, {}, {}],
34+
matches: [],
35+
}
36+
const { wrapper } = init(data, { dropNLastRounds: 2 })
37+
expect(wrapper.querySelectorAll('.round-wrapper').length).toBe(3)
38+
})
39+
40+
test(`renders a number of rounds reduced by dropNLastRounds when data.rounds was extended due to the number of 1st round matches`, () => {
41+
42+
const data = {
43+
rounds: [{}, {}, {}, {}, {}],
44+
matches: [{
45+
roundIndex: 0,
46+
order: 52,
47+
}],
48+
}
49+
const { wrapper } = init(data, { dropNLastRounds: 2 })
50+
expect(wrapper.querySelectorAll('.round-wrapper').length).toBe(5)
51+
})
52+
53+
test(`When n last rounds gets dropped, navigation on click is limited accordingly`, () => {
54+
55+
const data = {
56+
rounds: [{}, {}, {}, {}, {}],
57+
matches: [],
58+
}
59+
const { wrapper, bracket: br } = init(data, { dropNLastRounds: 2, visibleRoundsCount: 2 })
60+
61+
wrapper.querySelector('.navigation-button.right')
62+
.dispatchEvent(new MouseEvent('click', { bubbles: true }))
63+
wrapper.querySelector('.navigation-button.right')
64+
.dispatchEvent(new MouseEvent('click', { bubbles: true }))
65+
wrapper.querySelector('.navigation-button.right')
66+
.dispatchEvent(new MouseEvent('click', { bubbles: true }))
67+
68+
expect(br.getNavigationState().baseRoundIndex).toBe(1)
69+
70+
const all_rounds = [...wrapper.querySelectorAll('.round-wrapper')]
71+
expect(getComputedStyle(all_rounds[0]).visibility).toBe('hidden')
72+
expect(getComputedStyle(all_rounds[2]).visibility).toBe('visible')
73+
})
74+
75+
76+
test(`When n last rounds gets dropped, navigation by moveToNextRound is limited accordingly`, () => {
77+
78+
const data = {
79+
rounds: [{}, {}, {}, {}, {}],
80+
matches: [],
81+
}
82+
const { wrapper, bracket: br } = init(data, { dropNLastRounds: 2, visibleRoundsCount: 2 })
83+
84+
br.moveToNextRound()
85+
br.moveToNextRound()
86+
br.moveToNextRound()
87+
88+
expect(br.getNavigationState().baseRoundIndex).toBe(1)
89+
90+
const all_rounds = [...wrapper.querySelectorAll('.round-wrapper')]
91+
expect(getComputedStyle(all_rounds[0]).visibility).toBe('hidden')
92+
expect(getComputedStyle(all_rounds[2]).visibility).toBe('visible')
93+
})
94+
95+
96+
test(`When n last rounds gets dropped, moveToLastRound navigates to the reduced last round`, () => {
97+
const data = {
98+
rounds: [{}, {}, {}, {}, {}],
99+
matches: [],
100+
}
101+
const { bracket: br } = init(data, { dropNLastRounds: 2, visibleRoundsCount: 2 })
102+
103+
br.moveToLastRound()
104+
expect(br.getNavigationState().baseRoundIndex).toBe(1)
105+
})
106+
107+
108+
test(`When n last rounds gets dropped, lastRoundIsFullyVisible is correct`, () => {
109+
const data = {
110+
rounds: [{}, {}, {}, {}, {}, {}],
111+
matches: [],
112+
}
113+
const { bracket: br } = init(data, { dropNLastRounds: 2, visibleRoundsCount: 2 })
114+
115+
br.moveToNextRound()
116+
expect(br.getNavigationState().lastRoundIsFullyVisible).toBe(false)
117+
br.moveToNextRound()
118+
expect(br.getNavigationState().lastRoundIsFullyVisible).toBe(true)
119+
})
120+
121+
test('hides nav buttons on initialization if reduced rounds count is <= options.visibleRoundsCount', () => {
122+
const data = {
123+
rounds: [{}, {}, {}, {}, {}, {}],
124+
matches: [],
125+
}
126+
127+
const { wrapper } = init(data, { dropNLastRounds: 2, visibleRoundsCount: 4 })
128+
expect(wrapper.querySelectorAll('.navigation-button.hidden').length).toBe(2)
129+
})
130+
131+
test(`When n last rounds gets dropped, right nav button is disabled when necessary`, () => {
132+
const data = {
133+
rounds: [{}, {}, {}, {}, {}, {}],
134+
matches: [],
135+
}
136+
const { wrapper, bracket: br } = init(data, { dropNLastRounds: 2, visibleRoundsCount: 2 })
137+
138+
br.moveToNextRound()
139+
expect(
140+
wrapper.querySelector('.navigation-button.right').classList.contains('active')
141+
).toBe(true)
142+
143+
br.moveToNextRound()
144+
expect(
145+
wrapper.querySelector('.navigation-button.right').classList.contains('active')
146+
).toBe(false)
147+
})
148+
149+
// hides nav buttons when reduced tournament is narrower than the screen
150+
151+
// right nav button enabled/disabled

0 commit comments

Comments
 (0)