-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
2ed6afc
commit 4eed770
Showing
7 changed files
with
174 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
function createEntry(place, scoreEntry) { | ||
let nickname = '-', | ||
correctNumber = '-', | ||
questionsNumber = '-'; | ||
|
||
if (scoreEntry !== undefined) { | ||
({ nickname, correctNumber, questionsNumber } = scoreEntry); | ||
} | ||
|
||
let div = document.createElement('div'); | ||
div.className = 'ranking-row'; | ||
div.innerHTML = ` | ||
<div class="place"> | ||
${place} | ||
</div> | ||
<div class="nickname"> | ||
${nickname} | ||
</div> | ||
<div class="score"> | ||
${correctNumber} / ${questionsNumber} | ||
</div> | ||
`; | ||
return div; | ||
} | ||
|
||
function createRankingHeader() { | ||
let div = document.createElement('div'); | ||
div.className = 'ranking-row'; | ||
div.style.fontWeight = 'bold'; | ||
div.innerHTML = ` | ||
<div class="place"> | ||
Place | ||
</div> | ||
<div class="nickname"> | ||
Player | ||
</div> | ||
<div class="score"> | ||
Answered | ||
</div> | ||
`; | ||
return div; | ||
} | ||
|
||
function createHeader() { | ||
let div = document.createElement('div'); | ||
div.className = 'icon-header'; | ||
div.setAttribute('data-testid', 'icon-header'); | ||
div.innerHTML = ` | ||
<img data-testid='ranking-icon' src="./static/assets/ui/contacts_24px.svg" alt="Ranking icon"> | ||
<p>Mode Ranking</p> | ||
`; | ||
return div; | ||
} | ||
|
||
function ranking(scoreList) { | ||
let parent = document.querySelector('.ranking-box'); | ||
|
||
let placeholders = []; | ||
const places = ['1st', '2nd', '3rd']; | ||
|
||
for (let place = 0; place < places.length; ++place) { | ||
placeholders.push(createEntry(places[place], scoreList[place])); | ||
} | ||
|
||
parent.appendChild(createHeader()); | ||
parent.appendChild(createRankingHeader()); | ||
placeholders.forEach((item) => parent.appendChild(item)); | ||
} | ||
|
||
export { ranking }; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
.ranking-box { | ||
background-color: white; | ||
font-size: 1.5rem; | ||
border-radius: var(--border-radius); | ||
width: 100%; | ||
height: 100%; | ||
padding: 2rem; | ||
box-shadow: var(--box-shadow-simple); | ||
} | ||
|
||
.icon-header { | ||
width: 100%; | ||
display: flex; | ||
flex-direction: row; | ||
justify-content: center; | ||
align-items: center; | ||
font-weight: bold; | ||
font-size: 2rem; | ||
} | ||
|
||
.icon-header > p { | ||
margin-left: 2rem; | ||
} | ||
|
||
.ranking-row { | ||
background-color: white; | ||
grid-column-gap: 10px; | ||
margin-bottom: 10px; | ||
display: grid; | ||
grid-template-columns: 15% 70% 15%; | ||
grid-template-areas: "place nickname score"; | ||
} | ||
|
||
.place { | ||
grid-area: place; | ||
} | ||
|
||
.nickname { | ||
grid-area: nickname; | ||
} | ||
|
||
.score { | ||
grid-area: score; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { getScores, saveScore } from '../../../src/app/logic/localStorageScore'; | ||
import { ranking } from '../../../src/app/components/ranking'; | ||
import { screen } from '@testing-library/dom'; | ||
import '@testing-library/jest-dom/extend-expect'; | ||
import { PEOPLE_MODE } from '../../../src/app/modes'; | ||
|
||
test('screen has four items of ranking-row', () => { | ||
document.body.innerHTML = `<div id="ranking-box" class="ranking-box"></div>`; | ||
ranking(getScores()); | ||
|
||
let rows = document.querySelectorAll('.ranking-row'); | ||
expect(rows.length).toBe(4); | ||
expect(); | ||
}); | ||
|
||
test('there is an img tag for icon', () => { | ||
document.body.innerHTML = `<div id="ranking-box" class="ranking-box"></div>`; | ||
ranking(getScores()); | ||
|
||
expect(screen.getByTestId('ranking-icon')).toBeTruthy(); | ||
}); | ||
|
||
test('there is Lucy and Nancy in HTML', () => { | ||
document.body.innerHTML = `<div id="ranking-box" class="ranking-box"></div>`; | ||
saveScore(PEOPLE_MODE, 'Nancy', 12, 30); | ||
saveScore(PEOPLE_MODE, 'Lucy', 14, 30); | ||
|
||
ranking(getScores(PEOPLE_MODE)); | ||
|
||
let nicknames = document.querySelectorAll('.nickname'); | ||
let scores = document.querySelectorAll('.score'); | ||
|
||
expect(nicknames[1].textContent.includes('Lucy')).toBeTruthy(); | ||
expect(nicknames[2].textContent.includes('Nancy')).toBeTruthy(); | ||
expect(nicknames[3].textContent.includes('-')).toBeTruthy(); | ||
expect(scores[1].textContent.includes('14 / 30')).toBeTruthy(); | ||
expect(scores[2].textContent.includes('12 / 30')).toBeTruthy(); | ||
expect(scores[3].textContent.includes('- / -')).toBeTruthy(); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters