Skip to content

Commit

Permalink
Fomat tests file.
Browse files Browse the repository at this point in the history
  • Loading branch information
przemek83 committed Nov 2, 2024
1 parent ea88ca1 commit 138f463
Showing 1 changed file with 96 additions and 84 deletions.
180 changes: 96 additions & 84 deletions test/ops.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,19 @@ const toTest = require('../js/ops.js');
const fs = require('fs');
const path = require('path');

const knightWithOrderText = '62\tArcyksiążę MichalOprych [IMP]\t198\t499.653.242\t169.323\t150.225\t15.954';
const knightWithoutOrderText = '20\tArcyksiążę William\t299\t1.041.479.270\t130.162\t127.406\t2.209';
const knightWithOrderText =
'62\tArcyksiążę MichalOprych [IMP]\t198\t499.653.242\t169.323\t150.225\t15.954';
const knightWithoutOrderText =
'20\tArcyksiążę William\t299\t1.041.479.270\t130.162\t127.406\t2.209';

describe('Knight', () => {
test('Knight in order creation', () => {
const knight = new toTest.Knight(knightWithOrderText);

expect(knight.name).toBe('Arcyksiążę MichalOprych ');
expect(knight.order).toBe('[IMP]');
expect(knight.level).toBe('198');
expect(knight.lootText).toBe("499.653.242");
expect(knight.lootText).toBe('499.653.242');
expect(knight.loot).toBe(499653242);
expect(knight.fights).toBe(169323);
expect(knight.win).toBe(150225);
Expand All @@ -25,11 +27,11 @@ describe('Knight', () => {

test('Knight without order creation', () => {
const knight = new toTest.Knight(knightWithoutOrderText);

expect(knight.name).toBe('Arcyksiążę William');
expect(knight.order).toBe('');
expect(knight.level).toBe('299');
expect(knight.lootText).toBe("1.041.479.270");
expect(knight.lootText).toBe('1.041.479.270');
expect(knight.loot).toBe(1041479270);
expect(knight.fights).toBe(130162);
expect(knight.win).toBe(127406);
Expand All @@ -44,38 +46,41 @@ describe('Knight', () => {
const knight = new toTest.Knight(knightWithOrderText);
knight.lootFromCheckPoint = 499651242;
knight.calculateLootDiff();

expect(knight.lootDiff).toBe(2000);
});

test('should print correctly for knight with order', () => {
const knight = new toTest.Knight(knightWithOrderText);
const output = knight.print();

expect(output).toBe('0 62 Arcyksiążę MichalOprych [IMP] 198 499.653.242\n');

expect(output).toBe(
'0 62 Arcyksiążę MichalOprych [IMP] 198 499.653.242\n');
});

test('should print correctly for knight without order', () => {
const knight = new toTest.Knight(knightWithoutOrderText);
const output = knight.print();

expect(output).toBe('0 20 Arcyksiążę William 299 1.041.479.270\n');
});
});

describe('Output', () => {
test('should create row correctly for knight with order', () => {
test('should create row correctly for knight with order', () => {
const knight = new toTest.Knight(knightWithOrderText);
const row = toTest.createRow(knight, 1);

expect(row).toBe('<td>0</td><td>62</td><td>Arcyksiążę MichalOprych </td><td>[IMP]</td><td>198</td><td>499.653.242</td><td><center><button class=\"btnIgnore\" name=\"button\" id=\"button\" onclick=\"ignoreKnight(1);\">x</button></center></td>');

expect(row).toBe(
'<td>0</td><td>62</td><td>Arcyksiążę MichalOprych </td><td>[IMP]</td><td>198</td><td>499.653.242</td><td><center><button class=\"btnIgnore\" name=\"button\" id=\"button\" onclick=\"ignoreKnight(1);\">x</button></center></td>');
});

test('should create row correctly for knight without order', () => {
const knight = new toTest.Knight(knightWithoutOrderText);
const row = toTest.createRow(knight, 1);

expect(row).toBe('<td>0</td><td>20</td><td>Arcyksiążę William</td><td></td><td>299</td><td>1.041.479.270</td><td><center><button class=\"btnIgnore\" name=\"button\" id=\"button\" onclick=\"ignoreKnight(1);\">x</button></center></td>');

expect(row).toBe(
'<td>0</td><td>20</td><td>Arcyksiążę William</td><td></td><td>299</td><td>1.041.479.270</td><td><center><button class=\"btnIgnore\" name=\"button\" id=\"button\" onclick=\"ignoreKnight(1);\">x</button></center></td>');
});

const knights = new Array();
Expand All @@ -84,8 +89,9 @@ describe('Output', () => {

test('should create table with 2 knights', () => {
const table = toTest.createTable(knights)

expect(table).toBe('<table id=\"rounded-corner\" ><tbody><thead><tr><th scope=\"col\">Increase</th><th scope=\"col\">Place</th><th scope=\"col\">Knight</th><th scope=\"col\">Order</th><th scope=\"col\">Level</th><th scope=\"col\">Loot</th><th scope=\"col\">Ignore</th></tr></thead><tr><td>0</td><td>62</td><td>Arcyksiążę MichalOprych </td><td>[IMP]</td><td>198</td><td>499.653.242</td><td><center><button class=\"btnIgnore\" name=\"button\" id=\"button\" onclick=\"ignoreKnight(0);\">x</button></center></td></tr>\n\

expect(table).toBe(
'<table id=\"rounded-corner\" ><tbody><thead><tr><th scope=\"col\">Increase</th><th scope=\"col\">Place</th><th scope=\"col\">Knight</th><th scope=\"col\">Order</th><th scope=\"col\">Level</th><th scope=\"col\">Loot</th><th scope=\"col\">Ignore</th></tr></thead><tr><td>0</td><td>62</td><td>Arcyksiążę MichalOprych </td><td>[IMP]</td><td>198</td><td>499.653.242</td><td><center><button class=\"btnIgnore\" name=\"button\" id=\"button\" onclick=\"ignoreKnight(0);\">x</button></center></td></tr>\n\
<tr><td>0</td><td>20</td><td>Arcyksiążę William</td><td></td><td>299</td><td>1.041.479.270</td><td><center><button class=\"btnIgnore\" name=\"button\" id=\"button\" onclick=\"ignoreKnight(1);\">x</button></center></td></tr>\n\
</tbody></table>');
});
Expand All @@ -95,7 +101,7 @@ describe('Data pasting', () => {
let originalConsole;

beforeAll(() => {
originalConsole = { ...console };
originalConsole = {...console};
console.log = jest.fn();
});

Expand All @@ -118,101 +124,106 @@ describe('Data pasting', () => {
expect(input.value).toBe('')
});

test('should create table with 100 knights', () => {
toTest.dataPasted(input)
test('should create table with 100 knights', () => {
toTest.dataPasted(input)

const filePath = path.join(__dirname, 'data/Top100_base_expected.txt');
const expected = fs.readFileSync(filePath, 'utf8');

expect(document.getElementById("wrapper").innerHTML).toBe(expected)
});
const filePath = path.join(__dirname, 'data/Top100_base_expected.txt');
const expected = fs.readFileSync(filePath, 'utf8');

test('paste second time rank without changes', () => {
toTest.dataPasted(input)
toTest.dataPasted(input)
expect(document.getElementById('wrapper').innerHTML).toBe(expected)
});

const filePath = path.join(__dirname, 'data/Top100_base_expected.txt');
const expected = fs.readFileSync(filePath, 'utf8');

expect(document.getElementById("wrapper").innerHTML).toBe(expected)
});
test('paste second time rank without changes', () => {
toTest.dataPasted(input)
toTest.dataPasted(input)

test('should update loots after loading updated data', () => {
toTest.dataPasted(input)
const filePath = path.join(__dirname, 'data/Top100_base_expected.txt');
const expected = fs.readFileSync(filePath, 'utf8');

let filePath = path.join(__dirname, 'data/Top100_first_update.txt');
const first_update = fs.readFileSync(filePath, 'utf8');
expect(document.getElementById('wrapper').innerHTML).toBe(expected)
});

input.value = first_update
toTest.dataPasted(input)
test('should update loots after loading updated data', () => {
toTest.dataPasted(input)

filePath = path.join(__dirname, 'data/Top100_first_update_expected.txt');
const expected = fs.readFileSync(filePath, 'utf8');

expect(document.getElementById("wrapper").innerHTML).toBe(expected)
});
let filePath = path.join(__dirname, 'data/Top100_first_update.txt');
const first_update = fs.readFileSync(filePath, 'utf8');

test('should update loots after checkpoint and pasting second update', () => {
toTest.dataPasted(input)
input.value = first_update
toTest.dataPasted(input)

let filePath = path.join(__dirname, 'data/Top100_first_update.txt');
const first_update = fs.readFileSync(filePath, 'utf8');
filePath = path.join(__dirname, 'data/Top100_first_update_expected.txt');
const expected = fs.readFileSync(filePath, 'utf8');

input.value = first_update
toTest.dataPasted(input)
expect(document.getElementById('wrapper').innerHTML).toBe(expected)
});

toTest.saveCheckpoint()
test(
'should update loots after checkpoint and pasting second update',
() => {
toTest.dataPasted(input)

filePath = path.join(__dirname, 'data/Top100_second_update.txt');
const second_update = fs.readFileSync(filePath, 'utf8');
let filePath = path.join(__dirname, 'data/Top100_first_update.txt');
const first_update = fs.readFileSync(filePath, 'utf8');

input.value = second_update
toTest.dataPasted(input)
input.value = first_update
toTest.dataPasted(input)

filePath = path.join(__dirname, 'data/Top100_second_update_expected.txt');
const expected = fs.readFileSync(filePath, 'utf8');

expect(document.getElementById("wrapper").innerHTML).toBe(expected)
});
toTest.saveCheckpoint()

test('should ignore', () => {
toTest.dataPasted(input)
toTest.ignoreKnight(5)
filePath = path.join(__dirname, 'data/Top100_second_update.txt');
const second_update = fs.readFileSync(filePath, 'utf8');

const filePath = path.join(__dirname, 'data/Top100_ignore_expected.txt');
const expected = fs.readFileSync(filePath, 'utf8');
input.value = second_update
toTest.dataPasted(input)

expect(document.getElementById("wrapper").innerHTML).toBe(expected)
});
filePath =
path.join(__dirname, 'data/Top100_second_update_expected.txt');
const expected = fs.readFileSync(filePath, 'utf8');

expect(document.getElementById('wrapper').innerHTML).toBe(expected)
});

test('should ignore', () => {
toTest.dataPasted(input)
toTest.ignoreKnight(5)

const filePath = path.join(__dirname, 'data/Top100_ignore_expected.txt');
const expected = fs.readFileSync(filePath, 'utf8');

expect(document.getElementById('wrapper').innerHTML).toBe(expected)
});
});

describe('Utils', () => {
const knightWithOrderText = 'Arcyksiążę MichalOprych [IMP]\t198\t499.653.242\t169.323\t150.225\t15.954\n63';
const knightWithoutOrderText = 'Arcyksiążę William\t299\t1.041.479.270\t130.162\t127.406\t2.209\n21';
const knightWithOrderText =
'Arcyksiążę MichalOprych [IMP]\t198\t499.653.242\t169.323\t150.225\t15.954\n63';
const knightWithoutOrderText =
'Arcyksiążę William\t299\t1.041.479.270\t130.162\t127.406\t2.209\n21';

const firstKnight = new toTest.Knight(knightWithOrderText)
firstKnight.lootDiff = 1
const secondKnight = new toTest.Knight(knightWithoutOrderText)
secondKnight.lootDiff = 2

test('compare left loot diff greater', () => {
expect(toTest.compare(firstKnight,secondKnight)).toBe(1)
});
test(
'compare left loot diff greater',
() => {expect(toTest.compare(firstKnight, secondKnight)).toBe(1)});

test('compare left loot diff lower', () => {
expect(toTest.compare(secondKnight,firstKnight)).toBe(-1)
});
test(
'compare left loot diff lower',
() => {expect(toTest.compare(secondKnight, firstKnight)).toBe(-1)});

test('compare left loot diff greater', () => {
expect(toTest.compare(firstKnight,firstKnight)).toBe(0)
});
test(
'compare left loot diff greater',
() => {expect(toTest.compare(firstKnight, firstKnight)).toBe(0)});
});

describe('Big ranks', () => {
let originalConsole;

beforeAll(() => {
originalConsole = { ...console };
originalConsole = {...console};
console.log = jest.fn();
});

Expand All @@ -235,8 +246,8 @@ describe('Big ranks', () => {

const filePath = path.join(__dirname, 'data/Top2000_base_expected.txt');
const expected = fs.readFileSync(filePath, 'utf8');
expect(document.getElementById("wrapper").innerHTML).toBe(expected)

expect(document.getElementById('wrapper').innerHTML).toBe(expected)
});

test('should update loots after loading updated data', () => {
Expand All @@ -248,9 +259,10 @@ describe('Big ranks', () => {
input.value = update
toTest.dataPasted(input)

const expectedPath = path.join(__dirname, 'data/Top2000_update_expected.txt');
const expectedPath =
path.join(__dirname, 'data/Top2000_update_expected.txt');
const expected = fs.readFileSync(expectedPath, 'utf8');
expect(document.getElementById("wrapper").innerHTML).toBe(expected)

expect(document.getElementById('wrapper').innerHTML).toBe(expected)
});
});

0 comments on commit 138f463

Please sign in to comment.