Skip to content

Better tests for lib/sort.js #300

@dreeves

Description

@dreeves

Now that we've refactored the gallery sorting code to compute a sort index for every promise and sort by that single number, we could make the tests simpler by dropping the need for pairwise comparisons.

Instead just define a big list of different kinds of promises, listed in the order they ought to be in in a user's gallery. Then just compute the sort index for each promise and check that those numbers are sorted in ascending order.

Relevant types of promises, listed in the order they should sort in:

  1. tini and tdue and tfin all null (or undefined?)
  2. tini a week ago and tdue and tfin both null
  3. tini a day ago and tdue and tfin both null
  4. tini is anything, tdue is today, tfin is null [scheldist 0]
  5. tini is anything, tdue is 2 days ago, tfin is null [scheldist 1]
  6. tini is anything, tdue is 2 days from now, tfin is null [scheldist 2]
  7. tini is anything, tdue is 4 days ago, tfin is null [scheldist 3]
  8. tini is anything, tdue is 4 days from now, tfin is null [scheldist 4]
  9. tini is anything, tdue is 12 days ago, tfin is null [scheldist 5]
  10. tini is anything, tdue is 24 days ago, tfin is null [scheldist 6]
  11. tini is anything, tdue is 7 days from now, tfin is null [scheldist 7]
  12. tini is anything, tdue is anything, tfin is yesterday
  13. tini is anything, tdue is anything, tfin is a week ago

So number 1 is a promise that's messed up and should sort to the very top, next are numbers 2-3 which sort by increasing creation date because they have no due dates, after that are numbers 4-11 which are incomplete promises sorted by urgency (Schelling distance), and finally numbers 12-13 are completed promises sorted by decreasing completion date.

For the "is anything" values it shouldn't matter to the sorting how those are filled in so just pick random dates and make some of them are null to ensure that doesn't break anything either.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions