Skip to content

Commit

Permalink
added few more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
SriHV committed Nov 12, 2024
1 parent 6895cbb commit 041f525
Showing 1 changed file with 40 additions and 2 deletions.
42 changes: 40 additions & 2 deletions src/components/button/_macro.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,6 +149,21 @@ describe('FOR: Macro: Button', () => {
});
});

describe('GIVEN: Params: iconType', () => {
describe('WHEN: iconType parameter is provided', () => {
test('THEN: the button has an svg element', () => {
const $ = cheerio.load(
renderComponent('button', {
text: 'Click me!',
iconPosition: 'after',
iconType: 'exit',
}),
);
expect($('svg').length).toBe(1);
});
});
});

describe('GIVEN: Params: variants', () => {
describe('WHEN: variants are present', () => {
test('THEN: the button has the expected variant classes', () => {
Expand Down Expand Up @@ -419,7 +434,7 @@ describe('FOR: Macro: Button', () => {

describe('GIVEN: Params: noIcon', () => {
describe('WHEN: noIcon is set to true', () => {
test('THEN: button does not have the default arrow-next icon', () => {
test('THEN: the button does not have the default arrow-next icon', () => {
const faker = templateFaker();
const iconsSpy = faker.spy('icon');

Expand All @@ -432,7 +447,7 @@ describe('FOR: Macro: Button', () => {
});
});
describe('WHEN: noIcon is set to false', () => {
test('THEN: button has the default arrow-next icon', () => {
test('THEN: the button has the default arrow-next icon', () => {
const faker = templateFaker();
const iconsSpy = faker.spy('icon');

Expand All @@ -445,4 +460,27 @@ describe('FOR: Macro: Button', () => {
});
});
});

describe('GIVEN: Params: listeners', () => {
describe('WHEN: listeners are provided', () => {
test('THEN: the button renders each listener', () => {
const $ = cheerio.load(
renderComponent('button', {
id: 'example-id',
listeners: {
click: `alert('Input was clicked')`,
keypress: `alert('Key was pressed')`,
},
}),
);
const script = $('script').html();
expect(script).toContain(
`document.getElementById("example-id").addEventListener('click', function(){ alert('Input was clicked') });`,
);
expect(script).toContain(
`document.getElementById("example-id").addEventListener('keypress', function(){ alert('Key was pressed') });`,
);
});
});
});
});

0 comments on commit 041f525

Please sign in to comment.