<commit_before>// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

import { BeatmapsetSearchFilters } from 'beatmapset-search-filters';

describe('BeatmapsetSearchFilters', () => {
  let subject: BeatmapsetSearchFilters;

  describe('.query', () => {
    beforeEach(() => {
      subject = new BeatmapsetSearchFilters('https://notarealdomain');
    });

    it('should remove leading whitespace', () => {
      subject.query = '  whee 12 ああ';

      expect(subject.query).toBe('whee 12 ああ');
    });

    it('should remove trailing whitespace', () => {
      subject.query = 'whee 12 ああ  ';

      expect(subject.query).toBe('whee 12 ああ');
    });

    it('should treat empty string as null', () => {
      subject.query = '';

      // type inference was a bit _too_ smart.
      expect(subject.query as string | null).toBe(null);
    });
  });

  describe('.update', () => {
    beforeEach(() => {
      subject = new BeatmapsetSearchFilters('https://notarealdomain/?sort=title_desc');
    });

    it('should reset sort when query changes', () => {
      subject.update({ query: 'foo' });

      expect(subject.sort).toBeNull();
    });

    it('should reset sort when status changes', () => {
      subject.update({ status: 'foo' });

      expect(subject.sort).toBeNull();
    });

    it('should not reset sort if status nor query changes', () => {
      subject.update({ genre: 'bar', mode: 'osu' });

      expect(subject.sort).toBe('title_desc');
    });
  });
});<commit_msg>update tests<commit_after>// Copyright (c) ppy Pty Ltd <<EMAIL>>. Licensed under the GNU Affero General Public License v3.0.
// See the LICENCE file in the repository root for full licence text.

import { BeatmapsetSearchFilters } from 'beatmapset-search-filters';

describe('BeatmapsetSearchFilters', () => {
  let subject: BeatmapsetSearchFilters;

  describe('.query', () => {
    beforeEach(() => {
      subject = new BeatmapsetSearchFilters('https://notarealdomain');
    });

    it('should remove leading whitespace', () => {
      subject.query = '  whee 12 ああ';

      expect(subject.query).toBe('whee 12 ああ');
    });

    it('should remove trailing whitespace', () => {
      subject.query = 'whee 12 ああ  ';

      expect(subject.query).toBe('whee 12 ああ');
    });

    it('should treat empty string as null', () => {
      subject.query = '';

      // type inference was a bit _too_ smart.
      expect(subject.query as string | null).toBe(null);
    });
  });

  describe('.update', () => {
    beforeEach(() => {
      subject = new BeatmapsetSearchFilters('https://notarealdomain/?sort=title_desc');
    });

    it('should reset sort when query changes', () => {
      subject.update('query', 'foo' );

      expect(subject.sort).toBeNull();
    });

    it('should reset sort when status changes', () => {
      subject.update('status', 'foo' );

      expect(subject.sort).toBeNull();
    });

    it('should not reset sort if status nor query changes', () => {
      subject.update('genre', 'bar');

      expect(subject.sort).toBe('title_desc');
    });
  });
});
{'fraction_non_alphanumeric': 0.17001254705144292, 'fraction_numerical': 0.006273525721455458, 'mean_word_length': 3.0265151515151514, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 29, 'https://': 4, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5891614', 'n_tokens_mistral': 986, 'n_tokens_neox': 939, 'n_words': 238}