Skip to content

Commit

Permalink
🚥 add tests for problem when has space in prefix
Browse files Browse the repository at this point in the history
On branch fix/#70/problem-with-space-in-prefix
Changes to be committed:
	modified:   cypress/e2e/v4.x.x/set-mask.cy.ts
	modified:   tests/set-mask.test.ts
  • Loading branch information
codermarcos committed Mar 6, 2024
1 parent 71fc99d commit 718503d
Show file tree
Hide file tree
Showing 2 changed files with 202 additions and 71 deletions.
229 changes: 158 additions & 71 deletions cypress/e2e/v4.x.x/set-mask.cy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -257,80 +257,167 @@ describe(
describe(
'prefix and suffix',
() => {
beforeEach(
() => {
cy.visit(getUrl({ prefix: '$', suffix: 'CAD' }));
cy.reload();
}
);

it(
'should format when input was created',
() => {
cy.get('input').should('have.value', '$0,00CAD');
}
);

it(
'shouldn\'t allow type a letter',
() => {
cy.get('input').type('abc');
cy.get('input').should('have.value', '$0,00CAD');
}
);

it(
'should format when type only cents',
() => {
cy.get('input').type('1');
cy.get('input').should('have.value', '$0,01CAD');

cy.get('input').type('{backspace}');
cy.get('input').should('have.value', '$0,00CAD');

cy.get('input').type('12');
cy.get('input').should('have.value', '$0,12CAD');

cy.get('input').type('{backspace}'.repeat(2));
cy.get('input').should('have.value', '$0,00CAD');

cy.get('input').type('66');
cy.get('input').should('have.value', '$0,66CAD');
}
);

it(
'should format dozens',
describe(
'common behaviour',
() => {
cy.get('input').type('123');
cy.get('input').should('have.value', '$1,23CAD');


cy.get('input').type('{backspace}'.repeat(3));
cy.get('input').should('have.value', '$0,00CAD');

cy.get('input').type('1234');
cy.get('input').should('have.value', '$12,34CAD');

cy.get('input').type('{backspace}'.repeat(4));
cy.get('input').should('have.value', '$0,00CAD');

cy.get('input').type('6666');
cy.get('input').should('have.value', '$66,66CAD');
beforeEach(
() => {
cy.visit(getUrl({ prefix: '$', suffix: 'CAD' }));
cy.reload();
}
);

it(
'should format when input was created',
() => {
cy.get('input').should('have.value', '$0,00CAD');
}
);

it(
'shouldn\'t allow type a letter',
() => {
cy.get('input').type('abc');
cy.get('input').should('have.value', '$0,00CAD');
}
);

it(
'should format when type only cents',
() => {
cy.get('input').type('1');
cy.get('input').should('have.value', '$0,01CAD');

cy.get('input').type('{backspace}');
cy.get('input').should('have.value', '$0,00CAD');

cy.get('input').type('12');
cy.get('input').should('have.value', '$0,12CAD');

cy.get('input').type('{backspace}'.repeat(2));
cy.get('input').should('have.value', '$0,00CAD');

cy.get('input').type('66');
cy.get('input').should('have.value', '$0,66CAD');
}
);

it(
'should format dozens',
() => {
cy.get('input').type('123');
cy.get('input').should('have.value', '$1,23CAD');


cy.get('input').type('{backspace}'.repeat(3));
cy.get('input').should('have.value', '$0,00CAD');

cy.get('input').type('1234');
cy.get('input').should('have.value', '$12,34CAD');

cy.get('input').type('{backspace}'.repeat(4));
cy.get('input').should('have.value', '$0,00CAD');

cy.get('input').type('6666');
cy.get('input').should('have.value', '$66,66CAD');
}
);

it(
'should format hundreds',
() => {
cy.get('input').type('12345');
cy.get('input').should('have.value', '$123,45CAD');

cy.get('input').type('{backspace}'.repeat(5));
cy.get('input').should('have.value', '$0,00CAD');

cy.get('input').type('66699');
cy.get('input').should('have.value', '$666,99CAD');
}
);
}
);

it(
'should format hundreds',
() => {
cy.get('input').type('12345');
cy.get('input').should('have.value', '$123,45CAD');

cy.get('input').type('{backspace}'.repeat(5));
cy.get('input').should('have.value', '$0,00CAD');

cy.get('input').type('66699');
cy.get('input').should('have.value', '$666,99CAD');

describe(
'wrong behaviour prefix and suffix with space',
() => {
beforeEach(
() => {
cy.visit(getUrl({ prefix: '$ ', suffix: ' CAD' }));
cy.reload();
}
);

it(
'should format when input was created',
() => {
cy.get('input').should('have.value', '$ 0,00 CAD');
}
);

it(
'shouldn\'t allow type a letter',
() => {
cy.get('input').type('abc');
cy.get('input').should('have.value', '$ 0,00 CAD');
}
);

it(
'should format when type only cents',
() => {
cy.get('input').type('1');
cy.get('input').should('have.value', '$ 0,01 CAD');

cy.get('input').type('{backspace}');
cy.get('input').should('have.value', '$ 0,00 CAD');

cy.get('input').type('12');
cy.get('input').should('have.value', '$ 0,12 CAD');

cy.get('input').type('{backspace}'.repeat(2));
cy.get('input').should('have.value', '$ 0,00 CAD');

cy.get('input').type('66');
cy.get('input').should('have.value', '$ 0,66 CAD');
}
);

it(
'should format dozens',
() => {
cy.get('input').type('123');
cy.get('input').should('have.value', '$ 1,23 CAD');


cy.get('input').type('{backspace}'.repeat(3));
cy.get('input').should('have.value', '$ 0,00 CAD');

cy.get('input').type('1234');
cy.get('input').should('have.value', '$ 12,34 CAD');

cy.get('input').type('{backspace}'.repeat(4));
cy.get('input').should('have.value', '$ 0,00 CAD');

cy.get('input').type('6666');
cy.get('input').should('have.value', '$ 66,66 CAD');
}
);

it(
'should format hundreds',
() => {
cy.get('input').type('12345');
cy.get('input').should('have.value', '$ 123,45 CAD');

cy.get('input').type('{backspace}'.repeat(5));
cy.get('input').should('have.value', '$ 0,00 CAD');

cy.get('input').type('66699');
cy.get('input').should('have.value', '$ 666,99 CAD');
}
);
}
);
}
Expand Down
44 changes: 44 additions & 0 deletions tests/set-mask.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,17 @@ describe(
expect(input.value).toBe('R$0,69BRL');
},
);

it(
'should format when type cents only and prefix has space',
() => {
clear = setMask(input, { prefix: 'R$ ', suffix: ' BRL' });

write('69');

expect(input.value).toBe('R$ 0,69 BRL');
},
);

it(
'should format when type cents and dozens',
Expand All @@ -210,6 +221,17 @@ describe(
expect(input.value).toBe('R$6,66BRL');
},
);

it(
'should format when type cents and dozens and prefix has space',
() => {
clear = setMask(input, { prefix: 'R$ ', suffix: ' BRL' });

write('666');

expect(input.value).toBe('R$ 6,66 BRL');
},
);

it(
'should format when type thousands',
Expand All @@ -221,6 +243,17 @@ describe(
expect(input.value).toBe('R$6.669,99BRL');
},
);

it(
'should format when type thousands',
() => {
clear = setMask(input, { prefix: 'R$ ', suffix: ' BRL' });

write('666999');

expect(input.value).toBe('R$ 6.669,99 BRL');
},
);

it(
'should format when type number sequentialy',
Expand All @@ -232,6 +265,17 @@ describe(
expect(input.value).toBe('R$12.345,67BRL');
},
);

it(
'should format when type number sequentialy',
() => {
clear = setMask(input, { prefix: 'R$ ', suffix: ' BRL' });

write('1234567');

expect(input.value).toBe('R$ 12.345,67 BRL');
},
);
}
);

Expand Down

0 comments on commit 718503d

Please sign in to comment.