Skip to content

Commit

Permalink
Merge pull request #3 from alireza-ab/master
Browse files Browse the repository at this point in the history
feat: add toPersian directive
  • Loading branch information
mediv0 authored May 30, 2021
2 parents 28bc6a0 + ef8f429 commit 7a6bc6b
Show file tree
Hide file tree
Showing 5 changed files with 88 additions and 2 deletions.
44 changes: 44 additions & 0 deletions src/directives/toPersian/__tests__/toPersianDirective.spec.ts
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("کیک");
});
});
4 changes: 4 additions & 0 deletions src/directives/toPersian/index.ts
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");
2 changes: 1 addition & 1 deletion src/directives/urlFix/__tests__/urlFixDirective.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ describe("urlFix", () => {
},
template: "<input v-url-fix.sync />"
};
it("should replace space with urlFix in typing", async () => {
it("should fix url in typing", async () => {
const url = `https://fa.wikipedia.org/wiki/%D9%85%D8%AF%DB%8C%D8%A7%D9%88%DB%8C%DA%A9%DB%8C:Gadget-Extra-Editbuttons-botworks.js`;

const wrapper = mount(cmpSync);
Expand Down
38 changes: 38 additions & 0 deletions stories/directives/toPersianDirective.story.ts
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"
}
}
}
};
2 changes: 1 addition & 1 deletion stories/directives/urlFixDirective.story.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ export default {
name: "str",
type: { name: "string", required: true },
defaultValue: null,
description: "Replace spaces for given text with urlFix.",
description: "url that need to be fixed",
table: {
type: { summary: "string" },
defaultValue: { summary: "null" }
Expand Down

0 comments on commit 7a6bc6b

Please sign in to comment.