Skip to content

Commit

Permalink
fix: UT and E2E tests
Browse files Browse the repository at this point in the history
  • Loading branch information
steve-lebleu committed Mar 30, 2024
1 parent 50d6e11 commit aa948a2
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 22 deletions.
28 changes: 10 additions & 18 deletions cypress/e2e/kompleter.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ describe("Kompletr.js", function() {
});

it("should be initialized with #result element into DOM", function() {
expect(cy.get('#kpl-result')).to.not.be.undefined;
expect(cy.get('#kompletr-results')).to.not.be.undefined;
});

});
Expand All @@ -29,33 +29,33 @@ describe("Kompletr.js", function() {

it ("should return 0 results with a value length < 2", function() {
cy.get('#auto-complete').click().type('a').then(() => {
cy.get('.item--result').should('not.exist');
cy.get('.item--row').should('not.exist');
});
});

it ("should return n results with a value length >= 2", function() {
cy.get('#auto-complete').click().type('Ter').then(() => {
cy.get('.item--result').its('length').should('be.gte', 0);
cy.get('.item--row').its('length').should('be.gte', 0);
});
});

xit ("should complete input when Enter key is pressed", function() {
it ("should complete input when Enter key is pressed", function() {
cy.get('#auto-complete')
.click()
.type('Te')
.type('{downarrow}')
.type('{enter}')
.invoke('val')
.then((value) => {
console.log('value', value)
expect(value).to.equals('Teresina');
})
});

xit ("should complete input when click is done on a suggestion", function() {
it ("should complete input when click is done on a suggestion", function() {
cy.get('#auto-complete')
.click()
.type('Te');
cy.get('.item--result:first-child')
cy.get('.item--row:first-child')
.click();
cy.get('#auto-complete')
.invoke('val')
Expand All @@ -64,21 +64,13 @@ describe("Kompletr.js", function() {
})
});

xit ("should close suggestions when click is done out of the list", function() {
it ("should close suggestions when click is done out of the list", function() {
cy.get('#auto-complete')
.click()
.type('Te');
cy.get('body')
.click();
cy.get('.item--result').should('not.exist');
});

xit ("should navigate between suggestions using keyboard", function() {
cy.get('#auto-complete')
.click()
.type('Te');
cy.get('.item--result:first-child')
.click();
.click('topRight');
cy.get('#kompletr-results').should('not.visible');
});
});
});
8 changes: 4 additions & 4 deletions test/dom.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,8 @@ describe('DOM', () => {
dom.buildResults(data);
expect(dom.result.firstChild).toBeInstanceOf(HTMLElement);
expect(dom.result.firstChild.id).toBe('1');
expect(dom.result.firstChild.className).toBe('item--result');
expect(dom.result.firstChild.firstChild.className).toBe('item--data');
expect(dom.result.firstChild.className).toBe('item--row');
expect(dom.result.firstChild.firstChild.className).toBe('item--property');
expect(dom.result.firstChild.firstChild.textContent).toBe('test');
expect(broadcaster.trigger).toHaveBeenCalled();
});
Expand All @@ -87,8 +87,8 @@ describe('DOM', () => {
dom.buildResults(data, ['prop']);
expect(dom.result.firstChild).toBeInstanceOf(HTMLElement);
expect(dom.result.firstChild.id).toBe('1');
expect(dom.result.firstChild.className).toBe('item--result');
expect(dom.result.firstChild.firstChild.className).toBe('item--data');
expect(dom.result.firstChild.className).toBe('item--row');
expect(dom.result.firstChild.firstChild.className).toBe('item--property');
expect(dom.result.firstChild.firstChild.textContent).toBe('test');
expect(broadcaster.trigger).toHaveBeenCalled();
});
Expand Down

0 comments on commit aa948a2

Please sign in to comment.