Skip to content

Commit

Permalink
Merge branch 'sprint-5' into refactor(RSS-ECOMM-5_23)/removeUnusedEle…
Browse files Browse the repository at this point in the history
…ments
  • Loading branch information
stardustmeg committed Jun 17, 2024
2 parents 1da4fe5 + 30f066e commit 77faed3
Show file tree
Hide file tree
Showing 56 changed files with 1,685 additions and 277 deletions.
9 changes: 6 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@
"typescript": "^5.4.5",
"validate-branch-name": "^1.3.0",
"vite": "^5.2.11",
"vite-plugin-sass": "^0.1.0",
"vitest": "^1.6.0"
"vite-plugin-sass": "^0.1.0"
},
"dependencies": {
"@commercetools/api-request-builder": "^6.0.0",
Expand All @@ -66,23 +65,27 @@
"@commercetools/sdk-middleware-http": "^7.0.4",
"@types/hammerjs": "^2.0.45",
"@types/js-cookie": "^3.0.6",
"@types/sinon": "^17.0.3",
"@types/uuid": "^9.0.8",
"autoprefixer": "^10.4.19",
"hammerjs": "^2.0.8",
"isomorphic-fetch": "^3.0.0",
"js-cookie": "^3.0.5",
"materialize-css": "^1.0.0-rc.2",
"modern-normalize": "^2.0.0",
"msw": "^2.3.1",
"nouislider": "^15.7.1",
"plop": "^4.0.1",
"postcode-validator": "^3.8.20",
"sharp": "^0.33.3",
"sinon": "^18.0.0",
"swiper": "^11.1.3",
"uuid": "^9.0.1",
"vite-plugin-checker": "^0.6.4",
"vite-plugin-image-optimizer": "^1.1.7",
"vite-plugin-svg-spriter": "^1.0.0",
"vite-tsconfig-paths": "^4.3.2"
"vite-tsconfig-paths": "^4.3.2",
"vitest": "^1.6.0"
},
"homepage": "https://github.com/stardustmeg/ecommerce-application#readme",
"license": "ISC"
Expand Down
2 changes: 1 addition & 1 deletion postcss.config.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
module.exports = {
export default {
plugins: {
autoprefixer: {},
},
Expand Down
4 changes: 4 additions & 0 deletions src/app/App/tests/App.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import AppModel from '../model/AppModel.ts';

const app = new AppModel();

/**
* @vitest-environment jsdom
*/

describe('Checking AppModel class', () => {
it('application successfully created', () => {
expect(app.start()).toBe(true);
Expand Down
30 changes: 30 additions & 0 deletions src/entities/Coupon/test/coupon.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
import type { CartCoupon } from '@/shared/types/cart.ts';

import sinon from 'sinon';

import CouponModel from '../model/CouponModel.ts';

/**
* @vitest-environment jsdom
*/
const coupon: CartCoupon = {
coupon: {
cartDiscount: '',
discountCode: '',
id: '',
},
value: 10,
};

const deleteCallback = sinon.fake();
const couponModel = new CouponModel(coupon, deleteCallback);

describe('Checking CustomerApi', () => {
it('should check if root is defined', () => {
expect(couponModel).toBeDefined();
});

it('should check if CustomerApi is an instance of CustomerApi', () => {
expect(couponModel).toBeInstanceOf(CouponModel);
});
});
22 changes: 22 additions & 0 deletions src/entities/Post/test/post.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import postsData from '@/shared/Posts/posts.ts';
import sinon from 'sinon';

import PostView from '../view/PostView.ts';

/**
* @vitest-environment jsdom
*/

const deleteCallback = sinon.fake();
const posts = postsData;
const post = new PostView(posts[0], deleteCallback);

describe('Checking post', () => {
it('should check if post is defined', () => {
expect(post).toBeDefined();
});

it('should check if post is an instance of PostView', () => {
expect(post).toBeInstanceOf(PostView);
});
});
20 changes: 20 additions & 0 deletions src/entities/Summary/test/summary.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
import sinon from 'sinon';

import SummaryModel from '../model/SummaryModel.ts';

/**
* @vitest-environment jsdom
*/

const deleteCallback = sinon.fake();
const summaryModel = new SummaryModel({ en: '', ru: '' }, deleteCallback);

describe('Checking summaryModel', () => {
it('should check if summaryModel is defined', () => {
expect(summaryModel).toBeDefined();
});

it('should check if summaryModel is an instance of SummaryModel', () => {
expect(summaryModel).toBeInstanceOf(SummaryModel);
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@ import type { InputFieldParams, InputFieldValidatorParams } from '@/shared/types

import InputFieldValidatorModel from '../model/InputFieldValidatorModel.ts';

/**
* @vitest-environment jsdom
*/

const validatorParams: InputFieldValidatorParams = {
maxLength: 10,
minLength: 2,
Expand Down
21 changes: 20 additions & 1 deletion src/pages/AboutUsPage/view/AboutUsPageView.ts
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
import LinkModel from '@/shared/Link/model/LinkModel.ts';
import getStore from '@/shared/Store/Store.ts';
import observeStore, { selectCurrentLanguage } from '@/shared/Store/observer.ts';
import { LINK_DETAILS } from '@/shared/constants/links.ts';
import { PAGE_DESCRIPTION } from '@/shared/constants/pages.ts';
import SVG_DETAILS from '@/shared/constants/svg.ts';
import createBaseElement from '@/shared/utils/createBaseElement.ts';
import createSVGUse from '@/shared/utils/createSVGUse.ts';

import styles from './aboutUsPageView.module.scss';

Expand Down Expand Up @@ -34,12 +38,27 @@ class AboutUsPageView {
tag: 'div',
});

this.page.append(this.createTitle(), this.cardsList);
this.page.append(this.createTitle(), this.cardsList, this.createRSSLogo().getHTML());
this.parent.append(this.page);

return this.page;
}

private createRSSLogo(): LinkModel {
const logo = new LinkModel({
attrs: {
href: 'https://rs.school',
target: LINK_DETAILS.BLANK,
},
classes: [styles.logo],
});

const svg = document.createElementNS(SVG_DETAILS.SVG_URL, 'svg');
svg.append(createSVGUse(SVG_DETAILS.RSS_LOGO));
logo.getHTML().append(svg);
return logo;
}

private createTitle(): HTMLHeadingElement {
const title = createBaseElement({
cssClasses: [styles.title],
Expand Down
25 changes: 25 additions & 0 deletions src/pages/AboutUsPage/view/aboutUsPageView.module.scss
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,28 @@
justify-content: center;
}
}

.logo {
display: flex;
margin: 0 auto;
margin-top: var(--small-offset);
width: max-content;

svg {
width: 11rem;
height: 4rem;
transition: fill 0.1s;

use {
transition: fill 0.1s;
}
}

@media (hover: hover) {
&:hover {
svg {
fill: var(--steam-green-1200);
}
}
}
}
22 changes: 22 additions & 0 deletions src/pages/BlogPage/test/blogPage.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import createBaseElement from '@/shared/utils/createBaseElement.ts';

import BlogPageModel from '../model/BlogPageModel.ts';

/**
* @vitest-environment jsdom
*/

const parent = createBaseElement({
tag: 'div',
});
const blog = new BlogPageModel(parent);

describe('Checking blog', () => {
it('should check if post is defined', () => {
expect(blog).toBeDefined();
});

it('should check if blog is an instance of BlogPageModel', () => {
expect(blog).toBeInstanceOf(BlogPageModel);
});
});
22 changes: 22 additions & 0 deletions src/pages/CartPage/test/cart.spec.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import createBaseElement from '@/shared/utils/createBaseElement.ts';

import CartPageModel from '../model/CartPageModel.ts';

/**
* @vitest-environment jsdom
*/

const parent = createBaseElement({
tag: 'div',
});
const cart = new CartPageModel(parent);

describe('Checking cart', () => {
it('should check if post is defined', () => {
expect(cart).toBeDefined();
});

it('should check if cart is an instance of CartPageModel', () => {
expect(cart).toBeInstanceOf(CartPageModel);
});
});
87 changes: 4 additions & 83 deletions src/shared/API/cart/CartApi.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import type { AddCartItem, Cart, CartProduct, EditCartItem } from '@/shared/types/cart.ts';
import type { Cart } from '@/shared/types/cart.ts';
import type {
CartPagedQueryResponse,
Cart as CartResponse,
Expand All @@ -12,41 +12,13 @@ import { CURRENCY } from '@/shared/constants/product.ts';

import getApiClient, { type ApiClient } from '../sdk/client.ts';

enum Actions {
addLineItem = 'addLineItem',
changeLineItemQuantity = 'changeLineItemQuantity',
removeLineItem = 'removeLineItem',
}
export class CartApi {
export default class CartApi {
private client: ApiClient;

constructor() {
this.client = getApiClient();
}

public async addProduct(cart: Cart, addCartItem: AddCartItem): Promise<ClientResponse> {
const data = await this.client
.apiRoot()
.me()
.carts()
.withId({ ID: cart.id })
.post({
body: {
actions: [
{
action: Actions.addLineItem,
productId: addCartItem.productId,
quantity: addCartItem.quantity,
variantId: addCartItem.variantId,
},
],
version: cart.version,
},
})
.execute();
return data;
}

public async create(): Promise<ClientResponse<CartResponse>> {
const myCart: MyCartDraft = {
currency: CURRENCY,
Expand Down Expand Up @@ -79,49 +51,6 @@ export class CartApi {
return data;
}

public async deleteProduct(cart: Cart, product: CartProduct): Promise<ClientResponse> {
const data = await this.client
.apiRoot()
.me()
.carts()
.withId({ ID: cart.id })
.post({
body: {
actions: [
{
action: Actions.removeLineItem,
lineItemId: product.lineItemId,
},
],
version: cart.version,
},
})
.execute();
return data;
}

public async editProductCount(cart: Cart, editCartItem: EditCartItem): Promise<ClientResponse> {
const data = await this.client
.apiRoot()
.me()
.carts()
.withId({ ID: cart.id })
.post({
body: {
actions: [
{
action: Actions.changeLineItemQuantity,
lineItemId: editCartItem.lineId,
quantity: editCartItem.quantity,
},
],
version: cart.version,
},
})
.execute();
return data;
}

public async getActiveCart(): Promise<ClientResponse<CartResponse>> {
const data = await this.client.apiRoot().me().activeCart().get().execute();
return data;
Expand All @@ -137,14 +66,14 @@ export class CartApi {
return data;
}

public async setAnonymousId(cart: Cart, actions: CartSetAnonymousIdAction): Promise<ClientResponse> {
public async setAnonymousId(cart: Cart, actions: CartSetAnonymousIdAction[]): Promise<ClientResponse> {
const data = await this.client
.apiRoot()
.carts()
.withId({ ID: cart.id })
.post({
body: {
actions: [actions],
actions,
version: cart.version,
},
})
Expand All @@ -168,11 +97,3 @@ export class CartApi {
return data;
}
}

const createCartApi = (): CartApi => new CartApi();

const cartApi = createCartApi();

export default function getCartApi(): CartApi {
return cartApi;
}
Loading

0 comments on commit 77faed3

Please sign in to comment.