-
Notifications
You must be signed in to change notification settings - Fork 2
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 #3 from alireza-ab/master
feat: add toPersian directive
- Loading branch information
Showing
5 changed files
with
88 additions
and
2 deletions.
There are no files selected for viewing
44 changes: 44 additions & 0 deletions
44
src/directives/toPersian/__tests__/toPersianDirective.spec.ts
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,44 @@ | ||
import { mount } from "@vue/test-utils"; | ||
import toPersian from "../index"; | ||
|
||
describe("toPersian", () => { | ||
const cmp = { | ||
props: ["val"], | ||
directives: { | ||
toPersian | ||
}, | ||
template: "<div v-to-persian>{{val}}</div>" | ||
}; | ||
it("should convert to persian chars", async () => { | ||
const url = `كيك`; | ||
|
||
const wrapper = mount(cmp, { | ||
propsData: { | ||
val: url | ||
} | ||
}); | ||
|
||
expect(wrapper.text()).toBe("کیک"); | ||
}); | ||
it("should empty if prop is empty", () => { | ||
const wrapper = mount(cmp); | ||
|
||
expect(wrapper.text()).toBe(""); | ||
}); | ||
|
||
const cmpSync = { | ||
directives: { | ||
toPersian | ||
}, | ||
template: "<input v-to-persian.sync />" | ||
}; | ||
it("should replace convert to persian chars in typing", async () => { | ||
const url = `كيك`; | ||
|
||
const wrapper = mount(cmpSync); | ||
const input = wrapper.find("input"); | ||
await input.setValue(url); | ||
|
||
expect(wrapper.find("input").element.value).toBe("کیک"); | ||
}); | ||
}); |
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,4 @@ | ||
import found from "../helpers/foundation"; | ||
import { toPersianChars } from "@persian-tools/persian-tools"; | ||
|
||
export default found(toPersianChars, "toPersian"); |
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,38 @@ | ||
import toPersian from "../../src/directives/toPersian/index"; | ||
const Template = (args: any) => ({ | ||
directives: { toPersian: toPersian }, | ||
setup() { | ||
return { | ||
text: args.val | ||
}; | ||
}, | ||
template: `<div> | ||
<div><strong>Text:</strong> {{text}}</div> | ||
<br /> | ||
<div><strong>Fixed text:</strong> <span v-to-persian>{{text}}</span></div> | ||
<br /> | ||
<input :value="text" v-to-persian.sync /> | ||
</div>` | ||
}); | ||
|
||
export const Default = Template.bind({}); | ||
Default.args = { val: "علي كيك خورد." }; | ||
|
||
export default { | ||
title: "Directives/toPersian", | ||
argTypes: { | ||
val: { | ||
name: "str", | ||
type: { name: "string", required: true }, | ||
defaultValue: null, | ||
description: "Description: Replaces all instances of ي and ك withی and ک, respectively. It should not make any ch anges to Arabic text surrounded by appropriate templates.", | ||
table: { | ||
type: { summary: "string" }, | ||
defaultValue: { summary: "null" } | ||
}, | ||
control: { | ||
type: "text" | ||
} | ||
} | ||
} | ||
}; |
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