-
-
Notifications
You must be signed in to change notification settings - Fork 4.7k
fix(settings): Support order property on App Discover elements and hide future elements
#44282
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,96 @@ | ||
| /** | ||
| * @copyright Copyright (c) 2024 Ferdinand Thiessen <[email protected]> | ||
| * | ||
| * @author Ferdinand Thiessen <[email protected]> | ||
| * | ||
| * @license AGPL-3.0-or-later | ||
| * | ||
| * This program is free software: you can redistribute it and/or modify | ||
| * it under the terms of the GNU Affero General Public License as | ||
| * published by the Free Software Foundation, either version 3 of the | ||
| * License, or (at your option) any later version. | ||
| * | ||
| * This program is distributed in the hope that it will be useful, | ||
| * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
| * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | ||
| * GNU Affero General Public License for more details. | ||
| * | ||
| * You should have received a copy of the GNU Affero General Public License | ||
| * along with this program. If not, see <http://www.gnu.org/licenses/>. | ||
| * | ||
| */ | ||
|
|
||
| import type { IAppDiscoverElement } from '../constants/AppDiscoverTypes' | ||
|
|
||
| import { describe, expect, it } from '@jest/globals' | ||
| import { filterElements, parseApiResponse } from './appDiscoverParser' | ||
|
|
||
| describe('App Discover API parser', () => { | ||
| describe('filterElements', () => { | ||
| it('can filter expired elements', () => { | ||
| const result = filterElements({ id: 'test', type: 'post', expiryDate: 100 }) | ||
| expect(result).toBe(false) | ||
| }) | ||
|
|
||
| it('can filter upcoming elements', () => { | ||
| const result = filterElements({ id: 'test', type: 'post', date: Date.now() + 10000 }) | ||
| expect(result).toBe(false) | ||
| }) | ||
|
|
||
| it('ignores element without dates', () => { | ||
| const result = filterElements({ id: 'test', type: 'post' }) | ||
| expect(result).toBe(true) | ||
| }) | ||
|
|
||
| it('allows not yet expired elements', () => { | ||
| const result = filterElements({ id: 'test', type: 'post', expiryDate: Date.now() + 10000 }) | ||
| expect(result).toBe(true) | ||
| }) | ||
|
|
||
| it('allows yet included elements', () => { | ||
| const result = filterElements({ id: 'test', type: 'post', date: 100 }) | ||
| expect(result).toBe(true) | ||
| }) | ||
|
|
||
| it('allows elements included and not expired', () => { | ||
| const result = filterElements({ id: 'test', type: 'post', date: 100, expiryDate: Date.now() + 10000 }) | ||
| expect(result).toBe(true) | ||
| }) | ||
|
|
||
| it('can handle null values', () => { | ||
| const result = filterElements({ id: 'test', type: 'post', date: null, expiryDate: null } as unknown as IAppDiscoverElement) | ||
| expect(result).toBe(true) | ||
| }) | ||
| }) | ||
|
|
||
| describe('parseApiResponse', () => { | ||
| it('can handle basic post', () => { | ||
| const result = parseApiResponse({ id: 'test', type: 'post' }) | ||
| expect(result).toEqual({ id: 'test', type: 'post' }) | ||
| }) | ||
|
|
||
| it('can handle carousel', () => { | ||
| const result = parseApiResponse({ id: 'test', type: 'carousel' }) | ||
| expect(result).toEqual({ id: 'test', type: 'carousel' }) | ||
| }) | ||
|
|
||
| it('can handle showcase', () => { | ||
| const result = parseApiResponse({ id: 'test', type: 'showcase' }) | ||
| expect(result).toEqual({ id: 'test', type: 'showcase' }) | ||
| }) | ||
|
|
||
| it('throws on unknown type', () => { | ||
| expect(() => parseApiResponse({ id: 'test', type: 'foo-bar' })).toThrow() | ||
| }) | ||
|
|
||
| it('parses the date', () => { | ||
| const result = parseApiResponse({ id: 'test', type: 'showcase', date: '2024-03-19T17:28:19+0000' }) | ||
| expect(result).toEqual({ id: 'test', type: 'showcase', date: 1710869299000 }) | ||
| }) | ||
|
|
||
| it('parses the expiryDate', () => { | ||
| const result = parseApiResponse({ id: 'test', type: 'showcase', expiryDate: '2024-03-19T17:28:19Z' }) | ||
| expect(result).toEqual({ id: 'test', type: 'showcase', expiryDate: 1710869299000 }) | ||
| }) | ||
| }) | ||
| }) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Large diffs are not rendered by default.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.