Skip to content

Commit

Permalink
feat: edit base cocktails (#461)
Browse files Browse the repository at this point in the history
* feat: edit base cocktails

* fix

* chore: added eslint rule

* fix

* fix

* fix

* chore: update version
  • Loading branch information
anton-gustafsson authored Dec 27, 2023
1 parent 6ab5b80 commit e9590fc
Show file tree
Hide file tree
Showing 29 changed files with 571 additions and 182 deletions.
11 changes: 6 additions & 5 deletions .eslintrc.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,12 @@
"prettier"
],
"rules": {
"@typescript-eslint/consistent-type-definitions": [1, "type"],
"@typescript-eslint/no-unused-vars": [1],
"@typescript-eslint/no-empty-function": [1],
"@typescript-eslint/no-inferrable-types": [1],
"@typescript-eslint/no-extraneous-class": [1],
"@typescript-eslint/consistent-type-definitions": ["warn", "type"],
"@typescript-eslint/no-unused-vars": "warn",
"@typescript-eslint/no-empty-function": "warn",
"@typescript-eslint/no-inferrable-types": "warn",
"@typescript-eslint/no-extraneous-class": "warn",
"@typescript-eslint/no-unnecessary-boolean-literal-compare": "error",
"eqeqeq": ["error", "always", { "null": "ignore" }]
},

