main

mattermost/focalboard

Last updated at: 29/12/2023 09:50

boardView.test.ts

TLDR

The boardView.test.ts file contains tests for the sortBoardViewsAlphabetically function in the boardView.ts file. The tests cover different scenarios of sorting board views alphabetically.

Methods

sortBoardViewsAlphabetically

The sortBoardViewsAlphabetically method takes an array of board views and sorts them in alphabetical order based on the title of each view. The sorting is case-sensitive and considers ASCII characters, leading emojis, and non-Latin characters.

END

// Copyright (c) 2015-present Mattermost, Inc. All Rights Reserved.
// See LICENSE.txt for license information.

import {TestBlockFactory} from '../test/testBlockFactory'

import {sortBoardViewsAlphabetically} from './boardView'

test('boardView: sort with ASCII', async () => {
    const view1 = TestBlockFactory.createBoardView()
    view1.title = 'Maybe'
    const view2 = TestBlockFactory.createBoardView()
    view2.title = 'Active'

    const views = [view1, view2]
    const sorted = sortBoardViewsAlphabetically(views)
    expect(sorted).toEqual([view2, view1])
})

test('boardView: sort with leading emoji', async () => {
    const view1 = TestBlockFactory.createBoardView()
    view1.title = '🤔 Maybe'
    const view2 = TestBlockFactory.createBoardView()
    view2.title = '🚀 Active'

    const views = [view1, view2]
    const sorted = sortBoardViewsAlphabetically(views)
    expect(sorted).toEqual([view2, view1])
})

test('boardView: sort with non-latin characters', async () => {
    const view1 = TestBlockFactory.createBoardView()
    view1.title = 'zebra'
    const view2 = TestBlockFactory.createBoardView()
    view2.title = 'ñu'

    const views = [view1, view2]
    const sorted = sortBoardViewsAlphabetically(views)
    expect(sorted).toEqual([view2, view1])
})