-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #138 from ably/company-autocomplete
[DEX-55] Company autocomplete
- Loading branch information
Showing
17 changed files
with
699 additions
and
291 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
PATH | ||
remote: . | ||
specs: | ||
ably-ui (6.0.1) | ||
ably-ui (6.0.1.dev.6103afe) | ||
view_component (~> 2.33.0) | ||
|
||
GEM | ||
|
111 changes: 111 additions & 0 deletions
111
cypress/integration/core/company_autocomplete/behaviour.spec.js
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,111 @@ | ||
describe("Company Autocomplete", () => { | ||
const url = "/components/company-autocomplete?framework=vw"; | ||
const CONTAINER_SELECTOR = "[data-id=company-autocomplete-dropdown]"; | ||
const ITEMS_SELECTOR = `${CONTAINER_SELECTOR} button`; | ||
|
||
beforeEach(() => { | ||
cy.visit(url); | ||
}); | ||
|
||
it("shows the drop down when you start typing", () => { | ||
cy.get("input").type("A"); | ||
cy.get(CONTAINER_SELECTOR).should("be.visible"); | ||
cy.get(CONTAINER_SELECTOR).contains("All Things Apple"); | ||
}); | ||
|
||
it("updates the input when a result is clicked on", () => { | ||
cy.get("input").type("A"); | ||
cy.get(CONTAINER_SELECTOR).should("be.visible"); | ||
cy.get(ITEMS_SELECTOR).eq(1).click(); | ||
cy.get("input").should("have.value", "All Things Apple"); | ||
}); | ||
|
||
it("changes the focus when the down arrow is pressed", () => { | ||
cy.get("input").type("A"); | ||
cy.get("input") | ||
.trigger("keydown", { code: "ArrowDown" }) | ||
.trigger("keydown", { code: "ArrowDown" }) | ||
.get(ITEMS_SELECTOR) | ||
.eq(1) | ||
.should("have.focus"); | ||
}); | ||
|
||
it("changes the focus when the up arrow is pressed", () => { | ||
cy.get("input").type("A"); | ||
|
||
cy.get("input") | ||
.trigger("keydown", { code: "ArrowDown" }) | ||
.trigger("keydown", { code: "ArrowDown" }) | ||
.get(ITEMS_SELECTOR) | ||
.eq(1) | ||
.should("have.focus"); | ||
|
||
cy.get("input") | ||
.trigger("keydown", { code: "ArrowUp" }) | ||
.get(ITEMS_SELECTOR) | ||
.eq(0) | ||
.should("have.focus"); | ||
}); | ||
|
||
it("stops changing focus when the down arrow is pressed at the last item", () => { | ||
cy.get("input").type("A"); | ||
|
||
cy.get("input") | ||
.trigger("keydown", { code: "ArrowDown" }) | ||
.trigger("keydown", { code: "ArrowDown" }) | ||
.trigger("keydown", { code: "ArrowDown" }) | ||
.trigger("keydown", { code: "ArrowDown" }) | ||
.trigger("keydown", { code: "ArrowDown" }) | ||
.get(ITEMS_SELECTOR) | ||
.eq(4) | ||
.should("have.focus"); | ||
|
||
cy.get("input") | ||
.trigger("keydown", { code: "ArrowDown" }) | ||
.get(ITEMS_SELECTOR) | ||
.eq(4) | ||
.should("have.focus"); | ||
}); | ||
|
||
it("focuses on the input when up arrow is pressed on the first item", () => { | ||
cy.get("input").type("A"); | ||
|
||
cy.get("input") | ||
.trigger("keydown", { code: "ArrowDown" }) | ||
.get(ITEMS_SELECTOR) | ||
.eq(0) | ||
.should("have.focus"); | ||
|
||
cy.get("input") | ||
.trigger("keydown", { code: "ArrowUp" }) | ||
.get("input") | ||
.should("have.focus"); | ||
}); | ||
|
||
it("closes the dropdown when clicked outside it", () => { | ||
cy.get("input") | ||
.type("A") | ||
.get("body") | ||
.click() | ||
.get(CONTAINER_SELECTOR) | ||
.should("not.be.visible"); | ||
}); | ||
|
||
it("closes the dropdown when Esc is pressed", () => { | ||
cy.get("input") | ||
.type("A") | ||
.trigger("keydown", { code: "Escape" }) | ||
.get(CONTAINER_SELECTOR) | ||
.should("not.be.visible") | ||
.get("input") | ||
.should("have.focus"); | ||
}); | ||
|
||
// Not implemented as Cypress has no Tab support | ||
// https://docs.cypress.io/api/commands/type#Tabbing | ||
xit("moves focus away from input if shift-tab is pressed", () => {}); | ||
|
||
// Not implemented as Cypress has no Tab support | ||
// https://docs.cypress.io/api/commands/type#Tabbing | ||
xit("closes the menu after pressing tab on the last item", () => {}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,3 @@ | ||
module AblyUi | ||
VERSION = '6.0.1' | ||
VERSION = '6.0.1.dev.6103afe' | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -32,6 +32,7 @@ module.exports = [ | |
"Icon", | ||
"Slider", | ||
"CustomerLogos", | ||
"CompanyAutocomplete", | ||
], | ||
}, | ||
{ | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
module Api | ||
class CompanyDataController < ApplicationController | ||
include ActionController::MimeResponds | ||
respond_to :json | ||
|
||
def companies | ||
render json: [ | ||
{ | ||
name: "Apple", | ||
domain: "apple.com", | ||
logo: "https://logo.clearbit.com/apple.com" | ||
}, | ||
{ | ||
name: "All Things Apple", | ||
domain: "apple.news", | ||
logo: "https://logo.clearbit.com/apple.news" | ||
}, | ||
{ | ||
name: "AppleInsider", | ||
domain: "appleinsider.com", | ||
logo: "https://logo.clearbit.com/appleinsider.com" | ||
}, | ||
{ | ||
name: "Applebee's Grill + Bar", | ||
domain: "applebees.com", | ||
logo: "https://logo.clearbit.com/applebees.com" | ||
}, | ||
{ | ||
name: "Apple Federal Credit Union", | ||
domain: "applefcu.org", | ||
logo: "https://logo.clearbit.com/applefcu.org" | ||
} | ||
] | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
20 changes: 20 additions & 0 deletions
20
preview/app/views/components/company_autocomplete_vw.html.erb
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<%= render(TitleComponent.new(react: false, vw: true)) do %> | ||
Company Autocomplete | ||
<% end %> | ||
|
||
<div class="max-w-screen-xs"> | ||
<input type="text" placeholder="Company name" class="w-full" /> | ||
</div> | ||
|
||
<% content_for :component do %> | ||
<%= javascript_include_tag 'ably_ui/core/company_autocomplete/component' %> | ||
|
||
<script type="text/javascript"> | ||
document.addEventListener("DOMContentLoaded", () => { | ||
const input = document.querySelector('input'); | ||
AblyUi.Core.CompanyAutocomplete(input, "/api/companies"); | ||
|
||
document.body.classList.add("bg-light-grey", "m-32"); | ||
}); | ||
</script> | ||
<% end %> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.