fix first status count

This commit is contained in:
Nicolas Constant 2020-09-02 18:43:04 -04:00
parent 8f719c515b
commit 0e23b64b63
No known key found for this signature in database
GPG Key ID: 1E9F677FB01A5688
2 changed files with 27 additions and 3 deletions

View File

@ -164,6 +164,23 @@ describe('CreateStatusComponent', () => {
expect(result.length).toBe(1); expect(result.length).toBe(1);
}); });
it('should cound URL correctly', () => {
const newLine = String.fromCharCode(13, 10);
const status = `qsddq sqd qsd qsdqs dqsd qsd qsd qsd qsd qsd qsd qsd qsd qs dqsd qsd qsd qsd qsd qsddq sqd qsd qsdqs dqsd qsd qsd qsd qsd qsd qsd https://google.com/testqsdqsdqsdqsdqsdqsdqsdqdqsdqsdqsdqsdqs dsqd qsd qsd dsqdqs dqs dqsd qsd qsd qsd qsd qsd qs dqsdsq qsd qsd qs dsqds qqs d dqs dqs dqs dqqsd qsd qsd qsd sqd qsd qsd sqd qds dsqd qsddq sqd qsd qsdqs dqsd qsd qsd qsd qsd qsd qsd qsd qsd qs dqsd qsd qsd qsd qsd qsddq sqd qsd qsdqs dqsd qsd qsd qsd qsd qsd qsd dsqd qsd qsd dsqdqs fqd dsq sq dsq qsd q qsd qsd qs dqs dqs qsd qsd qss sq ss s`;
(<any>component).maxCharLength = 500;
(<any>component).countStatusChar(status);
expect((<any>component).charCountLeft).toBe(0);
});
it('should cound URL correctly - new lines', () => {
const status = `qsddq sqd qsd qsdqs dqsd qsd qsd qsd qsd qsd qsd qsd qsd qs dqsd qsd qsd qsd qsd qsddq sqd qsd qsdqs dqsd qsd qsd qsd qsd qsd qsd\nhttps://google.com/testqsdqsdqsdqsdqsdqsdqsdqdqsdqsdqsdqsdqs\ndsqd qsd qsd dsqdqs dqs dqsd qsd qsd qsd qsd qsd qs dqsdsq qsd qsd qs dsqds qqs d dqs dqs dqs dqqsd qsd qsd qsd sqd qsd qsd sqd qds dsqd qsddq sqd qsd qsdqs dqsd qsd qsd qsd qsd qsd qsd qsd qsd qs dqsd qsd qsd qsd qsd qsddq sqd qsd qsdqs dqsd qsd qsd qsd qsd qsd qsd dsqd qsd qsd dsqdqs fqd dsq sq dsq qsd q qsd qsd qs dqs dqs qsd qsd qss sq ss s`;
(<any>component).maxCharLength = 500;
(<any>component).countStatusChar(status);
expect((<any>component).charCountLeft).toBe(0);
});
it('should add alias in multiposting replies', () => { it('should add alias in multiposting replies', () => {
const status = '@Lorem@ipsum.com ipsum dolor sit amet, consectetur adipiscing elit. Mauris sed ante id dolor vulputate pulvinar sit amet a nisl. Duis sagittis nisl sit amet est rhoncus rutrum. Duis aliquet eget erat nec molestie. Fusce bibendum consectetur rhoncus. Aenean vel neque ac diam hendrerit interdum id a nisl. Aenean leo ante, luctus eget erat at, interdum tincidunt turpis. Donec non efficitur magna. Nam placerat convallis tincidunt. Etiam ac scelerisque velit, at vestibulum turpis. In hac habitasse platea dictu0'; const status = '@Lorem@ipsum.com ipsum dolor sit amet, consectetur adipiscing elit. Mauris sed ante id dolor vulputate pulvinar sit amet a nisl. Duis sagittis nisl sit amet est rhoncus rutrum. Duis aliquet eget erat nec molestie. Fusce bibendum consectetur rhoncus. Aenean vel neque ac diam hendrerit interdum id a nisl. Aenean leo ante, luctus eget erat at, interdum tincidunt turpis. Donec non efficitur magna. Nam placerat convallis tincidunt. Etiam ac scelerisque velit, at vestibulum turpis. In hac habitasse platea dictu0';
(<any>component).maxCharLength = 500; (<any>component).maxCharLength = 500;

View File

@ -474,8 +474,8 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
} }
const currentStatus = parseStatus[parseStatus.length - 1]; const currentStatus = parseStatus[parseStatus.length - 1];
const statusExtraChars = this.getMentionExtraChars(status); const statusExtraChars = this.getMentionExtraChars(currentStatus);
const linksExtraChars = this.getLinksExtraChars(status); const linksExtraChars = this.getLinksExtraChars(currentStatus);
const statusLength = [...currentStatus].length - statusExtraChars - linksExtraChars; const statusLength = [...currentStatus].length - statusExtraChars - linksExtraChars;
this.charCountLeft = this.maxCharLength - statusLength - this.getCwLength(); this.charCountLeft = this.maxCharLength - statusLength - this.getCwLength();
@ -634,7 +634,10 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
} }
private parseStatus(status: string): string[] { private parseStatus(status: string): string[] {
//console.error(status.toString());
let mentionExtraChars = this.getMentionExtraChars(status); let mentionExtraChars = this.getMentionExtraChars(status);
let urlExtraChar = this.getLinksExtraChars(status);
let trucatedStatus = `${status}`; let trucatedStatus = `${status}`;
let results = []; let results = [];
@ -644,7 +647,7 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
aggregateMention += `${x} `; aggregateMention += `${x} `;
}); });
const currentMaxCharLength = this.maxCharLength + mentionExtraChars - this.getCwLength(); const currentMaxCharLength = this.maxCharLength + mentionExtraChars + urlExtraChar - this.getCwLength();
const maxChars = currentMaxCharLength - 6; const maxChars = currentMaxCharLength - 6;
while (trucatedStatus.length > currentMaxCharLength) { while (trucatedStatus.length > currentMaxCharLength) {
@ -658,6 +661,10 @@ export class CreateStatusComponent implements OnInit, OnDestroy {
trucatedStatus = aggregateMention + trucatedStatus.substr(nextIndex + 1); trucatedStatus = aggregateMention + trucatedStatus.substr(nextIndex + 1);
} }
results.push(trucatedStatus); results.push(trucatedStatus);
console.warn(`this.maxCharLength ${this.maxCharLength}`)
console.warn(results);
return results; return results;
} }