123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111 |
- import TeamStore from 'sentry/stores/teamStore';
- describe('TeamStore', function () {
- const teamFoo = TestStubs.Team({
- id: '1',
- slug: 'team-foo',
- });
- const teamBar = TestStubs.Team({
- id: '2',
- slug: 'team-bar',
- });
- beforeEach(function () {
- TeamStore.reset();
- });
- describe('setting data', function () {
- it('populate teams correctly', function () {
- expect(TeamStore.getState()).toMatchObject({
- teams: [],
- loading: true,
- hasMore: null,
- cursor: null,
- loadedUserTeams: false,
- });
- TeamStore.loadInitialData([teamFoo, teamBar]);
- expect(TeamStore.getState()).toMatchObject({
- teams: [teamBar, teamFoo],
- loading: false,
- hasMore: null,
- cursor: null,
- loadedUserTeams: false,
- });
- });
- it('loads user teams', function () {
- expect(TeamStore.getState()).toMatchObject({
- teams: [],
- loadedUserTeams: false,
- });
- TeamStore.loadUserTeams([teamFoo]);
- expect(TeamStore.getState()).toMatchObject({
- teams: [teamFoo],
- loadedUserTeams: true,
- });
- });
- it('stores cursor and hasMore correctly', function () {
- expect(TeamStore.getState()).toMatchObject({
- teams: [],
- hasMore: null,
- cursor: null,
- loadedUserTeams: false,
- });
- TeamStore.loadInitialData([teamFoo], false, null);
- expect(TeamStore.getState()).toMatchObject({
- teams: [teamFoo],
- hasMore: false,
- cursor: null,
- loadedUserTeams: true,
- });
- });
- });
- describe('updating teams', function () {
- it('adds new teams', async function () {
- TeamStore.loadInitialData([teamFoo]);
- await tick();
- expect(TeamStore.getState()).toMatchObject({
- teams: [teamFoo],
- });
- TeamStore.onCreateSuccess(teamBar);
- await tick();
- expect(TeamStore.getState()).toMatchObject({
- teams: [teamBar, teamFoo],
- });
- });
- it('removes teams', async function () {
- TeamStore.loadInitialData([teamFoo]);
- await tick();
- expect(TeamStore.getState()).toMatchObject({
- teams: [teamFoo],
- });
- TeamStore.onRemoveSuccess(teamFoo.slug);
- await tick();
- expect(TeamStore.getState()).toMatchObject({
- teams: [],
- });
- });
- it('updates teams', async function () {
- TeamStore.loadInitialData([teamFoo]);
- await tick();
- expect(TeamStore.getState()).toMatchObject({
- teams: [teamFoo],
- });
- TeamStore.onUpdateSuccess(teamFoo.slug, teamBar);
- await tick();
- expect(TeamStore.getState()).toMatchObject({
- teams: [teamBar],
- });
- });
- });
- });
|