-
-
Notifications
You must be signed in to change notification settings - Fork 676
Store server feature level in Redux #4079
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
13 commits
Select commit
Hold shift + click to select a range
3982909
api types: Add a new property `zulip_feature_level`.
hashirsarwar d200fc8
accountsReducer-test: Make REALM_ADD tests more coherent.
hashirsarwar 1e51c0f
RealmScreen: Include feature level from /server_settings in REALM_ADD.
hashirsarwar b058fa2
accountsReducer: Store server feature level in Redux.
hashirsarwar d666225
RealmScreen: Use slightly neater nullish coalescing operator.
chrisbobbe c3b7a4d
accountsReducer tests: Test that REALM_INIT records feature level.
chrisbobbe 9e865c5
accountsReducer tests: Tweak to be more concise and correct.
chrisbobbe e3dc37e
accountsReducer tests: Simplify and tighten a bit further.
gnprice adc4c8f
accountsReducer tests: Clarify expectations and data flow in REALM_ADD.
gnprice 6df5725
accountsReducer tests: Simplify on REALM_INIT by writing data in line.
gnprice 8d8645e
accountsReducer tests: Further group the REALM_ADD test cases.
gnprice d11c3b4
types [nfc]: Describe `null` case of newish Account properties.
gnprice e122cfb
store [nfc]: Slightly simplify migrations; clarify comments.
gnprice 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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -16,58 +16,77 @@ import * as eg from '../../__tests__/lib/exampleData'; | |
|
|
||
| describe('accountsReducer', () => { | ||
| describe('REALM_ADD', () => { | ||
| const accountWithZulipVersion = eg.makeAccount({ | ||
| apiKey: '', | ||
| realm: 'https://realm.one.org', | ||
| }); | ||
| const accountWithoutZulipVersion = eg.makeAccount({ | ||
| apiKey: '', | ||
| zulipVersion: null, | ||
| realm: 'https://realm.two.org', | ||
| }); | ||
| const prevState = deepFreeze([accountWithZulipVersion, accountWithoutZulipVersion]); | ||
|
|
||
| test('if no account with this realm exists, prepend new one, with empty email/apiKey', () => { | ||
| const newAccount = eg.makeAccount({ | ||
| email: '', | ||
| apiKey: '', | ||
| realm: 'https://new.realm.org', | ||
| }); | ||
|
|
||
| const action = deepFreeze({ | ||
| describe('on list of identities', () => { | ||
| const account1 = eg.makeAccount({ realm: 'https://realm.one.org', apiKey: '' }); | ||
| const account2 = eg.makeAccount({ realm: 'https://realm.two.org', apiKey: '' }); | ||
| const prevState = deepFreeze([account1, account2]); | ||
| const baseAction = deepFreeze({ | ||
| type: REALM_ADD, | ||
| realm: newAccount.realm, | ||
| zulipFeatureLevel: eg.zulipFeatureLevel, | ||
| zulipVersion: eg.zulipVersion, | ||
| }); | ||
|
|
||
| const expectedState = [newAccount, accountWithZulipVersion, accountWithoutZulipVersion]; | ||
|
|
||
| const newState = accountsReducer(prevState, action); | ||
|
|
||
| expect(newState).toEqual(expectedState); | ||
| expect(newState).not.toBe(prevState); | ||
| }); | ||
| test('if no account with this realm exists, prepend new one, with empty email/apiKey', () => { | ||
| const newRealm = 'https://new.realm.org'; | ||
| const action = deepFreeze({ ...baseAction, realm: newRealm }); | ||
| expect(accountsReducer(prevState, action)).toEqual([ | ||
| eg.makeAccount({ realm: newRealm, email: '', apiKey: '' }), | ||
| account1, | ||
| account2, | ||
| ]); | ||
| }); | ||
|
|
||
| test('if account with this realm exists, move to front of list', () => { | ||
| const newAccount = eg.makeAccount({ | ||
| email: accountWithoutZulipVersion.email, | ||
| realm: accountWithoutZulipVersion.realm, | ||
| apiKey: '', | ||
| zulipVersion: eg.zulipVersion, | ||
| test('if account with this realm exists, move to front of list', () => { | ||
| const action = deepFreeze({ ...baseAction, realm: account2.realm }); | ||
| expect(accountsReducer(prevState, action)).toEqual([account2, account1]); | ||
| }); | ||
| }); | ||
|
|
||
| const action = deepFreeze({ | ||
| describe('if an account with this realm exists', () => { | ||
| const existingAccountBase = eg.makeAccount({}); | ||
| const baseAction = deepFreeze({ | ||
| type: REALM_ADD, | ||
| realm: newAccount.realm, | ||
| realm: existingAccountBase.realm, | ||
| zulipFeatureLevel: eg.zulipFeatureLevel, | ||
| zulipVersion: eg.zulipVersion, | ||
| }); | ||
|
|
||
| const expectedState = [newAccount, accountWithZulipVersion]; | ||
|
|
||
| const newState = accountsReducer(prevState, action); | ||
| describe('update its zulipVersion', () => { | ||
| const newZulipVersion = new ZulipVersion('4.0.0'); | ||
| const action = deepFreeze({ ...baseAction, zulipVersion: newZulipVersion }); | ||
|
|
||
| test('when its zulipVersion started out non-null', () => { | ||
| expect( | ||
| accountsReducer( | ||
| [{ ...existingAccountBase, zulipVersion: new ZulipVersion('3.0.0') }], | ||
| action, | ||
| ), | ||
| ).toEqual([{ ...existingAccountBase, zulipVersion: newZulipVersion }]); | ||
| }); | ||
|
|
||
| test('when its zulipVersion started out null', () => { | ||
| expect(accountsReducer([{ ...existingAccountBase, zulipVersion: null }], action)).toEqual( | ||
| [{ ...existingAccountBase, zulipVersion: newZulipVersion }], | ||
| ); | ||
| }); | ||
| }); | ||
|
|
||
| expect(newState).toEqual(expectedState); | ||
| expect(newState).not.toBe(prevState); | ||
| describe('update its zulipFeatureLevel', () => { | ||
| const newZulipFeatureLevel = 6; | ||
| const action = deepFreeze({ ...baseAction, zulipFeatureLevel: newZulipFeatureLevel }); | ||
|
|
||
| test('when its zulipFeatureLevel started out non-null', () => { | ||
| expect( | ||
| accountsReducer([{ ...existingAccountBase, zulipFeatureLevel: 5 }], action), | ||
| ).toEqual([{ ...existingAccountBase, zulipFeatureLevel: newZulipFeatureLevel }]); | ||
| }); | ||
|
|
||
| test('when its zulipVersion started out null', () => { | ||
| expect( | ||
| accountsReducer([{ ...existingAccountBase, zulipFeatureLevel: null }], action), | ||
| ).toEqual([{ ...existingAccountBase, zulipFeatureLevel: newZulipFeatureLevel }]); | ||
| }); | ||
| }); | ||
| }); | ||
| }); | ||
|
|
||
|
|
@@ -77,16 +96,26 @@ describe('accountsReducer', () => { | |
| const account3 = eg.makeAccount(); | ||
|
|
||
| test('records zulipVersion on active account', () => { | ||
| const prevState = deepFreeze([account1, account2, account3]); | ||
| const newZulipVersion = new ZulipVersion('2.0.0'); | ||
| const action = deepFreeze({ ...eg.action.realm_init, zulipVersion: newZulipVersion }); | ||
|
|
||
| const expectedState = [{ ...account1, zulipVersion: newZulipVersion }, account2, account3]; | ||
|
|
||
| const newState = accountsReducer(prevState, action); | ||
| expect( | ||
| accountsReducer( | ||
| deepFreeze([account1, account2, account3]), | ||
| deepFreeze({ ...eg.action.realm_init, zulipVersion: newZulipVersion }), | ||
| ), | ||
| ).toEqual([{ ...account1, zulipVersion: newZulipVersion }, account2, account3]); | ||
| }); | ||
|
|
||
| expect(newState).toEqual(expectedState); | ||
| expect(newState).not.toBe(prevState); | ||
| test('records zulipFeatureLevel on active account', () => { | ||
| const newZulipFeatureLevel = 6; | ||
| expect( | ||
| accountsReducer( | ||
| deepFreeze([account1, account2, account3]), | ||
| deepFreeze({ | ||
| ...eg.action.realm_init, | ||
| data: { ...eg.action.realm_init.data, zulip_feature_level: newZulipFeatureLevel }, | ||
| }), | ||
| ), | ||
| ).toEqual([{ ...account1, zulipFeatureLevel: newZulipFeatureLevel }, account2, account3]); | ||
| }); | ||
| }); | ||
|
|
||
|
|
@@ -154,6 +183,7 @@ describe('accountsReducer', () => { | |
| email: '[email protected]', | ||
| realm: 'https://new.realm.org', | ||
| zulipVersion: null, | ||
| zulipFeatureLevel: null, | ||
| }); | ||
|
|
||
| const action = deepFreeze({ | ||
|
|
||
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
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
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
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.