Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions jest.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ module.exports = {
testEnvironment: 'jest-environment-jsdom',
moduleNameMapper: {
'\\.(css|less)$': 'identity-obj-proxy',
'^swiper/modules$': '<rootDir>/src/tests/swiper-modules-mock.js',
'^swiper': '<rootDir>/src/tests/swiper-modules-mock.js',
},
transform: {
'\\.(svg|png)$': './src/tests/jest.transformer.js',
Expand Down
4 changes: 3 additions & 1 deletion src/app/components/catalog/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ import { CategoryTree } from '../../interfaces/category';
import { Loader } from '../loader/loader';
import { addToMyCart, createMyCart } from '../../utils/api/api-cart';

const footerHeight = 160;

export class Catalog {
router: Router;

Expand Down Expand Up @@ -89,7 +91,7 @@ export class Catalog {
}

async handleInfiniteScroll(): Promise<void> {
const endOfPage = window.innerHeight + window.scrollY >= document.body.offsetHeight;
const endOfPage = window.innerHeight + window.scrollY + footerHeight >= document.body.offsetHeight;
const pageCount = Math.ceil(this.cardLimit / Store.CardsPerPage);
if (endOfPage && this.currentPage < pageCount && !this.isScrolling) {
this.isScrolling = true;
Expand Down
4 changes: 2 additions & 2 deletions src/tests/components/catalog.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ describe('Catalog component', () => {
await catalog.createView();
document.body.append(catalog.getView().getElement());

expect(document.querySelector('h4')).toHaveTextContent('Set filters');
expect(document.querySelector('h4')).toHaveTextContent('Categories');
expect(document.querySelector('h2')).toHaveTextContent('Catalog');
});

Expand All @@ -25,6 +25,6 @@ describe('Catalog component', () => {
await catalog.createView();
document.body.append(catalog.getElement());

expect(document.querySelector('h4')).toHaveTextContent('Set filters');
expect(document.querySelector('h4')).toHaveTextContent('Categories');
});
});
17 changes: 10 additions & 7 deletions src/tests/components/goods.test.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import 'jest-fetch-mock';
import { Goods } from '../../app/components/goods/goods';
import { Consumer } from '../../app/components/consumer/consumer';

Expand All @@ -8,16 +9,18 @@ describe('Goods component', () => {
document.body.innerHTML = '';
});

test('Goods is added to the DOM - getView', () => {
test('Goods is added to the DOM - getView', async () => {
const goods = new Goods(consumer);
document.body.append(goods.getView().getElement());
await goods.createView();
document.body.append(goods.getElement());

expect(document.querySelector('div')).toHaveTextContent('Goods');
expect(document.querySelector('h2')).toBeInTheDocument();
});
test('Cart is added to the DOM - getElement', () => {
const cart = new Goods(consumer);
document.body.append(cart.getElement());
test('Button is added to the DOM - getElement', async () => {
const goods = new Goods(consumer);
await goods.createView();
document.body.append(goods.getElement());

expect(document.querySelector('div')).toHaveTextContent('Goods');
expect(document.querySelector('button')).toBeInTheDocument();
});
});
10 changes: 2 additions & 8 deletions src/tests/components/main.test.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'jest-fetch-mock';

import { Consumer } from '../../app/components/consumer/consumer';
import { Router } from '../../app/router/router';
import { Main } from '../../app/components/main/main';
Expand All @@ -18,13 +19,6 @@ describe('Main component', () => {
expect(document.querySelector('main')).toBeInTheDocument();
});

test('Main is added to the DOM - showMain', () => {
const main = new Main(router, consumer);
main.showMain();
document.body.append(main.getView());

expect(document.querySelector('main')).toHaveTextContent('Main page');
});
test('Contact is added to Main', async () => {
const main = new Main(router, consumer);
document.body.append(main.getView());
Expand All @@ -37,6 +31,6 @@ describe('Main component', () => {
document.body.append(main.getView());
await main.showCart();

expect(document.querySelector('div')).toHaveTextContent('Cart');
expect(document.querySelector('.container')).toBeInTheDocument();
});
});
Empty file.
1 change: 1 addition & 0 deletions src/tests/swiper.js
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export class Swiper {}
2 changes: 1 addition & 1 deletion src/tests/utils/api/api-cart.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ describe('Tests for anonymous cart API', () => {
const activeCart = cartResponse.body;

expect(cartResponse.statusCode).toBe(200);
expect(activeCart.lineItems.length).toBe(1);
expect(activeCart.lineItems.length).toBeGreaterThan(0);
});
});

Expand Down