Repository navigation
fix: react to provider set after the first update #577
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
uniqueg
wants to merge
9
commits into
dev
Choose a base branch
from
fix/565-provider-lifecycle
base: dev
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
+2,023
−62
Open
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
8c8bd63
fix: react to provider set after the first update
uniqueg 4ec93f6
docs: describe setting providers after rendering
uniqueg 7d90fd1
fix: drop stale loads after a provider switch
uniqueg b3e431a
fix: stop loading when the provider is removed
uniqueg 2a14d26
Merge branch 'dev' into fix/565-provider-lifecycle
uniqueg 734ff52
test: run at most three test suites at once
uniqueg 7f28a3e
fix: clear old provider data on failed loads
uniqueg 7699902
fix: report a removed provider in the tool form
uniqueg 29510bd
test: cover the REST providers
uniqueg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
152 changes: 152 additions & 0 deletions
152
packages/ecc-client-elixir-trs-filer/src/components/tool-create/tests/tool-create.test.ts
This file contains hidden or 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,152 @@ | ||
| /* eslint-disable import/no-extraneous-dependencies */ | ||
| import { expect, fixture, html, oneEvent, waitUntil } from "@open-wc/testing"; | ||
| import sinon from "sinon"; | ||
| import "../index.js"; | ||
| import type { ECCClientElixirTrsToolCreate } from "../tool-create.js"; | ||
| import type { TrsFilerProvider } from "../../../providers/index.js"; | ||
|
|
||
| const BASE_URL = "https://trs.example.org/ga4gh/trs/v2"; | ||
| const OTHER_URL = "https://other.example.org/ga4gh/trs/v2"; | ||
|
|
||
| type ToolClass = { id: string; name: string }; | ||
|
|
||
| /** | ||
| * A provider whose tool class list is a stub; the form loads nothing else | ||
| * before a submit. | ||
| */ | ||
| const stubProvider = ( | ||
| classes: ToolClass[] | Promise<ToolClass[]> = [ | ||
| { id: "workflow", name: "Workflow" }, | ||
| ] | ||
| ) => { | ||
| const stubs = { | ||
| getToolClasses: sinon.stub().callsFake(async () => classes), | ||
| }; | ||
| return { stubs, provider: stubs as unknown as TrsFilerProvider }; | ||
| }; | ||
|
|
||
| /** A promise and the function that resolves it. */ | ||
| const deferred = <T>() => { | ||
| let settleWith: (value: T) => void = () => undefined; | ||
| const promise = new Promise<T>((resolve) => { | ||
| settleWith = resolve; | ||
| }); | ||
| return { promise, resolve: settleWith }; | ||
| }; | ||
|
|
||
| /** The tool classes the form offers. */ | ||
| const offered = (el: ECCClientElixirTrsToolCreate) => | ||
| (el as unknown as { toolClasses: ToolClass[] }).toolClasses; | ||
|
|
||
| describe("ecc-client-elixir-trs-tool-create provider", () => { | ||
| let fetchStub: sinon.SinonStub; | ||
|
|
||
| beforeEach(() => { | ||
| fetchStub = sinon.stub(window, "fetch").callsFake( | ||
| async () => | ||
| new Response(JSON.stringify([]), { | ||
| headers: { "Content-Type": "application/json" }, | ||
| }) | ||
| ); | ||
| }); | ||
|
|
||
| afterEach(() => { | ||
| sinon.restore(); | ||
| }); | ||
|
|
||
| it("loads from a provider set after the first update", async () => { | ||
| const el = await fixture<ECCClientElixirTrsToolCreate>( | ||
| html`<ecc-client-elixir-trs-tool-create></ecc-client-elixir-trs-tool-create>` | ||
| ); | ||
| const { stubs, provider } = stubProvider(); | ||
|
|
||
| el.provider = provider; | ||
| await waitUntil(() => offered(el)[0]?.id === "workflow"); | ||
|
|
||
| expect(stubs.getToolClasses.callCount).to.equal(1); | ||
| expect(fetchStub.callCount).to.equal(0); | ||
| }); | ||
|
|
||
| it("loads from a provider that replaces the first one", async () => { | ||
| const first = stubProvider(); | ||
| const second = stubProvider([{ id: "tool", name: "Tool" }]); | ||
| const el = await fixture<ECCClientElixirTrsToolCreate>( | ||
| html`<ecc-client-elixir-trs-tool-create | ||
| .provider=${first.provider} | ||
| ></ecc-client-elixir-trs-tool-create>` | ||
| ); | ||
| await waitUntil(() => offered(el)[0]?.id === "workflow"); | ||
|
|
||
| el.provider = second.provider; | ||
| await waitUntil(() => offered(el)[0]?.id === "tool"); | ||
|
|
||
| expect(first.stubs.getToolClasses.callCount).to.equal(1); | ||
| }); | ||
|
|
||
| it("drops a slower load from a replaced provider", async () => { | ||
| const slow = deferred<ToolClass[]>(); | ||
| const first = stubProvider(slow.promise); | ||
| const second = stubProvider([{ id: "tool", name: "Tool" }]); | ||
| const el = await fixture<ECCClientElixirTrsToolCreate>( | ||
| html`<ecc-client-elixir-trs-tool-create | ||
| .provider=${first.provider} | ||
| ></ecc-client-elixir-trs-tool-create>` | ||
| ); | ||
|
|
||
| el.provider = second.provider; | ||
| await waitUntil(() => offered(el)[0]?.id === "tool"); | ||
| slow.resolve([{ id: "workflow", name: "Workflow" }]); | ||
| await slow.promise; | ||
| await el.updateComplete; | ||
|
|
||
| expect(offered(el)[0].id).to.equal("tool"); | ||
| }); | ||
|
|
||
| it("keeps a provider when the base URL is set too", async () => { | ||
| const { stubs, provider } = stubProvider(); | ||
| const el = await fixture<ECCClientElixirTrsToolCreate>( | ||
| html`<ecc-client-elixir-trs-tool-create | ||
| .provider=${provider} | ||
| ></ecc-client-elixir-trs-tool-create>` | ||
| ); | ||
| await waitUntil(() => stubs.getToolClasses.callCount === 1); | ||
|
|
||
| el.baseUrl = BASE_URL; | ||
| await el.updateComplete; | ||
|
|
||
| expect(stubs.getToolClasses.callCount).to.equal(1); | ||
| expect(fetchStub.callCount).to.equal(0); | ||
| }); | ||
|
|
||
| it("loads from the base URL and reloads when it changes", async () => { | ||
| const el = await fixture<ECCClientElixirTrsToolCreate>( | ||
| html`<ecc-client-elixir-trs-tool-create | ||
| .baseUrl=${BASE_URL} | ||
| ></ecc-client-elixir-trs-tool-create>` | ||
| ); | ||
| await waitUntil(() => fetchStub.callCount === 1); | ||
|
|
||
| el.baseUrl = OTHER_URL; | ||
| await waitUntil(() => fetchStub.callCount === 2); | ||
|
|
||
| expect(fetchStub.firstCall.args[0]).to.equal(`${BASE_URL}/toolClasses`); | ||
| expect(fetchStub.secondCall.args[0]).to.equal(`${OTHER_URL}/toolClasses`); | ||
| }); | ||
|
|
||
| it("offers no tool classes once the provider is removed without a base URL", async () => { | ||
| const { provider } = stubProvider(); | ||
| const el = await fixture<ECCClientElixirTrsToolCreate>( | ||
| html`<ecc-client-elixir-trs-tool-create | ||
| .provider=${provider} | ||
| ></ecc-client-elixir-trs-tool-create>` | ||
| ); | ||
| await waitUntil(() => offered(el).length === 1); | ||
| const failed = oneEvent(el, "ecc-tool-create-validation-failed"); | ||
|
|
||
| el.provider = undefined; | ||
| await el.updateComplete; | ||
|
|
||
| expect(offered(el)).to.deep.equal([]); | ||
| expect((await failed).detail.error).to.contain("Please provide either"); | ||
| }); | ||
| }); |
This file contains hidden or 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.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.