-
-
Notifications
You must be signed in to change notification settings - Fork 199
fix(file): name the |type: in FILE picker default labels #1805
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
Merged
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,86 @@ | ||
| import { afterEach, beforeEach, describe, expect, it } from "vitest"; | ||
| import type IChoice from "../../src/types/choices/IChoice"; | ||
| import { TemplateChoice } from "../../src/types/choices/TemplateChoice"; | ||
| import { createQuickAddE2EHarness, seedVaultFile } from "./e2eVault"; | ||
| import { POLL_OPTS, expectNoPrompt, pressKey, typeInto, waitForElement } from "./uiHelpers"; | ||
|
|
||
| // Two `{{FILE:<folder>|type:...}}` pickers on one folder and mode get default | ||
| // labels that name their type, so a one-page form can tell them apart. | ||
| const getContext = createQuickAddE2EHarness("file-type-label"); | ||
|
|
||
| type QuickAddData = { | ||
| choices: IChoice[]; | ||
| onePageInputEnabled: boolean; | ||
| }; | ||
|
|
||
| async function closeOpenPrompts() { | ||
| const { obsidian } = getContext(); | ||
| for (let remaining = 10; remaining > 0; remaining--) { | ||
| if (!await obsidian.dev.evalJson<boolean>('Boolean(document.querySelector(".modal-container, .prompt"))')) break; | ||
| await pressKey(obsidian, "Escape"); | ||
| } | ||
| await expectNoPrompt(obsidian); | ||
| } | ||
|
|
||
| beforeEach(closeOpenPrompts); | ||
| afterEach(closeOpenPrompts); | ||
|
|
||
| async function pick(selector: string, typed: string, expected: string) { | ||
| const { obsidian } = getContext(); | ||
| // A single picker preselects its first file and hides picked files from | ||
| // its suggestions, so clear it before searching. | ||
| await obsidian.dev.evalJson(`document.querySelector(${JSON.stringify(selector)}) | ||
| ?.closest(".qa-onepage-file-picker") | ||
| ?.querySelectorAll(".qa-onepage-file-picker__remove") | ||
| .forEach((button) => button.click())`); | ||
| await typeInto(obsidian, selector, typed); | ||
| // A suggestion reads as the file name followed by its path. | ||
| await expect.poll(() => obsidian.dev.evalJson<boolean>( | ||
| `document.querySelector(".suggestion-container .suggestion-item")?.textContent?.startsWith(${JSON.stringify(expected)}) ?? false`, | ||
| ), POLL_OPTS).toBe(true); | ||
| await pressKey(obsidian, "Enter"); | ||
| } | ||
|
|
||
| describe("FILE |type: default label", () => { | ||
| it("names each one-page attachment picker after its type", async () => { | ||
| const { obsidian, plugin, sandbox } = getContext(); | ||
| await seedVaultFile(obsidian, sandbox, "Attachments/photo.png", "png"); | ||
| await seedVaultFile(obsidian, sandbox, "Attachments/scan.pdf", "pdf"); | ||
| const folder = sandbox.path("Attachments"); | ||
| const template = new TemplateChoice("Attachment pair"); | ||
| template.command = true; | ||
| template.templatePath = await seedVaultFile( | ||
| obsidian, | ||
| sandbox, | ||
| "attachment-template.md", | ||
| `image: {{FILE:${folder}|type:image|link}}\npdf: {{FILE:${folder}|type:pdf|link}}\n`, | ||
| ); | ||
| template.fileNameFormat = { enabled: true, format: "attachment pair" }; | ||
| template.folder = { ...template.folder, enabled: true, folders: [sandbox.path("out")] }; | ||
| await plugin.data<QuickAddData>().patch((data) => { | ||
| data.onePageInputEnabled = true; | ||
| data.choices.push(template); | ||
| }); | ||
| await plugin.reload({ waitUntilReady: true }); | ||
| await obsidian.exec("command", { id: `quickadd:choice:${template.id}` }); | ||
|
|
||
| await waitForElement(obsidian, ".onePageInputModal"); | ||
| expect(await obsidian.dev.evalJson<string[]>( | ||
| 'Array.from(document.querySelectorAll(".onePageInputModal .setting-item-name")).map((name) => name.textContent)', | ||
| )).toEqual([ | ||
| `File from ${folder} (image, link)`, | ||
| `File from ${folder} (pdf, link)`, | ||
| ]); | ||
|
|
||
| const field = (qualifiers: string) => | ||
| `.onePageInputModal input[aria-label=${JSON.stringify( | ||
| `Choose file for File from ${folder} (${qualifiers})`, | ||
| )}]`; | ||
| await pick(field("image, link"), "pho", "photo.png"); | ||
| await pick(field("pdf, link"), "sca", "scan.pdf"); | ||
| await pressKey(obsidian, "Enter", true); | ||
| await expectNoPrompt(obsidian); | ||
| await expect.poll(() => sandbox.read("out/attachment pair.md").catch(() => ""), POLL_OPTS) | ||
| .toBe(`image: [[${folder}/photo.png]]\npdf: [[${folder}/scan.pdf]]\n`); | ||
| }); | ||
| }); |
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.