Skip to content

Commit

Permalink
ajust codestyle and fix prettier files
Browse files Browse the repository at this point in the history
  • Loading branch information
PiluVitu committed Apr 22, 2024
1 parent a3f7488 commit da2f823
Show file tree
Hide file tree
Showing 9 changed files with 114 additions and 44 deletions.
13 changes: 6 additions & 7 deletions .github/workflows/build.yml
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
name: Node.js CI

on:
push:
branches:
- main
pull_request:
branches:
- main

push:
branches:
- main
pull_request:
branches:
- main

jobs:
build:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/code-style.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ jobs:
uses: tj-actions/changed-files@v41
with:
files: |
./src/**
!pnpm-lock.yaml
- name: Run prettier in all files
if: steps.all-changed-files.outputs.any_changed == 'true'
Expand Down
8 changes: 7 additions & 1 deletion src/components/Checkbox/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,13 @@ const html = `
</label>
`;

export default function Checkbox({ check = false, name = '', text = '', disabled = false, value = '' } = {}) {
export default function Checkbox({
check = false,
name = '',
text = '',
disabled = false,
value = '',
} = {}) {
Component.call(this, { html, events });

this.setCheck(check);
Expand Down
11 changes: 8 additions & 3 deletions src/components/Dropdown/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,8 @@ export default function Dropdown({
this.selectedItem = null;

this.onSelect = (item) => {
const existsAndIsDifferent = this.selectedItem !== null && this.selectedItem !== item;
const existsAndIsDifferent =
this.selectedItem !== null && this.selectedItem !== item;
if (existsAndIsDifferent) this.selectedItem.unselect();

this.selectedItem = item;
Expand Down Expand Up @@ -77,8 +78,12 @@ export default function Dropdown({
if (this.isOpen()) this.close();
};

this.listen('mount', () => document.addEventListener('click', closeOnClickOutside));
this.listen('unmount', () => document.removeEventListener('click', closeOnClickOutside));
this.listen('mount', () =>
document.addEventListener('click', closeOnClickOutside),
);
this.listen('unmount', () =>
document.removeEventListener('click', closeOnClickOutside),
);
}

Dropdown.prototype = Object.assign(Dropdown.prototype, Component.prototype, {
Expand Down
103 changes: 77 additions & 26 deletions src/components/Dropdown/index.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ const propsMock = {
],

placeholder: 'Selecione',

};

describe('Dropdown', () => {
Expand All @@ -40,25 +39,42 @@ describe('Dropdown', () => {
it('opens the container when clicked', () => {
dropdown.selected.get('dropdown-toggle').dispatchEvent(clickEvent);

expect(dropdown.selected.get('dropdown-container').classList).toContain('dropdown--open');
expect(dropdown.selected.get('dropdown-container').classList).toContain(
'dropdown--open',
);
});

it('selects an item when clicking', () => {
const item = getByText(dropdown.selected.get('dropdown-options'), 'Soninho');
const item = getByText(
dropdown.selected.get('dropdown-options'),
'Soninho',
);

fireEvent.click(item);

expect(dropdown.selected.get('dropdown-selected').textContent).toBe('Soninho');
expect(dropdown.selected.get('dropdown-selected').classList).not.toContain('dropdown__selected--placeholder');
expect(dropdown.selected.get('dropdown-container').classList).not.toContain('dropdown--open');
expect(dropdown.selected.get('dropdown-selected').textContent).toBe(
'Soninho',
);
expect(dropdown.selected.get('dropdown-selected').classList).not.toContain(
'dropdown__selected--placeholder',
);
expect(dropdown.selected.get('dropdown-container').classList).not.toContain(
'dropdown--open',
);
});

it('selects a item programmatically', () => {
dropdown.setValue('soninho');

expect(dropdown.selected.get('dropdown-selected').textContent).toBe('Soninho');
expect(dropdown.selected.get('dropdown-selected').classList).not.toContain('dropdown__selected--placeholder');
expect(dropdown.selected.get('dropdown-container').classList).not.toContain('dropdown--open');
expect(dropdown.selected.get('dropdown-selected').textContent).toBe(
'Soninho',
);
expect(dropdown.selected.get('dropdown-selected').classList).not.toContain(
'dropdown__selected--placeholder',
);
expect(dropdown.selected.get('dropdown-container').classList).not.toContain(
'dropdown--open',
);
});

it('adds an element to the options', () => {
Expand All @@ -69,9 +85,13 @@ describe('Dropdown', () => {

dropdown.addItem(mockAdditionalItem);

expect(dropdown.selected.get('dropdown-options').children[3].dataset.value).toBe(mockAdditionalItem.value);
expect(
dropdown.selected.get('dropdown-options').children[3].dataset.value,
).toBe(mockAdditionalItem.value);
expect(dropdown.selected.get('dropdown-options').children.length).toBe(4);
expect(() => dropdown.addItem(mockAdditionalItem)).toThrowError('Item already exists');
expect(() => dropdown.addItem(mockAdditionalItem)).toThrowError(
'Item already exists',
);
});

it('removes an element in options', () => {
Expand All @@ -85,32 +105,44 @@ describe('Dropdown', () => {
dropdown.selected.get('dropdown-toggle').dispatchEvent(clickEvent);
fireEvent.click(document.documentElement);

expect(dropdown.selected.get('dropdown-container').classList).not.toContain('dropdown--open');
expect(dropdown.selected.get('dropdown-container').classList).not.toContain(
'dropdown--open',
);
});

it('closes when clicked in toggle', () => {
dropdown.selected.get('dropdown-toggle').dispatchEvent(clickEvent);
dropdown.selected.get('dropdown-toggle').dispatchEvent(clickEvent);

expect(dropdown.selected.get('dropdown-container').classList).not.toContain('dropdown--open');
expect(dropdown.selected.get('dropdown-container').classList).not.toContain(
'dropdown--open',
);
});

it('has the placeholder', () => {
expect(dropdown.selected.get('dropdown-selected').textContent).toBe(propsMock.placeholder);
expect(dropdown.selected.get('dropdown-selected').classList).toContain('dropdown__selected--placeholder');
expect(dropdown.selected.get('dropdown-selected').textContent).toBe(
propsMock.placeholder,
);
expect(dropdown.selected.get('dropdown-selected').classList).toContain(
'dropdown__selected--placeholder',
);
});

it('opens programmatically', () => {
dropdown.open();

expect(dropdown.selected.get('dropdown-container').classList).toContain('dropdown--open');
expect(dropdown.selected.get('dropdown-container').classList).toContain(
'dropdown--open',
);
});

it('closes programmatically', () => {
dropdown.open();
dropdown.close();

expect(dropdown.selected.get('dropdown-container').classList).not.toContain('dropdown--open');
expect(dropdown.selected.get('dropdown-container').classList).not.toContain(
'dropdown--open',
);
});

it('get the value programmatically', () => {
Expand All @@ -119,38 +151,53 @@ describe('Dropdown', () => {

fireEvent.click(item);

expect(dropdown.selected.get('dropdown-selected').dataset.value).toBe('raiva');
expect(dropdown.selected.get('dropdown-selected').dataset.value).toBe(
'raiva',
);
});

it('has the value programmatically', () => {
dropdown.setValue('raiva');

expect(dropdown.selected.get('dropdown-selected').dataset.value).toBe('raiva');
expect(dropdown.selected.get('dropdown-selected').dataset.value).toBe(
'raiva',
);
});

it('reset the value', () => {
dropdown.setValue('soninho');
expect(dropdown.selected.get('dropdown-selected').dataset.value).toBe('soninho');
expect(dropdown.selected.get('dropdown-selected').dataset.value).toBe(
'soninho',
);

dropdown.reset();
expect(dropdown.selected.get('dropdown-selected').dataset.value).toBe(undefined);
expect(dropdown.selected.get('dropdown-selected').dataset.value).toBe(
undefined,
);
});

it('has the text label programmatically', () => {
dropdown.setText('Age');

expect(dropdown.selected.get('dropdown-selected').textContent).toBe('Age');
expect(dropdown.selected.get('dropdown-selected').classList).not.toContain('dropdown__selected--placeholder');
expect(dropdown.selected.get('dropdown-selected').classList).not.toContain(
'dropdown__selected--placeholder',
);
});

it('get the text label programmatically', () => {
dropdown.open();
const item = getByText(dropdown.selected.get('dropdown-options'), 'Soninho');
const item = getByText(
dropdown.selected.get('dropdown-options'),
'Soninho',
);

fireEvent.click(item);

dropdown.getText();
expect(dropdown.selected.get('dropdown-selected').textContent).toBe('Soninho');
expect(dropdown.selected.get('dropdown-selected').textContent).toBe(
'Soninho',
);
});

it('get the placeholder programmatically', () => {
Expand All @@ -162,8 +209,12 @@ describe('Dropdown', () => {
it('has the placeholder programmatically', () => {
dropdown.setPlaceholder('PetDex');

expect(dropdown.selected.get('dropdown-selected').textContent).toBe('PetDex');
expect(dropdown.selected.get('dropdown-selected').classList).toContain('dropdown__selected--placeholder');
expect(dropdown.selected.get('dropdown-selected').textContent).toBe(
'PetDex',
);
expect(dropdown.selected.get('dropdown-selected').classList).toContain(
'dropdown__selected--placeholder',
);
});

it('clear all itens', () => {
Expand Down
3 changes: 2 additions & 1 deletion src/components/ProgressBar/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,8 @@ ProgressBar.prototype = Object.assign(
setProgress(value) {
if (!isValueValid(value, this.minimum, this.maximum)) return;
this.currentProgress = value;
this.selected.get('progress-bar-foreground').style.width = getWidthFormated(this.currentProgress, this.minimum, this.maximum);
this.selected.get('progress-bar-foreground').style.width =
getWidthFormated(this.currentProgress, this.minimum, this.maximum);
this.selected.get('progress-bar').ariaValueNow = this.currentProgress;
this.emit('setProgress', this.currentProgress);
},
Expand Down
8 changes: 7 additions & 1 deletion src/components/RadioButton/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,13 @@
import { Component } from 'pet-dex-utilities';
import './index.scss';

const events = ['change', 'value:change', 'text:change', 'name:change', 'disable'];
const events = [
'change',
'value:change',
'text:change',
'name:change',
'disable',
];

const html = `
<label class="radio-container">
Expand Down
7 changes: 4 additions & 3 deletions src/components/RangeSlider/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,10 @@ export default function RangeSlider({

containerElement.style.backgroundPositionX = `${parseInt(containerElement.style.backgroundPositionX || 0, 10) - offsetX}px`;

currentValue = mouseX > startX
? Math.min(maximum, currentValue + this.getStepSize())
: Math.max(minimum, currentValue - this.getStepSize());
currentValue =
mouseX > startX
? Math.min(maximum, currentValue + this.getStepSize())
: Math.max(minimum, currentValue - this.getStepSize());

this.setValue(currentValue);
unitElement.textContent = unit;
Expand Down
3 changes: 2 additions & 1 deletion src/components/Tabber/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,8 @@ Tabber.prototype = Object.assign(Tabber.prototype, Component.prototype, {
this.currentTab.content.classList.remove('tabber-component--active');

this.currentTab.button = target;
this.currentTab.content = contentContainers[tabButtons.findIndex((tab) => tab === target)];
this.currentTab.content =
contentContainers[tabButtons.findIndex((tab) => tab === target)];

this.currentTab.button.classList.add('tabber-button--active');
this.currentTab.content.classList.add('tabber-component--active');
Expand Down

0 comments on commit da2f823

Please sign in to comment.