Skip to content

Commit

Permalink
Merge pull request #170 from OpenCovenant/correct_number_of_words
Browse files Browse the repository at this point in the history
Correct number of words
  • Loading branch information
AndersonCeci authored May 9, 2023
2 parents 01f574d + 6085a4d commit 49458f8
Show file tree
Hide file tree
Showing 5 changed files with 87 additions and 11 deletions.
22 changes: 16 additions & 6 deletions cypress/e2e/characters-words-markings.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,26 +5,36 @@ describe("its going to test if the characters change, words, typos change as we

it("will correctly update karaktere, fjalë, shenjime", () => {
cy.get("#editor > p > .typo").should("not.exist");

cy.get('[data-test="editor"]').type("gabmim ");
cy.wait(2000);
// TODO consider using should have text instead of contains
cy.get('[data-test="character-count"]')
cy.get('[data-test="characters-words-markings"]')
.contains("7 karaktere, 1 fjalë, 1 shenjim")
.should("exist");

cy.get('[data-test="editor"]').type(" gabim");
cy.get('[data-test="character-count"]')
cy.get('[data-test="characters-words-markings"]')
.contains("13 karaktere, 2 fjalë, 1 shenjim")
.should("exist");
cy.get('[data-test="editor"]').clear();
cy.get('[data-test="character-count"]')
cy.get('[data-test="clear-editor-icon"]').click();

cy.get('[data-test="editor"]').type("njeri-tjetri dhe ckemi ");
cy.get('[data-test="characters-words-markings"]')
.contains("24 karaktere, 3 fjalë, 2 shenjime")
.should("exist");
cy.get('[data-test="clear-editor-icon"]').click();
cy.get('[data-test="characters-words-markings"]')
.contains("0 karaktere, 0 fjalë, 0 shenjime")
.should("exist");

cy.get('[data-test="editor"]').type("{shift}");
cy.get('[data-test="character-count"]')
cy.get('[data-test="characters-words-markings"]')
.contains("0 karaktere, 0 fjalë, 0 shenjime")
.should("exist");

cy.get('[data-test="editor"]').type("{enter}");
cy.get('[data-test="character-count"]')
cy.get('[data-test="characters-words-markings"]')
.contains("0 karaktere, 0 fjalë, 0 shenjime")
.should("exist");
});
Expand Down
12 changes: 9 additions & 3 deletions cypress/e2e/expand-arrow.cy.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,9 @@ describe("click on expand/collapse arrow and then choose on a suggestion and che
cy.get('[data-test="suggestion"]').children().should("have.length", 8);
cy.get(
'[data-test="oscillate-suggestions-button"].bi-arrow-right-square'
).first().click();
)
.first()
.click();
cy.get(
'[data-test="oscillate-suggestions-button"].bi-arrow-right-square'
).click();
Expand All @@ -17,14 +19,18 @@ describe("click on expand/collapse arrow and then choose on a suggestion and che
.should("have.length.gt", 8);
cy.get(
'[data-test="oscillate-suggestions-button"].bi-arrow-left-square'
).first().click();
)
.first()
.click();
cy.get(
'[data-test="oscillate-suggestions-button"].bi-arrow-left-square'
).click();
cy.get('[data-test="suggestion"]').children().should("have.length", 8);
cy.get(
'[data-test="oscillate-suggestions-button"].bi-arrow-right-square'
).first().click();
)
.first()
.click();
cy.get(
'[data-test="oscillate-suggestions-button"].bi-arrow-right-square'
).click();
Expand Down
60 changes: 60 additions & 0 deletions mock-server/data/generateMarkingsForParagraphs.json
Original file line number Diff line number Diff line change
Expand Up @@ -1640,6 +1640,66 @@
}
]
}
},
{
"request": "<p>njeri-tjetri dhe&nbsp; ckemi&nbsp;</p>",
"response": {
"text": "<p>njeri-tjetri dhe&nbsp; ckemi&nbsp;</p>",
"textMarkings": [
{
"from": 0,
"to": 12,
"type": "typo",
"subtype": "gabim gramatikor, drejtshkrim",
"description": "kjo fjal\u00eb nuk ekziston, a doje t\u00eb shkruaje",
"suggestions": [
{
"display": "nj\u00ebri-tjetri",
"action": "nj\u00ebri-tjetri"
}
],
"paragraph": 0
},
{
"from": 18,
"to": 23,
"type": "typo",
"subtype": "gabim gramatikor, drejtshkrim",
"description": "kjo fjal\u00eb nuk ekziston, a doje t\u00eb shkruaje",
"suggestions": [
{
"display": "cekemi",
"action": "cekemi"
},
{
"display": "kemin",
"action": "kemin"
},
{
"display": "kemi",
"action": "kemi"
},
{
"display": "\u00e7'kemi",
"action": "\u00e7'kemi"
},
{
"display": "kemit",
"action": "kemit"
},
{
"display": "cekem",
"action": "cekem"
},
{
"display": "cikem",
"action": "cikem"
}
],
"paragraph": 0
}
]
}
}
]

2 changes: 1 addition & 1 deletion src/app/home/home.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@
align-content: center;
flex-direction: column;
"
data-test="character-count"
data-test="characters-words-markings"
>{{ characterCount }}&nbsp;{{
characterCount === 1 ? "karakter" : "karaktere"
}}&comma;&nbsp;{{ wordCount }}&nbsp;fjalë&comma;&nbsp;{{
Expand Down
2 changes: 1 addition & 1 deletion src/app/home/home.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@ export class HomeComponent implements AfterViewInit, OnDestroy {
if (editor.innerText === this.EMPTY_STRING) {
this.wordCount = 0;
} else {
const wordMatches = editor.innerText.match(/\b(\w+)\b/g)!;
const wordMatches = editor.innerText.match(/\b([\w'-]+)\b/g)!;
if (wordMatches) {
this.wordCount = wordMatches.length;
} else {
Expand Down

0 comments on commit 49458f8

Please sign in to comment.