Updated tests
This commit is contained in:
@ -4,5 +4,3 @@ import { tokenList } from "./tokenList";
|
|||||||
document.querySelector<HTMLDivElement>("#app")!.innerHTML = `
|
document.querySelector<HTMLDivElement>("#app")!.innerHTML = `
|
||||||
${tokenList()}
|
${tokenList()}
|
||||||
`;
|
`;
|
||||||
|
|
||||||
// setupTokenList(document.querySelector<HTMLDivElement>("#tokens")!);
|
|
||||||
|
@ -1,6 +1,6 @@
|
|||||||
// @vitest-environment jsdom
|
// @vitest-environment jsdom
|
||||||
|
|
||||||
import { assert, expect, test } from 'vitest'
|
import { expect, test } from 'vitest'
|
||||||
import {displayToken} from './token'
|
import {displayToken} from './token'
|
||||||
|
|
||||||
test('a 6 digit token is displayed', () => {
|
test('a 6 digit token is displayed', () => {
|
||||||
|
@ -9,16 +9,3 @@ test("displays correct account name", () => {
|
|||||||
expect(div.innerHTML).toContain("Github");
|
expect(div.innerHTML).toContain("Github");
|
||||||
});
|
});
|
||||||
|
|
||||||
test("displays multiple list items", () => {
|
|
||||||
const div: HTMLDivElement = document.createElement("div");
|
|
||||||
displayTokenListItem("Github", "ABCDEFGHIJKLMNOP", div);
|
|
||||||
displayTokenListItem("Gmail", "ABCDEFGHIJKLMNOP", div);
|
|
||||||
const tokens = [
|
|
||||||
{ account: "Github", secret: "blahblahblah" },
|
|
||||||
{ account: "Gmail", secret: "blahblahblah" },
|
|
||||||
];
|
|
||||||
tokens.map((token) => displayTokenListItem(token.account, token.secret, div));
|
|
||||||
console.log("dv", div.innerHTML);
|
|
||||||
expect(div.innerHTML).toContain("Github");
|
|
||||||
expect(div.innerHTML).toContain("Gmail");
|
|
||||||
});
|
|
||||||
|
@ -17,16 +17,15 @@ export function displayTokenListItem(
|
|||||||
secondsSinceStart = 0 + (secondsSinceEpoch % period);
|
secondsSinceStart = 0 + (secondsSinceEpoch % period);
|
||||||
secondsRemaining = period - (secondsSinceEpoch % period);
|
secondsRemaining = period - (secondsSinceEpoch % period);
|
||||||
const timerDiv = document.getElementById(`timer-${account}`);
|
const timerDiv = document.getElementById(`timer-${account}`);
|
||||||
const tokenDiv = document.getElementById(`secret-${account}`)
|
const tokenDiv = document.getElementById(`secret-${account}`);
|
||||||
if (timerDiv && tokenDiv) {
|
if (timerDiv && tokenDiv) {
|
||||||
timerDiv.innerHTML = secondsRemaining.toString();
|
timerDiv.innerHTML = secondsRemaining.toString();
|
||||||
timerDiv.style.background = `conic-gradient(transparent ${
|
timerDiv.style.background = `conic-gradient(transparent ${
|
||||||
(100 / 30) * secondsSinceStart
|
(100 / 30) * secondsSinceStart
|
||||||
}%, ${secondsRemaining < 10 ? "salmon" : "gainsboro"} 0)`;
|
}%, ${secondsRemaining < 10 ? "salmon" : "gainsboro"} 0)`;
|
||||||
token = displayToken(secret)
|
token = displayToken(secret);
|
||||||
tokenDiv.innerHTML = token;
|
tokenDiv.innerHTML = token;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
setInterval(() => {
|
setInterval(() => {
|
||||||
countdown();
|
countdown();
|
||||||
|
@ -1,28 +0,0 @@
|
|||||||
import { displayToken } from "./token";
|
|
||||||
|
|
||||||
class Timer {
|
|
||||||
constructor(public counter = 30, public element: HTMLDivElement, public account: string, public secret: string) {
|
|
||||||
|
|
||||||
let intervalId = setInterval(() => {
|
|
||||||
this.counter = this.counter - 1;
|
|
||||||
console.log(this.counter)
|
|
||||||
if(this.counter === 0) clearInterval(intervalId)
|
|
||||||
element.innerHTML = `<div class="fieldset-wrapper">
|
|
||||||
<fieldset>
|
|
||||||
<label>Account</label>
|
|
||||||
<p data-test-id="account">${account}</p>
|
|
||||||
</fieldset>
|
|
||||||
<fieldset>
|
|
||||||
<label>Code</label>
|
|
||||||
<p data-test-id="secret">${displayToken(secret)}</p>
|
|
||||||
</fieldset>
|
|
||||||
<fieldset>
|
|
||||||
<label></label>
|
|
||||||
<p>${this.counter}</p>
|
|
||||||
</div>`
|
|
||||||
return this.element
|
|
||||||
|
|
||||||
}, 1000)
|
|
||||||
}
|
|
||||||
}
|
|
||||||
export default Timer
|
|
Reference in New Issue
Block a user