-
Notifications
You must be signed in to change notification settings - Fork 58
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
Showing
16 changed files
with
2,060 additions
and
1,904 deletions.
There are no files selected for viewing
Large diffs are not rendered by default.
Oops, something went wrong.
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,24 @@ | ||
// @ts-expect-error | ||
import { assert } from '@japa/assert' | ||
// @ts-expect-error | ||
import { configure, processCLIArgs, run } from '@japa/runner' | ||
import chrome from 'sinon-chrome' | ||
|
||
processCLIArgs(process.argv.splice(2)) | ||
configure({ | ||
files: ['src/**/*.spec.js'], | ||
plugins: [ | ||
assert(), | ||
async () => { | ||
// @ts-expect-error | ||
global.location = new URL('https://www.faceit.com') | ||
|
||
// @ts-expect-error | ||
global.chrome = chrome | ||
|
||
global.chrome.runtime.id = 'testid' | ||
}, | ||
], | ||
}) | ||
|
||
run() |
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,47 @@ | ||
import { test } from '@japa/runner' | ||
import { parseHTML } from 'linkedom' | ||
import sinon from 'sinon' | ||
import { hasFeatureAttribute } from '../helpers/dom-element' | ||
import clickModalMatchReady, { FEATURE_NAME } from './click-modal-match-ready' | ||
|
||
const faceitEnvs = [ | ||
{ | ||
env: 'faceit', | ||
html: '<div class="FuseModalPortal"><div class="sc-bklklh NYiAz"><div class="sc-blFMiU fwcYfZ"><div class="sc-cdoIaK gaeZTF"><h5 size="5" class="sc-dIHSXr eCRPLL sc-fGdiLE lDkFc">Match ready</h5><div class="sc-cdoIaK gaeZTF"><div class="MatchCheckInModal__Holder-sc-yu96n5-0 daGuZS"><div class="MatchCheckInModal__Row-sc-yu96n5-1 dZVETa"><span class="sc-cbPlza bctuZo"><span class="sc-cbPlza fwYLNG">Confirm your match</span> <br> for the <span class="sc-cbPlza MatchCheckInModal__TextPrimary-sc-yu96n5-3 fwYLNG jOluuF">Repeek</span></span></div><div class="MatchCheckInModal__Row-sc-yu96n5-1 dZVETa"><span class="sc-cbPlza jxujzL">Expires in:</span></div><div class="CircleCountdown__CircleSpinner-sc-r4xxuy-0 gAAWfG"><div class="CircleCountdown__CircleValue-sc-r4xxuy-2 hpeccx"><span class="sc-cbPlza CircleCountdown__StyledText-sc-r4xxuy-3 fwYLNG ixeNii">81</span></div><div class="CircleCountdown__CircleOuter-sc-r4xxuy-1 kAHaiS"></div></div></div></div></div><div class="sc-cbelJu UPaKd"><div class="sc-ifjxht ixStst"><button class="sc-bypJrT djmUHF sc-ddjGPC dzWORN">Accept</button></div></div></div></div></div>', | ||
}, | ||
{ | ||
env: 'faceit beta', | ||
html: '<div class="FuseModalPortal"><div class="styles__Backdrop-sc-664e1c0f-0 fngpeO"><div class="styles__ModalWrapper-sc-664e1c0f-5 dvvnKY"><div class="styles__ModalContent-sc-664e1c0f-6 bwnBtX"><h5 size="5" class="HeadingBase-sc-e48327c2-0 bNWKuw styles__ModalTitle-sc-664e1c0f-1 dvUFkO">Match ready</h5><div class="styles__ModalContent-sc-664e1c0f-6 bwnBtX"><div class="MatchCheckInModal__Holder-sc-dcfe9dbf-0 bmHfST"><div class="MatchCheckInModal__Row-sc-dcfe9dbf-1 kIAsaH"><span class="Text-sc-f75cefb7-0 gjVnMO"><span class="Text-sc-f75cefb7-0 kcmOTI">Confirm your match</span> <br> for the <span class="Text-sc-f75cefb7-0 MatchCheckInModal__TextPrimary-sc-dcfe9dbf-3 kcmOTI czsWFE">Repeek</span></span></div><div class="MatchCheckInModal__Row-sc-dcfe9dbf-1 kIAsaH"><span class="Text-sc-f75cefb7-0 fRfakl">Expires in:</span></div><div class="CircleCountdown__CircleSpinner-sc-fdab6df8-0 epBeYb"><div class="CircleCountdown__CircleValue-sc-fdab6df8-2 indqqy"><span class="Text-sc-f75cefb7-0 CircleCountdown__StyledText-sc-fdab6df8-3 kcmOTI kTMQcx">81</span></div><div class="CircleCountdown__CircleOuter-sc-fdab6df8-1 gvtNmS"></div></div></div></div></div><div class="styles__ModalActions-sc-664e1c0f-3 jvlAUO"><div class="styles__ModalMainActions-sc-664e1c0f-4 cnaJxg"><button class="ButtonBase__Wrapper-sc-9fae6077-0 bwdpsX Button__Base-sc-bcb6f5c8-0 gWLpuZ">Accept</button></div></div></div></div></div>', | ||
}, | ||
] | ||
|
||
test.group(FEATURE_NAME, () => { | ||
test('sets feature attribute - {env}') | ||
.with(faceitEnvs) | ||
.run(async ({ assert }, { html }) => { | ||
const { document } = parseHTML(html) | ||
|
||
await clickModalMatchReady({ baseElement: document }) | ||
|
||
assert.isTrue( | ||
hasFeatureAttribute( | ||
FEATURE_NAME, | ||
document.querySelector('.FuseModalPortal'), | ||
), | ||
) | ||
}) | ||
|
||
test('clicks accept button - {env}') | ||
.with(faceitEnvs) | ||
.run(async ({ assert }, { html }) => { | ||
const { document } = parseHTML(html) | ||
|
||
const acceptButton = document.querySelector('button') | ||
|
||
acceptButton.onclick = sinon.spy() | ||
|
||
await clickModalMatchReady({ baseElement: document }) | ||
|
||
assert.isTrue(acceptButton.onclick.calledOnce) | ||
}) | ||
}) |
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
55 changes: 55 additions & 0 deletions
55
src/content/features/click-modal-party-invite-accept.spec.js
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,55 @@ | ||
import { test } from '@japa/runner' | ||
import { parseHTML } from 'linkedom' | ||
import sinon from 'sinon' | ||
import { hasFeatureAttribute } from '../helpers/dom-element' | ||
import clickModalPartyInviteAccept, { | ||
FEATURE_NAME, | ||
} from './click-modal-party-invite-accept' | ||
|
||
const faceitEnvs = [ | ||
{ | ||
env: 'faceit', | ||
html: '<div class="ReactModalPortal"><div class="ReactModal__Overlay ReactModal__Overlay--after-open" style="position: fixed; inset: 0px; background-color: rgba(0, 0, 0, 0.6); justify-content: center; align-items: flex-start; display: flex; overflow: auto; z-index: 1060;"><div class="ReactModal__Content ReactModal__Content--after-open" tabindex="-1" role="dialog" aria-modal="true" style="position: static; inset: inherit; border: none; background: none; overflow: visible; border-radius: inherit; outline: none; padding: 0px;"><div class="sc-jGONNV eeOWko"><div class="sc-dEMAZk eRZiMf"><h5 size="5" class="sc-dIHSXr eCRPLL sc-lopPiv dTBdcK">Invite to <span class="sc-imJffE hLozcV">party</span></h5><div class="sc-iugpza Txjh"><button class="sc-bypJrT djmUHF sc-ddjGPC gQPuSg"><i class="sc-iHbSHJ jkbxap"><svg viewBox="0 0 8 8" xmlns="http://www.w3.org/2000/svg" color="white" height="16" width="16" class="sc-klVQfs gdbspr"><path d="M8 7.025L4.939 3.994 7.969.936 7.025 0l-3.03 3.06L.937.03 0 .967l3.062 3.035L.03 7.063.967 8l3.037-3.064 3.06 3.033z" fill="currentColor"></path></svg></i></button></div></div><div class="sc-gMFoeA echMrx"><div class="sc-DwsMf gDFJfT"><div class="sc-dXHaLi iAwINc sc-cwsewg fZDMEu" size="80"><img aria-label="avatar" async="" src="https://distribution.faceit-cdn.net/images/657b4f34-9aa7-40a2-a9e4-c6a55d2e37ee.jpeg" class="sc-fRLnnz jeta-dZ"></div><div class="sc-ebpHGS BJPam"><span class="sc-cbPlza fwYLNG">DACHEC_Bot invited you to join their party</span><span class="sc-cbPlza bctuZo">Click accept to join the party</span><span class="sc-cbPlza bctuZo">Time remaining: 11</span></div></div><div class="sc-jaZhys dcznqn"><div class="sc-eOPQkR kCAsay"><button class="sc-bypJrT djmUHF sc-ddjGPC iXRFJh">Decline</button><button class="sc-bypJrT djmUHF sc-ddjGPC dzWORN">Accept</button></div></div></div></div></div></div></div>', | ||
}, | ||
{ | ||
env: 'faceit beta', | ||
html: '<div class="ReactModalPortal"><div class="ReactModal__Overlay ReactModal__Overlay--after-open" style="position: fixed; inset: 0px; background-color: rgba(0, 0, 0, 0.6); justify-content: center; align-items: flex-start; display: flex; overflow: auto; z-index: 1060;"><div class="ReactModal__Content ReactModal__Content--after-open" tabindex="-1" role="dialog" aria-modal="true" style="position: static; inset: inherit; border: none; background: none; overflow: visible; border-radius: inherit; outline: none; padding: 0px;"><div class="modal-next__Container-sc-b6f0d17-0 ZrgS"><div class="Header__HeaderHolder-sc-2cc7dc89-0 buHuYI"><h5 size="5" class="HeadingBase-sc-e48327c2-0 bNWKuw Header__HeaderText-sc-2cc7dc89-1 jPWORZ">Invite to <span class="style__PrimaryText-sc-918d2fcb-4 djldSF">party</span></h5><div class="Header__CloseButtonContainer-sc-2cc7dc89-2 erCApM"><button class="ButtonBase__Wrapper-sc-9fae6077-0 bwdpsX Button__Base-sc-bcb6f5c8-0 gnShNk"><i class="Icon__Holder-sc-cac5ab18-0 CUA-DS"><svg viewBox="0 0 8 8" xmlns="http://www.w3.org/2000/svg" color="white" height="16" width="16" class="Icon__StyledISvg-sc-cac5ab18-1 etGOee"><path d="M8 7.025L4.939 3.994 7.969.936 7.025 0l-3.03 3.06L.937.03 0 .967l3.062 3.035L.03 7.063.967 8l3.037-3.064 3.06 3.033z" fill="currentColor"></path></svg></i></button></div></div><div class="modal-next__Body-sc-b6f0d17-1 bOphMK"><div class="style__Holder-sc-918d2fcb-1 hEeDFz"><div class="Avatar__AvatarHolder-sc-89ce63d3-1 ejzlkk style__Avatar-sc-918d2fcb-0 hprtIr" size="80"><img aria-label="avatar" async="" src="https://distribution.faceit-cdn.net/images/657b4f34-9aa7-40a2-a9e4-c6a55d2e37ee.jpeg" class="Avatar__Image-sc-89ce63d3-2 hNxHpG"></div><div class="style__TextHolder-sc-918d2fcb-2 liNDFA"><span class="Text-sc-f75cefb7-0 kcmOTI">DACHEC_Bot invited you to join their party</span><span class="Text-sc-f75cefb7-0 gjVnMO">Click accept to join the party</span><span class="Text-sc-f75cefb7-0 gjVnMO">Time remaining: 7</span></div></div><div class="modal-next__Footer-sc-b6f0d17-2 fwatWi"><div class="style__ActionsHolder-sc-918d2fcb-3 laOydE"><button class="ButtonBase__Wrapper-sc-9fae6077-0 bwdpsX Button__Base-sc-bcb6f5c8-0 hgGeBh">Decline</button><button class="ButtonBase__Wrapper-sc-9fae6077-0 bwdpsX Button__Base-sc-bcb6f5c8-0 gWLpuZ">Accept</button></div></div></div></div></div></div></div>', | ||
}, | ||
] | ||
|
||
test.group(FEATURE_NAME, () => { | ||
test('sets feature attribute - {env}') | ||
.with(faceitEnvs) | ||
.run(async ({ assert }, faceitEnv) => { | ||
const { document } = parseHTML(faceitEnv.html) | ||
|
||
await clickModalPartyInviteAccept({ | ||
isFaceitBeta: faceitEnv.env === faceitEnvs[1].env, | ||
baseElement: document, | ||
}) | ||
|
||
assert.isTrue( | ||
hasFeatureAttribute( | ||
FEATURE_NAME, | ||
document.querySelector('.ReactModalPortal'), | ||
), | ||
) | ||
}) | ||
|
||
test('clicks accept button - {env}') | ||
.with(faceitEnvs) | ||
.run(async ({ assert }, faceitEnv) => { | ||
const { document } = parseHTML(faceitEnv.html) | ||
|
||
const acceptButton = document.querySelectorAll('button')[2] | ||
|
||
acceptButton.onclick = sinon.spy() | ||
|
||
await clickModalPartyInviteAccept({ | ||
isFaceitBeta: faceitEnv.env === faceitEnvs[1].env, | ||
baseElement: document, | ||
}) | ||
|
||
assert.isTrue(acceptButton.onclick.calledOnce) | ||
}) | ||
}) |
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,76 @@ | ||
import { test } from '@japa/runner' | ||
import { estimateRatingChange, predictRatingChange } from './elo' | ||
|
||
test.group('elo', () => { | ||
test('estimateRatingChange', ({ assert }) => { | ||
assert.deepEqual(estimateRatingChange(2000, 2000), { | ||
gain: 25, | ||
loss: -25, | ||
}) | ||
|
||
assert.deepEqual(estimateRatingChange(5000, 1000), { | ||
gain: 1, | ||
loss: -50, | ||
}) | ||
|
||
assert.deepEqual(estimateRatingChange(1000, 5000), { | ||
gain: 50, | ||
loss: -1, | ||
}) | ||
|
||
assert.strictEqual(estimateRatingChange(1853, 1159).gain, 1) | ||
assert.strictEqual(estimateRatingChange(1836, 1726).gain, 17) | ||
assert.strictEqual(estimateRatingChange(1813, 1789).gain, 23) | ||
assert.strictEqual(estimateRatingChange(1750, 1669).loss, -31) | ||
assert.strictEqual(estimateRatingChange(1775, 1602).gain, 13) | ||
assert.strictEqual(estimateRatingChange(1754, 1703).gain, 21) | ||
assert.strictEqual(estimateRatingChange(1781, 1685).loss, -32) | ||
assert.strictEqual(estimateRatingChange(1811, 1746).loss, -30) | ||
assert.strictEqual(estimateRatingChange(1877, 1875).loss, -25) | ||
assert.strictEqual(estimateRatingChange(1871, 1870).gain, 25) | ||
assert.strictEqual(estimateRatingChange(1727, 1639).loss, -31) | ||
}) | ||
|
||
test('estimateRatingChange is off by +-1', ({ assert }) => { | ||
assert.strictEqual(estimateRatingChange(1789, 1865).gain, 31) // Actual: 30 | ||
assert.strictEqual(estimateRatingChange(1907, 1816).loss, -32) // Actual: -31 | ||
assert.strictEqual(estimateRatingChange(1787, 1783).gain, 24) // Actual: 25 | ||
assert.strictEqual(estimateRatingChange(1781, 1721).gain, 20) // Actual: 21, | ||
assert.strictEqual(estimateRatingChange(2043, 1939).loss, -33) // Actual: -32 | ||
assert.strictEqual(estimateRatingChange(2134, 2073).loss, -30) // Actual: -29 | ||
}).fails() | ||
|
||
test('predictRatingChange', ({ assert }) => { | ||
assert.deepEqual(predictRatingChange(0.5), { | ||
gain: 25, | ||
loss: -25, | ||
}) | ||
|
||
assert.deepEqual(predictRatingChange(0.52), { | ||
gain: 24, | ||
loss: -26, | ||
}) | ||
assert.deepEqual(predictRatingChange(0.48), { | ||
gain: 26, | ||
loss: -24, | ||
}) | ||
|
||
assert.deepEqual(predictRatingChange(0.44), { | ||
gain: 28, | ||
loss: -22, | ||
}) | ||
assert.deepEqual(predictRatingChange(0.56), { | ||
gain: 22, | ||
loss: -28, | ||
}) | ||
|
||
assert.deepEqual(predictRatingChange(0.55), { | ||
gain: 22, | ||
loss: -28, | ||
}) | ||
assert.deepEqual(predictRatingChange(0.45), { | ||
gain: 28, | ||
loss: -22, | ||
}) | ||
}) | ||
}) |
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,11 @@ | ||
import { test } from '@japa/runner' | ||
import * as pages from './pages' | ||
|
||
test.group('pages', () => { | ||
test('isRoomOverview', ({ assert }) => { | ||
const path = 'en/csgo/room/466ece1d-9f16-4b64-aa2d-826c60bc022f' | ||
|
||
assert.isTrue(pages.isRoomOverview(path)) | ||
assert.isFalse(pages.isRoomOverview('')) | ||
}) | ||
}) |
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 { test } from '@japa/runner' | ||
import { mapAverageStats, mapTotalStats } from './stats' | ||
|
||
test.group('stats', () => { | ||
test('mapTotalStats', ({ assert }) => { | ||
const stats = { | ||
m1: 1, | ||
unnecessary: true, | ||
} | ||
|
||
assert.deepEqual(mapTotalStats(stats), { matches: stats.m1 }) | ||
}) | ||
|
||
test('mapAverageStats', ({ assert }) => { | ||
const createStat = (c2, c3, c4, i6, i2, teamId) => ({ | ||
c2: c2.toString(), | ||
c3: c3.toString(), | ||
c4: c4.toString(), | ||
i6: i6.toString(), | ||
i2, | ||
teamId, | ||
unnecessary: true, | ||
}) | ||
|
||
const stats = [ | ||
createStat(0.25, 0.27, 20, 6, '123', '123'), | ||
createStat(0.44, 0.32, 12, 8, '123', '345'), | ||
createStat(0.36, 0.41, 19, 9, '123', '123'), | ||
] | ||
|
||
assert.deepEqual(mapAverageStats(stats), { | ||
averageKDRatio: 0.35, | ||
averageKRRatio: 0.33, | ||
averageHeadshots: 17, | ||
averageKills: 8, | ||
winRate: 67, | ||
}) | ||
}) | ||
}) |
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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.