publiclab / PublicLab.Editor

A general purpose, JS/Bootstrap UI framework for rich text posting. An author-friendly, minimal, mobile/desktop interface for creating blog-like content, designed for PublicLab.org

Home Page:https://publiclab.github.io/PublicLab.Editor/examples/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

add history test to Jest test suite

TildaDares opened this issue Β· comments

Hi, this is a first-timers-only issue. This means we've worked to make it more legible to folks who either haven't contributed to our codebase before, or even folks who haven't contributed to open source before.

If that's you, we're interested in helping you take the first step and can answer questions and help you out as you do. Note that we're especially interested in contributions from people from groups underrepresented in free and open source software!

We know that the process of creating a pull request is the biggest barrier for new contributors. This issue is for you πŸ’

If you have contributed before, consider leaving this one for someone new, and looking through our general help wanted issues. Thanks!

πŸ€” What you will need to know.

Nothing. This issue is meant to welcome you to Open Source :) We are happy to walk you through the process.

πŸ“‹ Step by Step

  • πŸ™‹ Claim this issue: Comment below. If someone else has claimed it, ask if they've opened a pull request already and if they're stuck -- maybe you can help them solve a problem or move it along!

  • πŸ“ Update the file test/ui-testing/history.test.js in the PublicLab.Editor repository (press the little pen Icon) and edit the line as shown below.

See this page for some help in taking your first steps!

Below is a "diff" showing in red (and a -) which lines to remove, and in green (and a +) which lines to add:

@@ -7,8 +7,102 @@ beforeAll(async () => {
 
 describe('History functions', () => {
 
-  test('something we are testing described here', () => {
+  let editor;
+  beforeAll(() => {
+    editor = new PL.Editor({
+      textarea: $('.ple-textarea')[0]
+    });
+  })
 
+  test('has log, key, interval, and id', () => {
+    expect(editor.history.log).not.toBeUndefined();
+    expect(editor.history.key).not.toBeUndefined();
+    expect(editor.history.options).not.toBeUndefined();
+    expect(editor.history.options.interval).not.toBeUndefined();
+    expect(editor.history.options.id).not.toBeUndefined();
+  });
 
+  test('can be flushed', () => {
+    expect(editor.history.fetch()).not.toEqual([]);
+    expect(editor.history.last()).not.toBe(null);
+
+    editor.history.flush();
+
+    expect(editor.history.fetch()).toEqual([]);
+    expect(editor.history.last()).toBe(null);
+  });
+
+  test('adds, fetches, and stores', () => {
+    editor.history.flush();
+    expect(editor.history.fetch()).toEqual([]);
+    expect(editor.history.last()).toBe(null);
+
+    expect($('.ple-history-saving').is(':visible')).toBe(false);
+    editor.history.add("some text");
+    expect(editor.history.last().text).toBe("some text");
+    expect(editor.history.last().timestamp).not.toBeUndefined();
+
+    expect(editor.history.fetch().length).toEqual(1);
+    expect(editor.history.last().text).toBe("some text");
+
+    editor.history.add("some more text");
+    expect(editor.history.last().text).toBe("some more text");
+    expect(editor.history.last().timestamp).not.toBeUndefined();
+
+    expect(editor.history.fetch().length).toEqual(2);
+    expect(editor.history.last().text).toBe("some more text");
+  });
+
+  test('creates new log entry when value() set', () => {
+    expect($(editor.richTextModule.options.textarea).length).toBeGreaterThan(0);
+    editor.richTextModule.value("changed textarea text");
+    editor.history.check();
+    expect(editor.history.last().text).toBe("changed textarea text");
+  });
+
+  test('stores only 20 items until we optimize it', () => {
+    editor.history.flush();
+    for (var i = 0; i < 10; i++) {
+      editor.history.add("some text " + i);
+    }
+    expect(editor.history.log.length).toBe(10);
+
+    for (var i = 10; i < 20; i++) {
+      editor.history.add("some text " + i);
+      expect(editor.history.log[editor.history.log.length - 1].text).toBe("some text " + i);
+    }
+    expect(editor.history.log.length).toBe(20);
+
+    for (var i = 20; i < 30; i++) {
+      editor.history.add("some text " + i);
+    }
+    expect(editor.history.log.length).toBe(20);
+
+    editor.history.fetch();
+    expect(editor.history.log.length).toBe(20);
+    expect(editor.history.log[0].text).toBe('some text 10');
+  });
+
+  test('writes out history to a DOM element', () => {
+    $('body').append("<div id='history'></div>");
+
+    editor.history.display($('#history')[0]);
+
+    expect(editor.history.log.length).not.toBe(0);
+    expect($('#history').html()).not.toBe('');
+    expect($('#history p.log').length).toBe(20);
+    expect($('#history p.day').length).toBe(1);
+
+    // start over and build DOM, checking as we go:
+    editor.history.log = [];
+
+    for (var i = 0; i < 10; i++) {
+      editor.history.add("some text " + i);
+      editor.history.display($('#history')[0]);
+      expect($('#history p.log').length).toBe(1 + i);
+      expect($('#history p.log:last .preview').html()).toBe("some text " + i + "...");
+    }
+    expect($('#history p.day').length).toBe(1);
+   });
+
 }, timeout);
  • πŸ’Ύ Commit your changes

  • πŸ”€ Start a Pull Request. There are two ways how you can start a pull request:

  1. If you are familiar with the terminal or would like to learn it, here is a great tutorial on how to send a pull request using the terminal.

  2. You can also edit files directly in your browser and open a pull request from there.

  • 🏁 Done Ask in comments for a review :)

Please keep us updated

πŸ’¬β° - We encourage contributors to be respectful to the community and provide an update within a week of claiming a first-timers-only issue. We're happy to keep it assigned to you as long as you need if you update us with a request for more time or help, but if we don't see any activity a week after you claim it we may reassign it to give someone else a chance. Thank you in advance!

If this happens to you, don't sweat it! Grab another open issue.

Is someone else already working on this?

πŸ”—- We encourage contributors to link to the original issue in their pull request so all users can easily see if someone's already started on it.

πŸ‘₯- If someone seems stuck, offer them some help! Otherwise, take a look at some other issues you can help with. Thanks!

πŸ€”β“ Questions?

Leave a comment below!

can i work on this?

@wellart was the first to indicate to work on this and I respect it but should wellart change his/her mind, I'm willing to work on it. Thank you.

Yes you can @wellart πŸŽ‰

Is issue is solves?
Can I work on this

@wellart @TildaDares
Is the issue solved_ or I can contribute in this issue

I think the issue is still open. Can I work on it?

Hello, @vaishnavighiradkar I'm currently working on this. This issue has a bit of complication which we experienced with other test files as well and so adding these changes wouldn't make it work. I'm putting up a document to add some explanations on how we can make the tests work.