Expand Down
4 changes: 2 additions & 2 deletions android/app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ android {
applicationId "com.moimob.drinkable"
minSdkVersion rootProject.ext.minSdkVersion
targetSdkVersion rootProject.ext.targetSdkVersion
versionCode 14501
versionName "1.45.1"
versionCode 14600
versionName "1.46.0"
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
aaptOptions {
// Files and dirs to omit from the packaged assets dir, modified to accommodate modern web apps.
Expand Down
8 changes: 4 additions & 4 deletions cypress/e2e/cocktails.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ describe('Cocktails', () => {

cy.dataCy('save-cocktail').click();

cy.dataCy('cocktail-name').should('have.class', 'input-error').type('Test Cocktail');
cy.dataCy('cocktail-name').blur();
cy.dataCy('cocktail-name-input').should('have.class', 'input-error').type('Test Cocktail');
cy.dataCy('cocktail-name-input').blur();

cy.dataCy('cocktail-image').selectFile('static/images/balmoral.jpg', { force: true });

Expand Down Expand Up @@ -88,8 +88,8 @@ describe('Cocktails', () => {

cy.dataCy('create-cocktail').click();

cy.dataCy('cocktail-name').type('Test Cocktail');
cy.dataCy('cocktail-name').blur();
cy.dataCy('cocktail-name-input').type('Test Cocktail');
cy.dataCy('cocktail-name-input').blur();
cy.dataCy('cocktail-image').selectFile('static/images/balmoral.jpg', { force: true });
cy.dataCy('textarea').type('Test Instructions');
cy.dataCy('save-cocktail').click();
Expand Down
136 changes: 136 additions & 0 deletions cypress/e2e/edit-base-cocktail.cy.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
import { ValidateCocktailRequest, validateCocktail } from './validation-helpers/validate-cocktail';

describe('Edit Base Cocktails', () => {
beforeEach(() => {
window.localStorage.clear();
window.localStorage.setItem('CapacitorStorage.messuarement-system', 'Imperial');
});

it('Edit base cocktail with new values', () => {
cy.visit('#/cocktails');

const cocktailId = '2';
cy.get(`#all-cocktails-${cocktailId}`).click();

validateCocktail({
name: 'Gin & Tonic',
category: 'Cocktail',
tags: [],
abv: '9.38%',
ingredients: [
{ name: 'Gin', amount: '1 1/3 fl oz' },
{ name: 'Tonic', amount: '4 fl oz' }
],
isEditedText: false
});

cy.dataCy('cocktail-dialog-dropdown-content').should('not.be.visible');

cy.dataCy('cocktail-dialog-dropdown').click();
cy.dataCy('cocktail-dialog-dropdown-content').should('be.visible');
cy.dataCy('dropdown-edit-cocktail').click();

cy.dataCy('cocktail-dialog-dropdown-content').should('not.be.visible');

cy.dataCy('cocktail-category-select').select('Other');

cy.dataCy('edit-tags').click();

cy.dataCy('tag-1').click();
cy.dataCy('edit-tags-drawer-close').click();

cy.dataCy(['ingredient-group-0', 'amount-input']).clear();
cy.dataCy(['ingredient-group-0', 'amount-input']).type('2');
cy.dataCy(['ingredient-group-0', 'amount-input']).blur();

cy.dataCy('save-cocktail').click();

const validateCocktailRequest: ValidateCocktailRequest = {
name: 'Gin & Tonic',
category: 'Other',
tags: ['IBA'],
ingredients: [
{ name: 'Gin', amount: '2 fl oz' },
{ name: 'Tonic', amount: '4 fl oz' }
],
abv: '12.5%',
isEditedText: true
};

validateCocktail(validateCocktailRequest);

// Validate that when dialog is reopened, the latest values are still there
cy.dataCy('close-dialog').click();
cy.get(`#all-cocktails-${cocktailId}`).click();
validateCocktail(validateCocktailRequest);
});

it('Restore Cocktail', () => {
window.localStorage.setItem(
'CapacitorStorage.cocktail-information',
JSON.stringify([
{
id: '2',
category: 2,
ingredientGroups: [
{
amount: '2',
ingredientId: '6',
unit: 'fl oz'
},
{
amount: '4',
ingredientId: '7',
unit: 'fl oz'
}
],
tags: ['1']
}
])
);

cy.visit('#/cocktails');

const cocktailId = '2';
cy.get(`#all-cocktails-${cocktailId}`).click();

validateCocktail({
name: 'Gin & Tonic',
category: 'Other',
tags: ['IBA'],
ingredients: [
{ name: 'Gin', amount: '2 fl oz' },
{ name: 'Tonic', amount: '4 fl oz' }
],
abv: '12.5%',
isEditedText: true
});

cy.dataCy('cocktail-dialog-dropdown-content').should('not.be.visible');

cy.dataCy('cocktail-dialog-dropdown').click();
cy.dataCy('cocktail-dialog-dropdown-content').should('be.visible');
cy.dataCy('dropdown-restore-cocktail').click();

cy.dataCy('cocktail-dialog-dropdown-content').should('not.be.visible');

const validateCocktailRequest = {
name: 'Gin & Tonic',
category: 'Cocktail',
tags: [],
abv: '9.38%',
ingredients: [
{ name: 'Gin', amount: '1 1/3 fl oz' },
{ name: 'Tonic', amount: '4 fl oz' }
],
isEditedText: false
};

validateCocktail(validateCocktailRequest);

// Validate that when dialog is reopened, the latest values are still there
cy.dataCy('close-dialog').click();
cy.get(`#all-cocktails-${cocktailId}`).click();
validateCocktail(validateCocktailRequest);
});
});
34 changes: 34 additions & 0 deletions cypress/e2e/validation-helpers/validate-cocktail.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
export type ValidateCocktailRequest = {
name: string;
category: string;
tags: string[];
abv: string;
ingredients: { name: string; amount: string }[];
isEditedText: boolean;
};

export function validateCocktail(cocktail: ValidateCocktailRequest) {
const { name, category, isEditedText, tags, ingredients, abv } = cocktail;

cy.dataCy('cocktail-name').should('have.text', name);
cy.dataCy('cocktail-category').should('have.text', category);

if (isEditedText) {
cy.dataCy('cocktail-edited-text').should('exist');
} else {
cy.dataCy('cocktail-edited-text').should('not.exist');
}

cy.get('[data-cy=cocktail-tags] > p').should('have.length', tags.length);
tags.forEach(tag => {
cy.get('[data-cy=cocktail-tags] > p').should('include.text', tag);
});

for (let i = 0; i < ingredients.length; i++) {
const element = ingredients[i];
cy.get(`[data-cy=ingredient-group-${i}] [data-cy=ingredient-name]`).should('include.text', element.name);
cy.get(`[data-cy=ingredient-group-${i}] [data-cy=ingredient-amount]`).should('include.text', element.amount);
}

cy.dataCy('cocktail-abv').should('include.text', abv);
}
2 changes: 2 additions & 0 deletions fastlane/metadata/android/en-US/changelogs/14600.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
• You can now edit base recipes
• Updated German translations
2 changes: 1 addition & 1 deletion src/components/copy-to-clipboard/copy-to-clipboard.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ export class CopyToClipboard {
public textCopied = false;

async copyToClipboard() {
if (this.textCopied === true) {
if (this.textCopied) {
return;
}

Expand Down
Loading

0 comments on commit e9590fc

Please sign in to comment.