|
@@ -4,8 +4,7 @@ jest.mock('sentry/utils/localStorage');
|
|
|
|
|
|
describe('AlertStore', function () {
|
|
|
beforeEach(function () {
|
|
|
- AlertStore.alerts = [];
|
|
|
- AlertStore.count = 0;
|
|
|
+ AlertStore.init();
|
|
|
});
|
|
|
|
|
|
describe('addAlert()', function () {
|
|
@@ -20,9 +19,9 @@ describe('AlertStore', function () {
|
|
|
type: 'info',
|
|
|
});
|
|
|
|
|
|
- expect(AlertStore.alerts).toHaveLength(2);
|
|
|
- expect(AlertStore.alerts[0].key).toEqual(0);
|
|
|
- expect(AlertStore.alerts[1].key).toEqual(1);
|
|
|
+ expect(AlertStore.getState()).toHaveLength(2);
|
|
|
+ expect(AlertStore.getState()[0].key).toEqual(0);
|
|
|
+ expect(AlertStore.getState()[1].key).toEqual(1);
|
|
|
});
|
|
|
|
|
|
it('should not add duplicates when noDuplicates is set', function () {
|
|
@@ -39,23 +38,27 @@ describe('AlertStore', function () {
|
|
|
noDuplicates: true,
|
|
|
});
|
|
|
|
|
|
- expect(AlertStore.alerts).toHaveLength(1);
|
|
|
+ expect(AlertStore.getState()).toHaveLength(1);
|
|
|
});
|
|
|
});
|
|
|
|
|
|
describe('closeAlert()', function () {
|
|
|
it('should remove alert', function () {
|
|
|
- AlertStore.alerts = [
|
|
|
- {key: 1, message: 'foo', type: 'error'},
|
|
|
- {key: 2, message: 'bar', type: 'error'},
|
|
|
- {key: 3, message: 'baz', type: 'error'},
|
|
|
- ];
|
|
|
+ const alerts = [
|
|
|
+ {message: 'foo', type: 'error'},
|
|
|
+ {message: 'bar', type: 'error'},
|
|
|
+ {message: 'baz', type: 'error'},
|
|
|
+ ] as const;
|
|
|
+ for (const alert of alerts) {
|
|
|
+ AlertStore.addAlert(alert);
|
|
|
+ }
|
|
|
|
|
|
- AlertStore.closeAlert(AlertStore.alerts[1]);
|
|
|
+ expect(AlertStore.getState()).toHaveLength(3);
|
|
|
+ AlertStore.closeAlert(AlertStore.getState()[1]);
|
|
|
|
|
|
- expect(AlertStore.alerts).toHaveLength(2);
|
|
|
- expect(AlertStore.alerts[0].key).toEqual(1);
|
|
|
- expect(AlertStore.alerts[1].key).toEqual(3);
|
|
|
+ const newState = AlertStore.getState();
|
|
|
+ expect(newState).toHaveLength(2);
|
|
|
+ expect(newState).toEqual([alerts[0], alerts[2]]);
|
|
|
});
|
|
|
it('should persist removal of persistent alerts', function () {
|
|
|
const alert = {
|
|
@@ -67,7 +70,17 @@ describe('AlertStore', function () {
|
|
|
|
|
|
AlertStore.closeAlert(alert);
|
|
|
AlertStore.addAlert(alert);
|
|
|
- expect(AlertStore.alerts).toHaveLength(0);
|
|
|
+ expect(AlertStore.getState()).toHaveLength(0);
|
|
|
});
|
|
|
});
|
|
|
+
|
|
|
+ it('returns a stable reference from getState', () => {
|
|
|
+ AlertStore.addAlert({
|
|
|
+ message: 'Bzzzzzzp *crash*',
|
|
|
+ type: 'error',
|
|
|
+ });
|
|
|
+
|
|
|
+ const state = AlertStore.getState();
|
|
|
+ expect(Object.is(state, AlertStore.getState())).toBe(true);
|
|
|
+ });
|
|
|
});
|