Skip to content

Commit

Permalink
Tests descriptions changed to english
Browse files Browse the repository at this point in the history
- Run test ok.
  • Loading branch information
Mcarrobof24 committed Jan 26, 2024
1 parent f8b12db commit 8216d56
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 27 deletions.
37 changes: 25 additions & 12 deletions src/dataFunctions.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,35 +13,48 @@ export const filterData = (data, filterBy, value) => {
};

export const sortData = (data, sortBy, sortOrder) => {
const orderData = data.toSorted((a, b) => {
if(sortOrder === "asc"){
return a[sortBy] - b[sortBy];
} else {
return b[sortBy] - a[sortBy];
const orderData = data.toSorted((a,b) => {
if(sortOrder === 'asc'){
if(a[sortBy] === b[sortBy]){
return 0;
}
if(a[sortBy]< b[sortBy]){
return -1;
}
return 1;
}
})
else {
if(a[sortBy] === b[sortBy]){
return 0;
}
if (a[sortBy] > b[sortBy]){
return -1;
}
return 1;
}
});
return orderData;
};

export const sortDataByPrice = (data, sortBy, sortOrder) => {
const orderDataByPrice = data.toSorted((a,b) => {
if(sortOrder === 'low'){
if(a.facts[sortBy] === b.facts[sortBy]){
return 0;
if(a.facts[sortBy] > b.facts[sortBy]){
return 1;
}
if(a.facts[sortBy]< b.facts[sortBy]){
return -1;
}
return 1;
return 0;
}
else {
if(a.facts[sortBy] === b.facts[sortBy]){
return 0;
if(a.facts[sortBy] < b.facts[sortBy]){
return 1;
}
if (a.facts[sortBy] > b.facts[sortBy]){
return -1;
}
return 1;
return 0;
}
})
return orderDataByPrice;
Expand Down
8 changes: 4 additions & 4 deletions src/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -26,14 +26,14 @@ <h2>Your Dreamed Vacation</h2>
<label for="2-select">Order by:</label>
<select data-testid="select-sort" name="name" id="2-select">
<option disable selected value="1">Ship Name</option>
<option value="asc">Name: A-Z</option>
<option value="desc">Name: Z-A</option>
<option value="asc">Name: A-Z</option>
<option value="desc">Name: Z-A</option>
</select>
<label for="3-select">Sort by:</label>
<select data-testid="select-sort-price" name="price-high-low" id="3-select">
<option disable selected value="2">Price</option>
<option value="low">Low to High</option>
<option value="high">High to Low</option>
<option value="low">Low to High</option>
<option value="high">High to Low</option>
</select>
<button data-testid="button-clear">Clear</button>
</nav>
Expand Down
19 changes: 8 additions & 11 deletions test/dataFunctions.spec.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
import { filterData, sortData, sortDataByPrice, computeStats} from '../src/dataFunctions.js';
import { data as fakeData } from './data.js';

console.log(fakeData);

describe('filterData collection tests', () => {
const filter1 = [fakeData[0]];
it('Should filter by price range from 1000-1500', () => {
Expand All @@ -25,31 +23,30 @@ describe('filterData collection tests', () => {
});
});

describe('Test de la función sortData', () => {
describe('sortData by name collection tests', () => {
const Order = [fakeData[1],fakeData[2],fakeData[0]];
describe('La función sortData debe ordenar de manera ascendente y descendente por nombre', () => {
it('Ordena de manera asscendente por nombre', () => {
describe('sortData function should order by name: ascendent and descendent', () => {
it('Should sort by name: ascendent', () => {

const result = sortData(fakeData,"name","asc");
expect(result).toEqual(Order);
});
it('Ordena de manera descendente por nombre', () => {
it('Should sort by name: descendent', () => {
const result = sortData(fakeData,"name","desc");
expect(result).toEqual(Order.reverse());
});
});
});

describe('Test de la función sortDataByPrice ', () => {
describe('sortDataByPrice collection tests', () => {
const resultOrder = [fakeData[0],fakeData[2],fakeData[1]];
const resultOrder2 = [fakeData[1],fakeData[2],fakeData[0]];
describe('La función sortData debe ordenar de manera ascendente y descendente por precio', () => {
it('Ordena de manera asscendente por precio', () => {

describe('sortDataByPrice function should order by price: ascendent and descendent', () => {
it('Should sort by price: ascendent', () => {
const result = sortDataByPrice(fakeData,"cruisePrice","low");
expect(result).toEqual(resultOrder);
});
it('Ordena de manera descendente por precio', () => {
it('Should sort by name: descendent', () => {
const result = sortDataByPrice(fakeData,"cruisePrice","high");
expect(result).toEqual(resultOrder2);
});
Expand Down

0 comments on commit 8216d56

Please sign in to comment.